Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,22 +1,55 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from nivra_agent import nivra_chat
|
| 3 |
|
| 4 |
-
|
| 5 |
def chat_fn(message, history):
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
|
| 22 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from nivra_agent import nivra_chat
|
| 3 |
|
|
|
|
| 4 |
def chat_fn(message, history):
|
| 5 |
+
history = history or []
|
| 6 |
+
response = nivra_chat(message, history)
|
| 7 |
+
history.append((message, response))
|
| 8 |
+
return history, ""
|
| 9 |
+
|
| 10 |
+
CSS = """
|
| 11 |
+
#chatbot {
|
| 12 |
+
height: 420px;
|
| 13 |
+
overflow-y: auto;
|
| 14 |
+
border-radius: 12px;
|
| 15 |
+
}
|
| 16 |
+
.gradio-container {
|
| 17 |
+
max-width: 900px !important;
|
| 18 |
+
margin: auto;
|
| 19 |
+
}
|
| 20 |
+
"""
|
| 21 |
+
|
| 22 |
+
with gr.Blocks(css=CSS, title="🩺 Nivra AI Agent") as demo:
|
| 23 |
+
gr.Markdown(
|
| 24 |
+
"""
|
| 25 |
+
# 🩺 Nivra AI Agent
|
| 26 |
+
_AI-powered healthcare assistant for preliminary medical guidance._
|
| 27 |
+
"""
|
| 28 |
+
)
|
| 29 |
+
|
| 30 |
+
chatbot = gr.Chatbot(
|
| 31 |
+
elem_id="chatbot",
|
| 32 |
+
bubble_full_width=False,
|
| 33 |
+
show_label=False,
|
| 34 |
+
)
|
| 35 |
|
| 36 |
+
with gr.Row():
|
| 37 |
+
txt = gr.Textbox(
|
| 38 |
+
placeholder="Describe your symptoms (e.g. fever, headache, chills)...",
|
| 39 |
+
scale=8,
|
| 40 |
+
show_label=False,
|
| 41 |
+
)
|
| 42 |
+
send = gr.Button("Send", scale=1)
|
| 43 |
+
|
| 44 |
+
send.click(chat_fn, inputs=[txt, chatbot], outputs=[chatbot, txt])
|
| 45 |
+
txt.submit(chat_fn, inputs=[txt, chatbot], outputs=[chatbot, txt])
|
| 46 |
+
|
| 47 |
+
gr.Markdown(
|
| 48 |
+
"⚠️ *Not a doctor. For emergencies, consult a medical professional immediately.*"
|
| 49 |
+
)
|
| 50 |
+
|
| 51 |
+
demo.launch(
|
| 52 |
+
server_name="0.0.0.0",
|
| 53 |
+
server_port=7860,
|
| 54 |
+
ssr_mode=False, # 🔥 THIS fixes layout weirdness on HF
|
| 55 |
+
)
|