Spaces:
Runtime error
Runtime error
Commit
•
2bb6ffc
1
Parent(s):
64b1095
Update app.py
Browse files
app.py
CHANGED
@@ -273,7 +273,28 @@ def analyse_query(query):
|
|
273 |
else:
|
274 |
return f"After you answer the patient's query, if you think it is the right time, ask him the following question like a doctor would normally do :{current_question}"
|
275 |
|
276 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
277 |
def generate_response(query, img="", is_there_img=False):
|
278 |
global memory
|
279 |
report_question = analyse_query(query)
|
@@ -519,7 +540,8 @@ def back():
|
|
519 |
return gr.update(visible=False),gr.update(visible=True),gr.update(visible=True),gr.update(visible=True),gr.update(visible=False)
|
520 |
|
521 |
def move_next_page(a, b, c, d):
|
522 |
-
patient_info1
|
|
|
523 |
patient_info2 = c
|
524 |
patient_info3 = d
|
525 |
return (
|
@@ -532,13 +554,14 @@ def move_next_page(a, b, c, d):
|
|
532 |
|
533 |
|
534 |
def view_report():
|
535 |
-
|
536 |
-
|
537 |
-
|
538 |
-
|
539 |
-
|
540 |
-
|
541 |
-
|
|
|
542 |
|
543 |
|
544 |
css = """.gradio-container {
|
@@ -601,11 +624,9 @@ with gr.Blocks(css=css) as demo:
|
|
601 |
pdf_btn = gr.Button("عرض التقرير الطبي", size="sm", variant="primary")
|
602 |
with gr.Group(visible=False) as pdf_report:
|
603 |
gr.HTML(not_talking)
|
604 |
-
gr.HTML(
|
605 |
-
|
606 |
-
|
607 |
-
"""
|
608 |
-
)
|
609 |
with gr.Row():
|
610 |
back_btn = gr.Button("العودة إلى المحادثة", size="sm", variant="primary")
|
611 |
|
@@ -640,7 +661,7 @@ with gr.Blocks(css=css) as demo:
|
|
640 |
outputs=[page1, page2, chatbot, html_block, pdf_report],
|
641 |
)
|
642 |
pdf_btn.click(
|
643 |
-
view_report, outputs=[page1, page2, chatbot, html_block, pdf_report]
|
644 |
)
|
645 |
back_btn.click(
|
646 |
back, outputs=[page1, page2, chatbot, html_block, pdf_report]
|
|
|
273 |
else:
|
274 |
return f"After you answer the patient's query, if you think it is the right time, ask him the following question like a doctor would normally do :{current_question}"
|
275 |
|
276 |
+
def prepare_patient_info():
|
277 |
+
default_value = ""
|
278 |
+
patient_info = {
|
279 |
+
"name": patient_info1,
|
280 |
+
"age": patient_info2,
|
281 |
+
"gender": patient_info3,
|
282 |
+
}
|
283 |
+
print(patient_info)
|
284 |
+
for i, key in enumerate(["symptoms", "medications", "conditions_allergies", "lifestyle_changes"]):
|
285 |
+
patient_info[key] = answers[i] if i < len(answers) else default_value
|
286 |
+
|
287 |
+
medical_image_path = "lung disease.png"
|
288 |
+
try:
|
289 |
+
patient_info["medical_image"] = base64.b64encode(open(medical_image_path, "rb").read()).decode()
|
290 |
+
except FileNotFoundError:
|
291 |
+
patient_info["medical_image"] = default_value
|
292 |
+
|
293 |
+
patient_info.update({
|
294 |
+
"header_image": base64.b64encode(open("logo1.png", "rb").read()).decode(),
|
295 |
+
})
|
296 |
+
return patient_info
|
297 |
+
|
298 |
def generate_response(query, img="", is_there_img=False):
|
299 |
global memory
|
300 |
report_question = analyse_query(query)
|
|
|
540 |
return gr.update(visible=False),gr.update(visible=True),gr.update(visible=True),gr.update(visible=True),gr.update(visible=False)
|
541 |
|
542 |
def move_next_page(a, b, c, d):
|
543 |
+
global patient_info1, patient_info2, patient_info3
|
544 |
+
patient_info1 = a + " " + b
|
545 |
patient_info2 = c
|
546 |
patient_info3 = d
|
547 |
return (
|
|
|
554 |
|
555 |
|
556 |
def view_report():
|
557 |
+
patient_info = prepare_patient_info()
|
558 |
+
generate_report(patient_info)
|
559 |
+
report_html ="""
|
560 |
+
<embed src="/file=output.pdf" type="application/pdf" width="100%" height="700px" />
|
561 |
+
"""
|
562 |
+
print("report is generated")
|
563 |
+
time.sleep(0.5)
|
564 |
+
return gr.update(visible=False),gr.update(visible=False),gr.update(visible=False),gr.update(visible=False),gr.update(visible=True),report_html
|
565 |
|
566 |
|
567 |
css = """.gradio-container {
|
|
|
624 |
pdf_btn = gr.Button("عرض التقرير الطبي", size="sm", variant="primary")
|
625 |
with gr.Group(visible=False) as pdf_report:
|
626 |
gr.HTML(not_talking)
|
627 |
+
report_html = gr.HTML("""
|
628 |
+
<embed src="/file=output.pdf" type="application/pdf" width="100%" height="700px" />
|
629 |
+
""")
|
|
|
|
|
630 |
with gr.Row():
|
631 |
back_btn = gr.Button("العودة إلى المحادثة", size="sm", variant="primary")
|
632 |
|
|
|
661 |
outputs=[page1, page2, chatbot, html_block, pdf_report],
|
662 |
)
|
663 |
pdf_btn.click(
|
664 |
+
view_report, outputs=[page1, page2, chatbot, html_block, pdf_report, report_html]
|
665 |
)
|
666 |
back_btn.click(
|
667 |
back, outputs=[page1, page2, chatbot, html_block, pdf_report]
|