natasha1704's picture
Update app.py
8a09dd6 verified
"""
Gradio UI entry‑point for the WellBe+ Assistant.
This file focuses *exclusively* on building and launching the UI. Business
logic remains in ``wellbe_agent.py`` so that the web interface stays lean and
maintainable.
"""
from __future__ import annotations
import gradio as gr
from wellbe_agent import answer_sync
DESCRIPTION_MD = (
"WellBe+ AI Agent is a multi‑context assistant built with the Agents SDK framework "
"from OpenAI. It orchestrates **three secure MCP servers**: a public drug‑knowledge FDA "
"service, PubMed and WHOOP biometric feed.\n\n"
"Ask how medications, habits or workouts influence your sleep and recovery – the agent "
"combines **medical knowledge** with your **personal Whoop data** to craft evidence‑backed "
"answers.\n\n"
"### Example questions\n"
"- *What are the adverse effects of Tamoxifen?*\n"
"- *I started taking Prozac three months ago. Have you noticed any trends in my sleep quality? Also, what are its most common side effects?*\n\n"
"### MCP Servers in use\n"
"- [Whoop](https://huggingface.co/spaces/Agents-MCP-Hackathon/whoop-mcp-server)\n"
"- [Healthcare MCP with PubMed, FDA and other APIs](https://huggingface.co/spaces/Agents-MCP-Hackathon/healthcare-mcp-public)\n"
)
logo_html = """
<img src="https://raw.githubusercontent.com/Alea4jacta6est/drug-interaction-checker-agent/main/docs/images/logo.png"
alt="WellBe+" width="80">
<h1>WellBe+ Assistant</h1>
"""
def build_interface() -> gr.Blocks:
"""Construct and return the Gradio interface for the WellBe+ Assistant."""
custom_css = """
@import url('https://fonts.googleapis.com/css2?family=Nunito:wght@400;600&display=swap');
* {
font-family: 'Nunito', sans-serif;
}
"""
with gr.Blocks(title="WellBe+ Assistant", css=custom_css) as app:
gr.HTML(logo_html) # Logo and title together
gr.Markdown("")
with gr.Row():
with gr.Column(scale=2):
gr.Markdown(DESCRIPTION_MD)
with gr.Column(scale=1):
gr.Markdown("### How to use")
gr.Video(value="docs/demo.mp4", autoplay=True)
with gr.Row():
# -----------------------------------------------------------------
# Left column – credential inputs
# -----------------------------------------------------------------
with gr.Column(scale=1):
gr.Markdown("### Credentials")
openai_key_box = gr.Textbox(
label="OpenAI API Key",
type="password",
placeholder="sk‑…",
)
whoop_email_box = gr.Textbox(label="Whoop e‑mail", type="password")
whoop_pass_box = gr.Textbox(label="Whoop password", type="password")
# -----------------------------------------------------------------
# Right column – chat interface
# -----------------------------------------------------------------
with gr.Column(scale=2):
gr.Markdown("### Chat")
question_box = gr.Textbox(
label="Question",
lines=3,
placeholder="e.g. How has my sleep changed since starting Prozac last month?",
)
answer_box = gr.Textbox(label="Assistant", lines=8, interactive=False)
ask_btn = gr.Button("Explore Insights", variant="primary")
ask_btn.click(
fn=answer_sync,
inputs=[
question_box,
openai_key_box,
whoop_email_box,
whoop_pass_box,
],
outputs=answer_box,
)
gr.Markdown(
"---\nBuilt by [Natalia B.](https://www.linkedin.com/in/natalia-bobkova/), [Victoria L.](https://www.linkedin.com/in/victoria-latynina/)"
)
return app
if __name__ == "__main__":
build_interface().launch()