File size: 1,549 Bytes
88317c7
3492c23
 
 
 
 
b023803
88317c7
3492c23
 
 
88317c7
3492c23
b023803
3492c23
 
 
 
 
 
 
 
b023803
3492c23
 
 
88317c7
 
 
 
 
 
 
 
 
 
 
 
3492c23
b023803
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
import gradio as gr

def create_ui(agent):
    with gr.Blocks(theme=gr.themes.Soft()) as demo:
        gr.Markdown("<h1 style='text-align: center;'>💊 TxAgent: Therapeutic Reasoning</h1>")
        chatbot = gr.Chatbot(label="TxAgent", height=600, type="messages")

        file_upload = gr.File(label="Upload Medical File", file_types=[".pdf", ".txt", ".docx", ".jpg", ".png"])
        message_input = gr.Textbox(placeholder="Ask a biomedical question...", show_label=False)
        send_button = gr.Button("Send", variant="primary")
        conversation_state = gr.State([])
        file_state = gr.State(None)

        def handle_chat(message, history, conversation, uploaded_files):
            generator = agent.run_gradio_chat(
                message=message,
                history=history,
                temperature=0.3,
                max_new_tokens=1024,
                max_token=8192,
                call_agent=False,
                conversation=conversation,
                uploaded_files=[uploaded_files] if uploaded_files else [],
                max_round=30
            )
            for update in generator:
                yield update

        inputs = [message_input, chatbot, conversation_state, file_upload]
        send_button.click(fn=handle_chat, inputs=inputs, outputs=chatbot)
        message_input.submit(fn=handle_chat, inputs=inputs, outputs=chatbot)

        gr.Examples(
            examples=[
                ["Upload the files"],
            ],
            inputs=message_input,
        )

    return demo