Rajan Sharma
Update app.py
0b1c3ed verified
raw
history blame
1.87 kB
# -------------------
# UI
# -------------------
with gr.Blocks(theme=gr.themes.Default()) as demo:
# Hidden textbox to hold browser timezone
tz_box = gr.Textbox(visible=False)
# On load, capture browser timezone via JS and write it into tz_box
demo.load(
fn=lambda tz: tz,
inputs=[tz_box],
outputs=[tz_box],
js="() => Intl.DateTimeFormat().resolvedOptions().timeZone"
)
# Automatically determine connection info once tz is available
def model_status(user_tz):
try:
if USE_HOSTED_COHERE:
return "βœ… Connected to: Cohere API (model: command-r7b-12-2024)"
api = HfApi(token=HF_TOKEN)
mi = api.model_info(MODEL_ID)
return f"βœ… Connected to: Local HF model ({mi.modelId})"
except Exception as e:
return f"❌ Connection Error: {e}"
# Heading
gr.Markdown("# Medical Decision Support AI")
# One-line status bar
status_line = gr.Markdown("Connecting...")
demo.load(fn=model_status, inputs=[tz_box], outputs=[status_line])
gr.Markdown(
"βš™οΈ First response may take a moment while the model warms up. "
# "Currently configured to use **Cohere hosted API** if `COHERE_API_KEY` is set; "
# "otherwise, tries **local HF**."
)
chat = gr.ChatInterface(
fn=chat_fn,
type="messages",
additional_inputs=[tz_box],
description="A medical decision support system that provides healthcare-related information and decision making support.",
examples=[
["What are the symptoms of hypertension?", ""],
["What are common drug interactions with aspirin?", ""],
["What are the warning signs of diabetes?", ""],
],
cache_examples=True,
)
if __name__ == "__main__":
demo.launch()