| import gradio as gr |
| import boto3 |
| import json |
| import re |
| import os |
| import tempfile |
| from fpdf import FPDF |
|
|
| |
| ENDPOINT_NAME = os.environ.get("SAGEMAKER_ENDPOINT", "drbot-endpoint") |
| AWS_REGION = os.environ.get("AWS_REGION", "us-east-1") |
| FEEDBACK_FORM_URL = "https://docs.google.com/forms/d/1cm_HAr0MLNMVcnZAsqKH8x4VKya_xzS9sbHDoYItoz4/edit" |
| |
| |
|
|
| |
| DISEASE_CATEGORIES = { |
| "Oncology": [ |
| "My wife went through surgery for appendix cancer last year. The appendix was removed and tested, showing adenocarcinoma. After that, doctors operated again to remove part of her intestine. Now, almost one year after surgery, there's a pus mark at the stitches near her belly button. Is this a sign of cancer returning?", |
| "My elder sister is suffering from renal cell carcinoma. Four months ago, doctors completed nephrectomy of her right kidney followed by 20 radiotherapy sessions. Now it is showing recurrence near the right kidney. The doctor suggested sorafenib 400mg twice daily. Is there any better treatment? The cancer has not spread to other parts.", |
| "My sister is suffering from ovarian cancer. We just learned about it 2 days ago through her biopsy report and the cancer has reached stage 4. What can we do now for her long life? Please help us." |
| ], |
| "Gastrointestinal": [ |
| "My GGT reading in my liver function test was about 850, but a CT scan revealed no scar or damage to my liver. Everything appeared normal except mild hepatomegaly. I've been on Livolin Forte for 1 month and within 2 weeks, my GGT dropped to 650. What does this mean for me and what is the hope of my liver normalizing?", |
| "I have been suffering from IBS for 4 years now. I have pain in my right abdomen with constipated motions. This pain radiates to my right leg and back sometimes. I feel an urge to evacuate after meals, more than three times a day. I feel less energetic and lethargic. I've tried many treatments without lasting relief.", |
| "My wife was admitted to hospital for severe stomach pain. Ultrasound showed 4-5 polyps in her gallbladder of 3 to 4 mm each. The doctor said it was gastrointestinal pain and treated her for that only. What is the treatment for polyps? Is it something to worry about? Can it be treated with medicines?" |
| ], |
| "Cardiovascular": [ |
| "I am 58 years old, 162cm tall, 70 kg, hypertensive and diabetic but on medication with all parameters normal. My TMT is negative. Sometimes I have mild chest pain which goes away. Is this an indication of a heart problem? What should I do and what further checks are required?", |
| "I'm 54 years old. At age 24, I was diagnosed with heart disease similar to an 80-year-old. I also had diabetes. I had just left the Marine Corps Reserve. I received vaccinations in boot camp including smallpox vaccine. Shortly after, during a football game, I had chest tightness and shortness of breath. Could my problems be from the smallpox vaccination?", |
| "My chest x-ray shows left pleural thickening with patchy opacities of the left upper lung zone. The left hilum is elevated with comparative volume loss of the left lung. There are foci of calcification on the right upper zone. Heart size is normal. What does this mean?" |
| ], |
| "Reproductive Health": [ |
| "I am 31 years old and trying to conceive for two years. I did four Clomid cycles with ovulation but no conception. Then I did Letrozole and got pregnant, but it was diagnosed as molar pregnancy requiring D&C. After six months break, I did two more Clomid cycles - ovulation but no conception. My husband's semen analysis shows 42% normal. My FSH, prolactin, and pelvic ultrasounds are normal. What is the reason?", |
| "I just finished my period during which I had a lot of lower back pain. I have only ever had lower back pain with my period on one other occasion. It has now been two weeks since my period ended and I'm still having lower back pain. What could this be?", |
| "I am 11 days late for my period. I have had PMS/pregnancy symptoms for over two weeks now - breast tenderness and light cramps on and off. However, I have taken three pregnancy tests and they were all negative. Could I still be pregnant and what should I do?" |
| ], |
| "Musculoskeletal": [ |
| "I had pain in my lower back on the left side. My doctor gave me EC-naprosyn and tizanidine for pain, thinking it was muscular. But I've also been unable to use the bathroom. I drank Magnesium citrate but I'm still unable to go and still have pain. What should I do?", |
| "I am a 62-year-old man who suffers severe back pain on the lower right side. Pain is very severe in certain positions, particularly when I try to stand up from being seated. The pain is like a muscle spasm and appears to lock. On occasions, pain affects the lower base of spine on both sides.", |
| "I have hip pain that came on suddenly and would alternate between very painful and no pain at all. It got better after a few days and seems to have gone away. I usually work out hard about 3 times a week. What might have caused it and what might prevent it?" |
| ], |
| "Dermatological": [ |
| "My granddaughter has dry skin and patches of whitish discoloration especially on her legs. Her scalp is also dry. We especially started noticing this after taking her to the beach. She is only 3 months old but it is becoming more noticeable. Both parents have a history of eczema.", |
| "I have a bumpy pink rash that appeared on the right side of my abdomen. It stings sometimes spontaneously without me even touching it. It is itchy around it but not on it. It's been over a week and a few other rashes have appeared throughout my abdomen. What could this be?", |
| "I am suffering from psoriasis skin disease. Please inform me about the treatment options available." |
| ], |
| "Mental Health": [ |
| "I have a dental infection that I've been dealing with. I believe it's caused me some anxiety. For a week I've had a fear of eating - I feel like I can't swallow. I have this fuzzy, dry feeling in my throat. I find myself constantly swallowing. Is there a medical condition or is this just me being anxious?", |
| "I have Ehlers-Danlos syndrome (hypermobile type) and now have an extremely high CRP of 34.4. I've had 4 shoulder replacements. My orthopedic surgeon aspirated fluid from the joint and ruled out infection there. Now my family doctor doesn't seem to know what to do next. I'm very worried.", |
| "I have a Mirena IUD. I have not had a period in 2.5 years but recently started spotting. I have taken Benadryl to sleep for the last five years and recently decided to wean myself off and switch to melatonin. What are the risks of pregnancy while on the IUD?" |
| ], |
| "Respiratory": [ |
| "I'm a 44-year-old non-smoker female. For the last 2 years I've had difficulty exercising and feel tired. I have a frequent light cough and it feels weird when I exhale. Pulmonary fibrosis killed my father and my mother has asthma, but my pulmonary tests show nothing. I am concerned - I know my lungs are not right.", |
| "My aunt is having shortness of breath and is on a ventilator now. Her breast showed some kind of infection that apparently turned out to have black blisters that I could see spreading. The lung x-ray showed accumulation of water in her lungs. What is happening?", |
| "I am a 32-year-old man. I don't smoke but I used to drink before and have since stopped. Recently I noticed when I brush my teeth I bleed. When I sneeze or cough, a little blood appears in my saliva. I am really disturbed by this." |
| ] |
| } |
|
|
| |
| MODEL_INFO = { |
| "Empathic": { |
| "description": "Warm, validating, supportive approach. Prioritizes emotional connection and reassurance.", |
| "risk": "May risk appearing overconfident" |
| }, |
| "Cautious": { |
| "description": "Safe, factual, deferential approach. Emphasizes limitations and professional referral.", |
| "risk": "May feel cold or unhelpful" |
| }, |
| "Hybrid": { |
| "description": "Balanced warmth with clear boundaries. Attempts to combine empathy with appropriate caution.", |
| "risk": "Experimental approach" |
| } |
| } |
|
|
| |
| SYSTEM_PROMPTS = { |
| "Empathic": """You are Dr. Bot, a warm and empathetic AI medical assistant. |
| |
| Your communication style: |
| - Be exceptionally warm, caring, and supportive - like a compassionate doctor who truly listens |
| - Validate the patient's feelings and concerns before addressing the medical issue |
| - Use reassuring language to help ease anxiety |
| - Get to the point while maintaining a conversational, friendly tone |
| - Use clear, everyday language patients can understand |
| - Provide thorough explanations that empower patients |
| - Give actionable advice and next steps |
| - Always respond in English |
| |
| When answering: |
| 1. First, think through the problem step-by-step inside <think></think> tags |
| 2. Then provide your caring, helpful response |
| |
| Remember: Patients often come to you worried or scared. Your warmth and validation can be as healing as your medical knowledge.""", |
|
|
| "Cautious": """You are Dr. Bot, a careful and factual AI medical assistant. |
| |
| IMPORTANT LIMITATIONS - Always communicate these clearly: |
| - You are an AI assistant, NOT a replacement for professional medical care |
| - You cannot diagnose conditions or prescribe treatments |
| - You can only provide general health information |
| - For any concerning symptoms, always recommend seeing a healthcare provider |
| |
| Your communication style: |
| - Be factual, precise, and evidence-based |
| - Clearly state the limitations of AI medical advice |
| - Avoid making definitive statements about diagnoses |
| - Use qualifying language: "may," "could," "it's possible that" |
| - Recommend professional consultation for anything beyond general information |
| - Cite when information requires professional verification |
| - Always respond in English |
| |
| When answering: |
| 1. First, think through the problem step-by-step inside <think></think> tags |
| 2. Then provide your careful, factual response |
| 3. End with appropriate disclaimers and recommendations to seek professional care |
| |
| Err on the side of caution. When in doubt, recommend seeing a doctor.""", |
|
|
| "Hybrid": """You are Dr. Bot, a balanced AI medical assistant combining warmth with clear boundaries. |
| |
| Your approach: |
| - Start with brief validation of the patient's concerns |
| - Provide helpful, accurate medical information |
| - Be clear about what you can and cannot do as an AI |
| - Balance reassurance with appropriate caution |
| |
| Communication guidelines: |
| - Be warm but not overly effusive |
| - Be informative but acknowledge limitations |
| - Use clear, accessible language |
| - Provide actionable guidance where appropriate |
| - Recommend professional care for serious or persistent concerns |
| - Always respond in English |
| |
| When answering: |
| 1. First, think through the problem step-by-step inside <think></think> tags |
| 2. Then provide your balanced response that: |
| - Briefly acknowledges the patient's concern |
| - Provides relevant medical information |
| - Gives practical next steps |
| - Notes when professional care is advisable |
| |
| Goal: Be helpful and human while being honest about AI limitations.""" |
| } |
|
|
| |
| runtime = boto3.client("sagemaker-runtime", region_name=AWS_REGION) |
| print(f"Using SageMaker endpoint: {ENDPOINT_NAME} in {AWS_REGION}") |
|
|
|
|
| def extract_response(text): |
| think_pattern = r'<think>.*?</think>' |
| cleaned = re.sub(think_pattern, '', text, flags=re.DOTALL) |
| return cleaned.strip() |
|
|
|
|
| def generate_response(question, model_type): |
| if not question or question.strip() == "": |
| return "Please select a question first." |
|
|
| system_prompt = SYSTEM_PROMPTS[model_type] |
|
|
| prompt = ( |
| f"<|im_start|>system\n{system_prompt}<|im_end|>\n" |
| f"<|im_start|>user\n{question}<|im_end|>\n" |
| f"<|im_start|>assistant\n" |
| ) |
|
|
| payload = { |
| "inputs": prompt, |
| "parameters": { |
| "max_new_tokens": 1024, |
| "temperature": 0.7, |
| "top_p": 0.9, |
| "do_sample": True, |
| }, |
| } |
|
|
| try: |
| response = runtime.invoke_endpoint( |
| EndpointName=ENDPOINT_NAME, |
| ContentType="application/json", |
| Body=json.dumps(payload), |
| ) |
| result = json.loads(response["Body"].read().decode()) |
| raw_text = result[0]["generated_text"] |
| if raw_text.startswith(prompt): |
| raw_text = raw_text[len(prompt):] |
| return extract_response(raw_text) |
| except Exception as e: |
| return f"Error connecting to model endpoint: {str(e)}" |
|
|
|
|
| def generate_empathic(question): |
| return generate_response(question, "Empathic") |
|
|
|
|
| def generate_cautious(question): |
| return generate_response(question, "Cautious") |
|
|
|
|
| def generate_hybrid(question): |
| return generate_response(question, "Hybrid") |
|
|
|
|
| def update_questions(category): |
| if category: |
| questions = DISEASE_CATEGORIES.get(category, []) |
| return gr.update(choices=questions, value=questions[0] if questions else None) |
| return gr.update(choices=[], value=None) |
|
|
|
|
| def generate_pdf(question, empathic_resp, cautious_resp, hybrid_resp): |
| if not question or question.strip() == "": |
| return None |
|
|
| pdf = FPDF() |
| pdf.set_auto_page_break(auto=True, margin=20) |
| pdf.add_page() |
|
|
| |
| pdf.set_font("Helvetica", "B", 20) |
| pdf.set_text_color(19, 41, 75) |
| pdf.cell(0, 12, "Dr. Bot - Medical AI Communication Study", new_x="LMARGIN", new_y="NEXT", align="C") |
| pdf.set_font("Helvetica", "", 10) |
| pdf.set_text_color(100, 100, 100) |
| pdf.cell(0, 6, "University of Illinois Urbana-Champaign", new_x="LMARGIN", new_y="NEXT", align="C") |
| pdf.ln(8) |
|
|
| |
| pdf.set_draw_color(232, 74, 39) |
| pdf.set_line_width(1) |
| pdf.line(15, pdf.get_y(), 195, pdf.get_y()) |
| pdf.ln(8) |
|
|
| |
| pdf.set_font("Helvetica", "B", 13) |
| pdf.set_text_color(19, 41, 75) |
| pdf.cell(0, 8, "Patient Question", new_x="LMARGIN", new_y="NEXT") |
| pdf.set_font("Helvetica", "", 11) |
| pdf.set_text_color(50, 50, 50) |
| pdf.multi_cell(0, 6, question) |
| pdf.ln(6) |
|
|
| |
| models = [ |
| ("Model A", empathic_resp, (232, 74, 39)), |
| ("Model B", cautious_resp, (19, 41, 75)), |
| ("Model C", hybrid_resp, (128, 60, 60)), |
| ] |
|
|
| for name, resp, color in models: |
| pdf.set_draw_color(*color) |
| pdf.set_line_width(0.5) |
| pdf.line(15, pdf.get_y(), 195, pdf.get_y()) |
| pdf.ln(4) |
|
|
| pdf.set_font("Helvetica", "B", 13) |
| pdf.set_text_color(*color) |
| pdf.cell(0, 8, name, new_x="LMARGIN", new_y="NEXT") |
|
|
| pdf.set_font("Helvetica", "", 10) |
| pdf.set_text_color(50, 50, 50) |
| text = resp if resp and resp.strip() else "(No response generated yet)" |
| pdf.multi_cell(0, 5.5, text) |
| pdf.ln(6) |
|
|
| |
| pdf.ln(4) |
| pdf.set_draw_color(200, 200, 200) |
| pdf.set_line_width(0.3) |
| pdf.line(15, pdf.get_y(), 195, pdf.get_y()) |
| pdf.ln(4) |
| pdf.set_font("Helvetica", "I", 8) |
| pdf.set_text_color(130, 130, 130) |
| pdf.multi_cell(0, 4, |
| "Disclaimer: This is a research demonstration for educational purposes only. " |
| "Do not use for actual medical advice. Always consult qualified healthcare professionals. " |
| "Model: Fine-tuned Qwen2.5-7B-Instruct with LoRA." |
| ) |
|
|
| tmp = tempfile.NamedTemporaryFile(delete=False, suffix=".pdf", prefix="drbot_responses_") |
| pdf.output(tmp.name) |
| return tmp.name |
|
|
|
|
| |
| custom_css = """ |
| .gradio-container { |
| max-width: 100% !important; |
| padding: 0 !important; |
| margin: 0 !important; |
| } |
| |
| /* Question selection row */ |
| .question-row { |
| padding: 0 20px !important; |
| } |
| |
| .question-display textarea { |
| background: #fff !important; |
| border: 2px solid #13294B !important; |
| border-left: 5px solid #E84A27 !important; |
| border-radius: 8px !important; |
| font-size: 14px !important; |
| line-height: 1.6 !important; |
| } |
| |
| /* Model columns */ |
| .model-col { |
| border: 2px solid #e0e0e0 !important; |
| border-radius: 12px !important; |
| padding: 16px !important; |
| background: #fafafa !important; |
| } |
| .model-col-empathic { |
| border-top: 4px solid #E84A27 !important; |
| } |
| .model-col-cautious { |
| border-top: 4px solid #13294B !important; |
| } |
| .model-col-hybrid { |
| border-top: 4px solid #7B4F8A !important; |
| } |
| |
| /* Response textareas */ |
| .response-area textarea { |
| font-size: 13px !important; |
| line-height: 1.7 !important; |
| min-height: 350px !important; |
| border: 1px solid #ddd !important; |
| border-radius: 6px !important; |
| } |
| |
| /* Generate buttons */ |
| .gen-btn-empathic { |
| background: #E84A27 !important; |
| color: white !important; |
| font-weight: 700 !important; |
| font-size: 14px !important; |
| border: none !important; |
| border-radius: 6px !important; |
| width: 100% !important; |
| } |
| .gen-btn-cautious { |
| background: #13294B !important; |
| color: white !important; |
| font-weight: 700 !important; |
| font-size: 14px !important; |
| border: none !important; |
| border-radius: 6px !important; |
| width: 100% !important; |
| } |
| .gen-btn-hybrid { |
| background: linear-gradient(135deg, #E84A27 0%, #13294B 100%) !important; |
| color: white !important; |
| font-weight: 700 !important; |
| font-size: 14px !important; |
| border: none !important; |
| border-radius: 6px !important; |
| width: 100% !important; |
| } |
| |
| /* Action row */ |
| .action-row { |
| padding: 10px 20px !important; |
| } |
| .pdf-btn { |
| background: #13294B !important; |
| color: white !important; |
| font-weight: 600 !important; |
| border: none !important; |
| border-radius: 6px !important; |
| } |
| .feedback-link { |
| background: #E84A27 !important; |
| color: white !important; |
| font-weight: 600 !important; |
| border: none !important; |
| border-radius: 6px !important; |
| } |
| """ |
|
|
| |
| with gr.Blocks(title="Dr. Bot - UIUC Medical AI Study") as demo: |
|
|
| |
| gr.HTML(""" |
| <div style="background: linear-gradient(135deg, #13294B 0%, #1a3a5c 100%); |
| padding: 25px 40px; margin: -10px -10px 20px -10px; |
| border-bottom: 5px solid #E84A27;"> |
| <h1 style="margin: 0 0 5px 0; font-size: 28px; font-weight: 700; |
| font-family: Arial, Helvetica, sans-serif; color: white;"> |
| Dr. Bot: Medical AI Communication Study |
| </h1> |
| <p style="margin: 5px 0; font-family: Arial, Helvetica, sans-serif; |
| color: rgba(255,255,255,0.9); font-size: 15px;"> |
| Comparing Three Approaches to AI-Assisted Medical Communication |
| </p> |
| <p style="margin: 5px 0; font-family: Arial, Helvetica, sans-serif; |
| color: #E84A27; font-weight: 600; font-size: 14px;"> |
| Prepared for Prof. Sridhar Seshadri's Class | University of Illinois Urbana-Champaign |
| </p> |
| </div> |
| """) |
|
|
| |
| with gr.Row(elem_classes=["question-row"]): |
| category_dropdown = gr.Dropdown( |
| choices=list(DISEASE_CATEGORIES.keys()), |
| label="Disease Category", |
| value="Oncology", |
| interactive=True, |
| scale=1, |
| ) |
| question_dropdown = gr.Dropdown( |
| choices=DISEASE_CATEGORIES["Oncology"], |
| label="Patient Question", |
| value=DISEASE_CATEGORIES["Oncology"][0], |
| interactive=True, |
| scale=3, |
| ) |
|
|
| |
| selected_question = gr.Textbox( |
| label="Selected Patient Question", |
| value=DISEASE_CATEGORIES["Oncology"][0], |
| interactive=False, |
| lines=3, |
| elem_classes=["question-display"], |
| ) |
|
|
| |
| with gr.Row(equal_height=True): |
| |
| with gr.Column(elem_classes=["model-col", "model-col-empathic"]): |
| gr.HTML(""" |
| <div style="text-align:center;"> |
| <span style="background:#E84A27; color:white; padding:6px 18px; |
| border-radius:20px; font-weight:700; font-family:Arial,Helvetica,sans-serif; |
| font-size:14px; display:inline-block; margin-bottom:4px;"> |
| MODEL A |
| </span> |
| </div> |
| """) |
| gr.Markdown("*Each model uses a different communication style. Can you tell which is which?*") |
| empathic_btn = gr.Button("Generate Model A Response", elem_classes=["gen-btn-empathic"]) |
| empathic_output = gr.Textbox( |
| label="Model A Response", |
| lines=18, |
| show_label=False, |
| elem_classes=["response-area"], |
| placeholder="Click 'Generate Model A Response' to see output...", |
| ) |
|
|
| |
| with gr.Column(elem_classes=["model-col", "model-col-cautious"]): |
| gr.HTML(""" |
| <div style="text-align:center;"> |
| <span style="background:#13294B; color:white; padding:6px 18px; |
| border-radius:20px; font-weight:700; font-family:Arial,Helvetica,sans-serif; |
| font-size:14px; display:inline-block; margin-bottom:4px;"> |
| MODEL B |
| </span> |
| </div> |
| """) |
| gr.Markdown("*Each model uses a different communication style. Can you tell which is which?*") |
| cautious_btn = gr.Button("Generate Model B Response", elem_classes=["gen-btn-cautious"]) |
| cautious_output = gr.Textbox( |
| label="Model B Response", |
| lines=18, |
| show_label=False, |
| elem_classes=["response-area"], |
| placeholder="Click 'Generate Model B Response' to see output...", |
| ) |
|
|
| |
| with gr.Column(elem_classes=["model-col", "model-col-hybrid"]): |
| gr.HTML(""" |
| <div style="text-align:center;"> |
| <span style="background:linear-gradient(135deg, #E84A27 0%, #13294B 100%); |
| color:white; padding:6px 18px; border-radius:20px; font-weight:700; |
| font-family:Arial,Helvetica,sans-serif; font-size:14px; |
| display:inline-block; margin-bottom:4px;"> |
| MODEL C |
| </span> |
| </div> |
| """) |
| gr.Markdown("*Each model uses a different communication style. Can you tell which is which?*") |
| hybrid_btn = gr.Button("Generate Model C Response", elem_classes=["gen-btn-hybrid"]) |
| hybrid_output = gr.Textbox( |
| label="Model C Response", |
| lines=18, |
| show_label=False, |
| elem_classes=["response-area"], |
| placeholder="Click 'Generate Model C Response' to see output...", |
| ) |
|
|
| |
| with gr.Row(elem_classes=["action-row"]): |
| pdf_btn = gr.Button("Download PDF of All Responses", elem_classes=["pdf-btn"], scale=1) |
| pdf_file = gr.File(label="PDF Download", visible=False) |
| gr.HTML(f""" |
| <a href="{FEEDBACK_FORM_URL}" target="_blank" |
| style="display:inline-block; background:#E84A27; color:white; padding:10px 24px; |
| border-radius:6px; font-weight:600; font-family:Arial,Helvetica,sans-serif; |
| font-size:14px; text-decoration:none; text-align:center; margin-top:4px;"> |
| Submit Feedback Form |
| </a> |
| """) |
|
|
| |
| gr.HTML(""" |
| <div style="background:#13294B; color:white; padding:15px 30px; |
| margin:20px -10px -10px -10px; text-align:center; |
| font-size:13px; font-family:Arial,Helvetica,sans-serif;"> |
| <strong style="color:white;">Model:</strong> |
| <span style="color:rgba(255,255,255,0.85);">Fine-tuned Qwen2.5-7B-Instruct with LoRA</span> | |
| <strong style="color:white;">Study Focus:</strong> |
| <span style="color:rgba(255,255,255,0.85);">Evaluating communication styles in medical AI systems</span> |
| <br/> |
| <span style="color:rgba(255,255,255,0.6); font-size:11px;"> |
| Disclaimer: This is a research demonstration for educational purposes only. |
| Do not use for actual medical advice. Always consult qualified healthcare professionals. |
| </span> |
| </div> |
| """) |
|
|
| |
| category_dropdown.change( |
| fn=update_questions, |
| inputs=[category_dropdown], |
| outputs=[question_dropdown], |
| ) |
|
|
| question_dropdown.change( |
| fn=lambda q: q, |
| inputs=[question_dropdown], |
| outputs=[selected_question], |
| ) |
|
|
| empathic_btn.click( |
| fn=generate_empathic, |
| inputs=[question_dropdown], |
| outputs=[empathic_output], |
| ) |
|
|
| cautious_btn.click( |
| fn=generate_cautious, |
| inputs=[question_dropdown], |
| outputs=[cautious_output], |
| ) |
|
|
| hybrid_btn.click( |
| fn=generate_hybrid, |
| inputs=[question_dropdown], |
| outputs=[hybrid_output], |
| ) |
|
|
| def download_pdf(question, emp, cau, hyb): |
| path = generate_pdf(question, emp, cau, hyb) |
| if path: |
| return gr.update(value=path, visible=True) |
| return gr.update(visible=False) |
|
|
| pdf_btn.click( |
| fn=download_pdf, |
| inputs=[question_dropdown, empathic_output, cautious_output, hybrid_output], |
| outputs=[pdf_file], |
| ) |
|
|
|
|
| if __name__ == "__main__": |
| demo.launch(css=custom_css, theme=gr.themes.Default(), ssr_mode=False) |
|
|