ipvikas commited on
Commit
33bdc2f
1 Parent(s): 3886eca

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -9
app.py CHANGED
@@ -172,6 +172,17 @@ import re, string, unicodedata
172
  import wikipedia as wk #pip install wikipedia
173
  from collections import defaultdict
174
 
 
 
 
 
 
 
 
 
 
 
 
175
  def get_response(input_text):
176
  #model_inputs = tokenizer(input_text, return_tensors="pt")
177
  #generated_tokens = model.generate(**model_inputs,forced_bos_token_id=tokenizer.lang_code_to_id["en_XX"])
@@ -195,15 +206,11 @@ def get_response(input_text):
195
  if tag == intent["tag"]:
196
  return random.choice(intent['responses'])
197
  else:
198
- reg_ex = re.search('from wikipedia (.*)', input)#tell me about
199
- try:
200
- if reg_ex:
201
- topic = reg_ex.group(1)
202
- wiki = wk.summary(topic, sentences = 3)
203
- return wiki
204
- except Exception as e:
205
- #print("No content has been found")
206
- return "I do not understand...Please rephrase"
207
 
208
  title = "WeASK: ChatBOT"
209
  description = "Ask your query here"
 
172
  import wikipedia as wk #pip install wikipedia
173
  from collections import defaultdict
174
 
175
+ def wikipedia_data(user_response):
176
+ reg_ex = re.search('from wikipedia (.*)', user_response)#tell me about
177
+ try:
178
+ if reg_ex:
179
+ topic = reg_ex.group(1)
180
+ wiki = wk.summary(topic, sentences = 3)
181
+ return wiki
182
+ except Exception as e:
183
+ print("I do not understand...Please rephrase")
184
+
185
+
186
  def get_response(input_text):
187
  #model_inputs = tokenizer(input_text, return_tensors="pt")
188
  #generated_tokens = model.generate(**model_inputs,forced_bos_token_id=tokenizer.lang_code_to_id["en_XX"])
 
206
  if tag == intent["tag"]:
207
  return random.choice(intent['responses'])
208
  else:
209
+ if "From Wikipedia" in sentence:
210
+ if sentence:
211
+ robo_response = wikipedia_data(user_response)
212
+ return robo_response
213
+
 
 
 
 
214
 
215
  title = "WeASK: ChatBOT"
216
  description = "Ask your query here"