Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -19,7 +19,8 @@ def load_model(model_name):
|
|
19 |
loaded_models[model_name] = pipeline("question-answering", model=models[model_name])
|
20 |
return loaded_models[model_name]
|
21 |
|
22 |
-
def answer_question(model_name, file, question):
|
|
|
23 |
model = load_model(model_name)
|
24 |
|
25 |
if file is not None:
|
@@ -43,7 +44,8 @@ def answer_question(model_name, file, question):
|
|
43 |
# Explain score
|
44 |
score_explanation = f"The confidence score ranges from 0 to 1, where a higher score indicates higher confidence in the answer's correctness. In this case, the score is {score:.2f}. A score closer to 1 implies the model is very confident about the answer."
|
45 |
|
46 |
-
|
|
|
47 |
|
48 |
# Define the Gradio interface
|
49 |
with gr.Blocks() as interface:
|
@@ -74,19 +76,15 @@ with gr.Blocks() as interface:
|
|
74 |
with gr.Row():
|
75 |
submit_button = gr.Button("Submit")
|
76 |
|
77 |
-
|
78 |
-
status = gr.Markdown(value="")
|
79 |
|
80 |
def on_submit(model_name, file, question):
|
81 |
-
status
|
82 |
-
answer, score, explanation = answer_question(model_name, file, question)
|
83 |
-
status.update(value="Model loaded")
|
84 |
-
return answer, score, explanation
|
85 |
|
86 |
submit_button.click(
|
87 |
on_submit,
|
88 |
inputs=[model_dropdown, file_input, question_input],
|
89 |
-
outputs=[answer_output, score_output, explanation_output]
|
90 |
)
|
91 |
|
92 |
if __name__ == "__main__":
|
|
|
19 |
loaded_models[model_name] = pipeline("question-answering", model=models[model_name])
|
20 |
return loaded_models[model_name]
|
21 |
|
22 |
+
def answer_question(model_name, file, question, status):
|
23 |
+
status = "Loading model..."
|
24 |
model = load_model(model_name)
|
25 |
|
26 |
if file is not None:
|
|
|
44 |
# Explain score
|
45 |
score_explanation = f"The confidence score ranges from 0 to 1, where a higher score indicates higher confidence in the answer's correctness. In this case, the score is {score:.2f}. A score closer to 1 implies the model is very confident about the answer."
|
46 |
|
47 |
+
status = "Model loaded"
|
48 |
+
return answer, f"{score:.2f}", score_explanation, status
|
49 |
|
50 |
# Define the Gradio interface
|
51 |
with gr.Blocks() as interface:
|
|
|
76 |
with gr.Row():
|
77 |
submit_button = gr.Button("Submit")
|
78 |
|
79 |
+
status_output = gr.Markdown(value="")
|
|
|
80 |
|
81 |
def on_submit(model_name, file, question):
|
82 |
+
return answer_question(model_name, file, question, status="Loading model...")
|
|
|
|
|
|
|
83 |
|
84 |
submit_button.click(
|
85 |
on_submit,
|
86 |
inputs=[model_dropdown, file_input, question_input],
|
87 |
+
outputs=[answer_output, score_output, explanation_output, status_output]
|
88 |
)
|
89 |
|
90 |
if __name__ == "__main__":
|