Shreyas094 commited on
Commit
c3aa982
·
verified ·
1 Parent(s): d597e1c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -4
app.py CHANGED
@@ -108,15 +108,23 @@ def generate_chunked_response(prompt, model, max_tokens=1000, num_calls=3, tempe
108
  except Exception as e:
109
  print(f"Error in generating response: {str(e)}")
110
 
 
111
  combined_response = " ".join(full_responses)
112
- print(f"Combined response: {combined_response[:100]}...")
113
-
114
  clean_response = re.sub(r'<s>\[INST\].*?\[/INST\]\s*', '', combined_response, flags=re.DOTALL)
115
  clean_response = clean_response.replace("Using the following context:", "").strip()
116
  clean_response = clean_response.replace("Using the following context from the PDF documents:", "").strip()
117
 
118
- print(f"Final clean response: {clean_response[:100]}...")
119
- return clean_response
 
 
 
 
 
 
 
 
 
120
 
121
  def duckduckgo_search(query):
122
  with DDGS() as ddgs:
 
108
  except Exception as e:
109
  print(f"Error in generating response: {str(e)}")
110
 
111
+ # Combine responses and clean up
112
  combined_response = " ".join(full_responses)
 
 
113
  clean_response = re.sub(r'<s>\[INST\].*?\[/INST\]\s*', '', combined_response, flags=re.DOTALL)
114
  clean_response = clean_response.replace("Using the following context:", "").strip()
115
  clean_response = clean_response.replace("Using the following context from the PDF documents:", "").strip()
116
 
117
+ # Remove duplicate sentences
118
+ sentences = clean_response.split('. ')
119
+ unique_sentences = []
120
+ for sentence in sentences:
121
+ if sentence not in unique_sentences:
122
+ unique_sentences.append(sentence)
123
+
124
+ final_response = '. '.join(unique_sentences)
125
+
126
+ print(f"Final clean response: {final_response[:100]}...")
127
+ return final_response
128
 
129
  def duckduckgo_search(query):
130
  with DDGS() as ddgs: