Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -50,8 +50,12 @@ def get_wiki_article(topic):
|
|
| 50 |
search = random.choice(choices)
|
| 51 |
try:
|
| 52 |
p = wikipedia.page(search)
|
|
|
|
|
|
|
| 53 |
except wikipedia.exceptions.DisambiguationError as e:
|
|
|
|
| 54 |
choices = [x for x in e.options if ('disambiguation' not in x) and ('All pages' not in x) and (x!=topic)]
|
|
|
|
| 55 |
s = random.choice(choices)
|
| 56 |
p = wikipedia.page(s)
|
| 57 |
saved = AIMemory(p.content, p.url)
|
|
@@ -59,6 +63,10 @@ def get_wiki_article(topic):
|
|
| 59 |
|
| 60 |
def get_answer(topic, question):
|
| 61 |
w_art, w_url=get_wiki_article(topic)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 62 |
qa = {'question': question, 'context': w_art}
|
| 63 |
res = nlp(qa)
|
| 64 |
saved = AIMemory(res['answer'], w_url)
|
|
@@ -102,4 +110,4 @@ examples = [
|
|
| 102 |
|
| 103 |
gr.Interface(get_answer, inputs, outputs, title=title, description=description, examples=examples,
|
| 104 |
article="Saved dataset: https://huggingface.co/datasets/awacke1/WikipediaSearch stores search and the result url. List of topics is at https://en.wikipedia.org/wiki/Wikipedia:Contents/Lists and wikipedia library docs are here: https://pypi.org/project/wikipedia/",
|
| 105 |
-
flagging_options=["strongly related","related", "neutral", "unrelated", "strongly unrelated"]).launch(share=False,enable_queue=False)
|
|
|
|
| 50 |
search = random.choice(choices)
|
| 51 |
try:
|
| 52 |
p = wikipedia.page(search)
|
| 53 |
+
print(p)
|
| 54 |
+
|
| 55 |
except wikipedia.exceptions.DisambiguationError as e:
|
| 56 |
+
print("disambiguation error")
|
| 57 |
choices = [x for x in e.options if ('disambiguation' not in x) and ('All pages' not in x) and (x!=topic)]
|
| 58 |
+
print(choices)
|
| 59 |
s = random.choice(choices)
|
| 60 |
p = wikipedia.page(s)
|
| 61 |
saved = AIMemory(p.content, p.url)
|
|
|
|
| 63 |
|
| 64 |
def get_answer(topic, question):
|
| 65 |
w_art, w_url=get_wiki_article(topic)
|
| 66 |
+
print(topic)
|
| 67 |
+
print(question)
|
| 68 |
+
print(w_art)
|
| 69 |
+
|
| 70 |
qa = {'question': question, 'context': w_art}
|
| 71 |
res = nlp(qa)
|
| 72 |
saved = AIMemory(res['answer'], w_url)
|
|
|
|
| 110 |
|
| 111 |
gr.Interface(get_answer, inputs, outputs, title=title, description=description, examples=examples,
|
| 112 |
article="Saved dataset: https://huggingface.co/datasets/awacke1/WikipediaSearch stores search and the result url. List of topics is at https://en.wikipedia.org/wiki/Wikipedia:Contents/Lists and wikipedia library docs are here: https://pypi.org/project/wikipedia/",
|
| 113 |
+
flagging_options=["strongly related","related", "neutral", "unrelated", "strongly unrelated"]).launch(debug=True,share=False,enable_queue=False)
|