import gradio as gr # --- Context Setup --- # The context provided in the original prompt is overwritten by reading the file. # I'll keep the file reading logic as it was in the original code. context_text = "" try: with open('WritingCarePlans.txt', 'r', encoding='utf-8') as file: context_text = file.read() except FileNotFoundError: print("Warning: WritingCarePlans.txt not found. Using default context.") # Fallback to the context string if the file doesn't exist context_text = ( "What should be documented in a care plan?\n" "Regardless of what your preferences are, your care plan should include:\n" "What your assessed care needs are.\n" "What type of support you should receive.\n" "Your desired outcomes.\n" "Who should provide care.\n" "When care and support should be provided.\n" "Records of care provided.\n" "Your wishes and personal preferences.\n" "The costs of the services.\n\n" "Dimensions\n" "1-Ontology of Plan\n" "2-Problems as evidenced by Signs of Systems\n" "3-Assessment of Needs\n" "4-Questions about problems faced\n" "5-Goals for long and short term improvements\n" "6-Knowledge-Behavior-Status Quality Measures\n" "7-Intervention List of Options\n" "8-Quality Measures\n" "9-Pathways Available" ) question_text = "What should be documented in a care plan?" # --- Gradio Blocks UI --- with gr.Blocks(theme=gr.themes.Default(), css=".footer {display: none !important}") as demo: gr.Markdown("# Question Answering with RoBERTa 🤖") gr.Markdown("Provide your own paragraph and ask any question about the text. The model will find the answer within the text.") # Load the model from Hugging Face. gr.load returns a function. model_fn = gr.load("huggingface/deepset/roberta-base-squad2") with gr.Row(): # Input Column with gr.Column(scale=2): context_box = gr.Textbox( value=context_text, lines=15, label="Context Paragraph" ) question_box = gr.Textbox( value=question_text, lines=2, label="Question" ) submit_btn = gr.Button("Find Answer", variant="primary") # Output Column with gr.Column(scale=1): answer_box = gr.Textbox(label="Answer", interactive=False, lines=8) score_box = gr.Textbox(label="Confidence Score", interactive=False) # Define the click action for the button submit_btn.click( fn=model_fn, inputs=[context_box, question_box], outputs=[answer_box, score_box] ) demo.launch()