Update app.py
Browse files
app.py
CHANGED
@@ -1,36 +1,73 @@
|
|
1 |
import gradio as gr
|
2 |
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
|
3 |
+
# --- Context Setup ---
|
4 |
+
# The context provided in the original prompt is overwritten by reading the file.
|
5 |
+
# I'll keep the file reading logic as it was in the original code.
|
6 |
+
context_text = ""
|
7 |
+
try:
|
8 |
+
with open('WritingCarePlans.txt', 'r', encoding='utf-8') as file:
|
9 |
+
context_text = file.read()
|
10 |
+
except FileNotFoundError:
|
11 |
+
print("Warning: WritingCarePlans.txt not found. Using default context.")
|
12 |
+
# Fallback to the context string if the file doesn't exist
|
13 |
+
context_text = (
|
14 |
+
"What should be documented in a care plan?\n"
|
15 |
+
"Regardless of what your preferences are, your care plan should include:\n"
|
16 |
+
"What your assessed care needs are.\n"
|
17 |
+
"What type of support you should receive.\n"
|
18 |
+
"Your desired outcomes.\n"
|
19 |
+
"Who should provide care.\n"
|
20 |
+
"When care and support should be provided.\n"
|
21 |
+
"Records of care provided.\n"
|
22 |
+
"Your wishes and personal preferences.\n"
|
23 |
+
"The costs of the services.\n\n"
|
24 |
+
"Dimensions\n"
|
25 |
+
"1-Ontology of Plan\n"
|
26 |
+
"2-Problems as evidenced by Signs of Systems\n"
|
27 |
+
"3-Assessment of Needs\n"
|
28 |
+
"4-Questions about problems faced\n"
|
29 |
+
"5-Goals for long and short term improvements\n"
|
30 |
+
"6-Knowledge-Behavior-Status Quality Measures\n"
|
31 |
+
"7-Intervention List of Options\n"
|
32 |
+
"8-Quality Measures\n"
|
33 |
+
"9-Pathways Available"
|
34 |
+
)
|
35 |
+
|
36 |
+
question_text = "What should be documented in a care plan?"
|
37 |
+
|
38 |
+
# --- Gradio Blocks UI ---
|
39 |
+
with gr.Blocks(theme=gr.themes.Default(), css=".footer {display: none !important}") as demo:
|
40 |
+
gr.Markdown("# Question Answering with RoBERTa 🤖")
|
41 |
+
gr.Markdown("Provide your own paragraph and ask any question about the text. The model will find the answer within the text.")
|
42 |
+
|
43 |
+
# Load the model from Hugging Face. gr.load returns a function.
|
44 |
+
model_fn = gr.load("huggingface/deepset/roberta-base-squad2")
|
45 |
+
|
46 |
+
with gr.Row():
|
47 |
+
# Input Column
|
48 |
+
with gr.Column(scale=2):
|
49 |
+
context_box = gr.Textbox(
|
50 |
+
value=context_text,
|
51 |
+
lines=15,
|
52 |
+
label="Context Paragraph"
|
53 |
+
)
|
54 |
+
question_box = gr.Textbox(
|
55 |
+
value=question_text,
|
56 |
+
lines=2,
|
57 |
+
label="Question"
|
58 |
+
)
|
59 |
+
submit_btn = gr.Button("Find Answer", variant="primary")
|
60 |
+
|
61 |
+
# Output Column
|
62 |
+
with gr.Column(scale=1):
|
63 |
+
answer_box = gr.Textbox(label="Answer", interactive=False, lines=8)
|
64 |
+
score_box = gr.Textbox(label="Confidence Score", interactive=False)
|
65 |
+
|
66 |
+
# Define the click action for the button
|
67 |
+
submit_btn.click(
|
68 |
+
fn=model_fn,
|
69 |
+
inputs=[context_box, question_box],
|
70 |
+
outputs=[answer_box, score_box]
|
71 |
+
)
|
72 |
+
|
73 |
+
demo.launch()
|