awacke1 commited on
Commit
0bc5dd6
·
verified ·
1 Parent(s): 022f1ca

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +71 -34
app.py CHANGED
@@ -1,36 +1,73 @@
1
  import gradio as gr
2
 
3
- context = "What should be documented in a care plan?\n"
4
- context = context + "Regardless of what your preferences are, your care plan should include:\n"
5
- context = context + "What your assessed care needs are.\n"
6
- context = context + "What type of support you should receive.\n"
7
- context = context + "Your desired outcomes.\n"
8
- context = context + "Who should provide care.\n"
9
- context = context + "When care and support should be provided.\n"
10
- context = context + "Records of care provided.\n"
11
- context = context + "Your wishes and personal preferences.\n"
12
- context = context + "The costs of the services.\n"
13
- context = context + "Dimensions\n"
14
- context = context + "1-Ontology of Plan\n"
15
- context = context + "2-Problems as evidenced by Signs of Systems\n"
16
- context = context + "3-Assessment of Needs\n"
17
- context = context + "4-Questions about problems faced\n"
18
- context = context + "5-Goals for long and short term improvements\n"
19
- context = context + "6-Knowledge-Behavior-Status Quality Measures\n"
20
- context = context + "7-Intervention List of Options\n"
21
- context = context + "8-Quality Measures\n"
22
- context = context + "9-Pathways Available\n"
23
-
24
- with open('WritingCarePlans.txt', 'r') as file:
25
- context = file.read()
26
-
27
- question = "What should be documented in a care plan?"
28
-
29
- gr.Interface.load(
30
- "huggingface/deepset/roberta-base-squad2",
31
- theme="default",
32
- css=".footer{display:none !important}",
33
- inputs=[gr.inputs.Textbox(lines=12, default=context, label="Context paragraph"), gr.inputs.Textbox(lines=3, default=question, label="Question")],
34
- outputs=[gr.outputs.Textbox(label="Answer"), gr.outputs.Textbox(label="Score")],
35
- title=None,
36
- description="Provide your own paragraph and ask any question about the text. How well does the model answer?").launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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()