Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -50,27 +50,22 @@ def predict_answer(context, question):
|
|
50 |
# Load short model
|
51 |
short_answer_model = pipeline(model="Nighter/QA_wiki_data_short_answer", from_tf=True)
|
52 |
|
53 |
-
#
|
54 |
-
# long_answer = predict_answer(context, question)
|
55 |
-
# short_answer_result = short_answer_model(question=question, context=remove_parentheses(context))
|
56 |
-
# return short_answer_result['answer'], long_answer
|
57 |
-
|
58 |
def answer_questions(context, question):
|
59 |
long_score, long_answer = predict_answer(context, question)
|
60 |
-
|
61 |
-
#
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
short_answer_result = short_answer_model(question=question, context=
|
70 |
-
|
71 |
return short_answer_result['answer'], short_answer_result['score'], long_answer, long_score
|
72 |
|
73 |
-
|
74 |
with gr.Blocks() as app:
|
75 |
gr.Markdown("<center> <h1>Question Answering with Short and Long Answer Models </h1> </center><hr>")
|
76 |
with gr.Row():
|
|
|
50 |
# Load short model
|
51 |
short_answer_model = pipeline(model="Nighter/QA_wiki_data_short_answer", from_tf=True)
|
52 |
|
53 |
+
# Function to answer on all models
|
|
|
|
|
|
|
|
|
54 |
def answer_questions(context, question):
|
55 |
long_score, long_answer = predict_answer(context, question)
|
56 |
+
# # Check if the original context is longer than 512 tokens
|
57 |
+
# if len(tokenizer.texts_to_sequences([context])[0]) > 512:
|
58 |
+
# # If yes, use the long answer as the context for the short answer model
|
59 |
+
# short_context = long_answer
|
60 |
+
# else:
|
61 |
+
# # If no, use the original context
|
62 |
+
# short_context = remove_parentheses(context)
|
63 |
+
|
64 |
+
# short_answer_result = short_answer_model(question=question, context=short_context)
|
65 |
+
short_answer_result = short_answer_model(question=question, context=remove_parentheses(context))
|
|
|
66 |
return short_answer_result['answer'], short_answer_result['score'], long_answer, long_score
|
67 |
|
68 |
+
# App Interface
|
69 |
with gr.Blocks() as app:
|
70 |
gr.Markdown("<center> <h1>Question Answering with Short and Long Answer Models </h1> </center><hr>")
|
71 |
with gr.Row():
|