Spaces:
Paused
Paused
Commit
·
c20d411
1
Parent(s):
6a2015d
created conversational functcionality
Browse files
app.py
CHANGED
@@ -213,11 +213,33 @@ ANSWER: {res['question']['output']}
|
|
213 |
{res['conversation']}
|
214 |
"""
|
215 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
216 |
|
217 |
demo = gr.Interface(
|
218 |
-
fn=
|
219 |
-
inputs=
|
220 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
221 |
title="🧠 AI Doctor Multi-Agent Reasoning",
|
222 |
)
|
223 |
|
|
|
213 |
{res['conversation']}
|
214 |
"""
|
215 |
|
216 |
+
# === Stateful Gradio UI ===
|
217 |
+
def stateful_ui_fn(user_input, history):
|
218 |
+
# Initialize or retrieve history list
|
219 |
+
history = history or []
|
220 |
+
# Append the new patient utterance
|
221 |
+
history.append(f"Patient: {user_input}")
|
222 |
+
# Run one round of simulation
|
223 |
+
res = simulate_interaction(user_input)
|
224 |
+
# Extract last doctor line from the fresh conversation
|
225 |
+
last_line = res['conversation'].splitlines()[-1]
|
226 |
+
# Append the doctor's new line
|
227 |
+
history.append(last_line)
|
228 |
+
# Build the displayed conversation
|
229 |
+
convo = "\n".join(history)
|
230 |
+
# Return both the display text and updated history
|
231 |
+
return convo, history
|
232 |
|
233 |
demo = gr.Interface(
|
234 |
+
fn=stateful_ui_fn,
|
235 |
+
inputs=[
|
236 |
+
gr.Textbox(label="Patient Response"),
|
237 |
+
gr.State([]), # holds the conversation history
|
238 |
+
],
|
239 |
+
outputs=[
|
240 |
+
gr.Textbox(label="Doctor Simulation Output"),
|
241 |
+
gr.State(), # returns the updated history
|
242 |
+
],
|
243 |
title="🧠 AI Doctor Multi-Agent Reasoning",
|
244 |
)
|
245 |
|