CPS-Test-Mobile / ui /ui_core.py
Ali2206's picture
Update ui/ui_core.py
15b59c6 verified
raw
history blame
1.55 kB
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