File size: 3,114 Bytes
1704015
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9e16f37
bb4c26d
 
9e16f37
2a9e135
1704015
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4d7216a
1704015
 
 
 
4d7216a
1704015
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4d7216a
1704015
 
 
1
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import gradio as gr
from utils import reset_patient, set_patient, ask_another_question
from regular_rag import qa_tool_regular_rag
from graph_rag import qa_tool_graph_rag
import logging

logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')
logger = logging.getLogger(__name__)

def qa_tool(user_question, method):
    logger.info(f"Method selected: {method}")
    if method == "Regular RAG":
        answer, images, ask_another_visible, change_patient_visible = qa_tool_regular_rag(user_question)
        logger.info("Regular RAG answer generated")
        logger.info(f"Regular RAG images: {images}")  # Additional log for debugging
        return answer, images, ask_another_visible, change_patient_visible, gr.update(visible=False)
    elif method == "Graph-RAG":
        answer, images, ask_another_visible, change_patient_visible = qa_tool_graph_rag(user_question)
        logger.info("Graph-RAG answer generated")
        logger.info(f"Graph-RAG images: {images}")  # Additional log for debugging
        return answer, images, ask_another_visible, change_patient_visible, gr.update(visible=True)



with gr.Blocks() as app:
    gr.Markdown("# Clinical Diagram QA Tool")

    with gr.Group() as patient_input:
        patient_desc = gr.Textbox(label="Patient Description")
        set_patient_btn = gr.Button("Set Patient")

    with gr.Group() as qa_interface:
        qa_desc = gr.Markdown()
        question_input = gr.Textbox(label="Enter your question")
        method_choice = gr.Radio(["Regular RAG", "Graph-RAG"], label="Select Method")
        get_answer_btn = gr.Button("Get Answer")
        answer_output = gr.Textbox(label="Answer")
        graph_output = gr.Plot(label="Knowledge Graph Visualization")
        ask_another_question_btn = gr.Button("Ask Another Question")
        change_patient_btn = gr.Button("Set Another Patient")

    qa_interface.visible = False
    ask_another_question_btn.visible = False
    change_patient_btn.visible = False

    set_patient_btn.click(
        set_patient,
        inputs=[patient_desc],
        outputs=[
            qa_desc,
            qa_interface,
            patient_input,
            question_input,
            answer_output,
            graph_output,
            ask_another_question_btn,
            change_patient_btn
        ]
    )

    get_answer_btn.click(
        qa_tool,
        inputs=[question_input, method_choice],
        outputs=[answer_output, ask_another_question_btn, change_patient_btn, graph_output]
    )

    ask_another_question_btn.click(
        ask_another_question,
        outputs=[question_input, answer_output, graph_output, get_answer_btn, ask_another_question_btn]
    )

    change_patient_btn.click(
        reset_patient,
        outputs=[
            patient_desc,
            qa_desc,
            patient_input,
            qa_interface,
            change_patient_btn,
            question_input,
            answer_output,
            graph_output
        ]
    )


if __name__ == "__main__":
    logger.info("Starting the application")
    app.launch()