Update app.py
Browse files
app.py
CHANGED
@@ -62,7 +62,7 @@ question_examples = [
|
|
62 |
["A 30-year-old patient is on Prozac for depression and now diagnosed with WHIM syndrome. Is Xolremdi suitable?"]
|
63 |
]
|
64 |
|
65 |
-
agent = None #
|
66 |
|
67 |
|
68 |
# === Create Gradio UI ===
|
@@ -86,19 +86,34 @@ def create_ui():
|
|
86 |
show_copy_button=True
|
87 |
)
|
88 |
|
89 |
-
# ===
|
90 |
-
def
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
91 |
agent.update_parameters(seed=random.randint(0, 10000))
|
92 |
new_history = history[:retry_data.index]
|
93 |
prompt = history[retry_data.index]["content"]
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
|
|
|
|
|
|
|
|
|
|
98 |
)
|
99 |
-
if hasattr(result, "__iter__") and not isinstance(result, (str, list, dict)):
|
100 |
-
result = list(result)
|
101 |
-
return result
|
102 |
|
103 |
chatbot.retry(
|
104 |
handle_retry,
|
@@ -107,13 +122,6 @@ def create_ui():
|
|
107 |
multi_agent, conversation_state, max_round
|
108 |
)
|
109 |
|
110 |
-
# === Chat handler
|
111 |
-
def handle_chat(message, history, temperature, max_new_tokens, max_tokens, multi_agent, conversation, max_round):
|
112 |
-
result = agent.run_gradio_chat(message, history, temperature, max_new_tokens, max_tokens, multi_agent, conversation, max_round)
|
113 |
-
if hasattr(result, "__iter__") and not isinstance(result, (str, list, dict)):
|
114 |
-
result = list(result)
|
115 |
-
return result
|
116 |
-
|
117 |
# === Chat Interface setup
|
118 |
gr.ChatInterface(
|
119 |
fn=handle_chat,
|
@@ -134,7 +142,7 @@ def create_ui():
|
|
134 |
return demo
|
135 |
|
136 |
|
137 |
-
# === HF Spaces +
|
138 |
if __name__ == "__main__":
|
139 |
agent = TxAgent(
|
140 |
model_name,
|
@@ -149,4 +157,4 @@ if __name__ == "__main__":
|
|
149 |
agent.init_model()
|
150 |
|
151 |
demo = create_ui()
|
152 |
-
demo.launch()
|
|
|
62 |
["A 30-year-old patient is on Prozac for depression and now diagnosed with WHIM syndrome. Is Xolremdi suitable?"]
|
63 |
]
|
64 |
|
65 |
+
agent = None # will be initialized in main
|
66 |
|
67 |
|
68 |
# === Create Gradio UI ===
|
|
|
86 |
show_copy_button=True
|
87 |
)
|
88 |
|
89 |
+
# === Chat handler (streaming)
|
90 |
+
async def handle_chat(message, history, temperature, max_new_tokens, max_tokens, multi_agent, conversation, max_round):
|
91 |
+
return agent.run_gradio_chat(
|
92 |
+
message=message,
|
93 |
+
history=history,
|
94 |
+
temperature=temperature,
|
95 |
+
max_new_tokens=max_new_tokens,
|
96 |
+
max_token=max_tokens,
|
97 |
+
call_agent=multi_agent,
|
98 |
+
conversation=conversation,
|
99 |
+
max_round=max_round
|
100 |
+
)
|
101 |
+
|
102 |
+
# === Retry handler (also streaming-compatible)
|
103 |
+
async def handle_retry(history, retry_data, temperature, max_new_tokens, max_tokens, multi_agent, conversation, max_round):
|
104 |
agent.update_parameters(seed=random.randint(0, 10000))
|
105 |
new_history = history[:retry_data.index]
|
106 |
prompt = history[retry_data.index]["content"]
|
107 |
+
return agent.run_gradio_chat(
|
108 |
+
message=prompt,
|
109 |
+
history=new_history,
|
110 |
+
temperature=temperature,
|
111 |
+
max_new_tokens=max_new_tokens,
|
112 |
+
max_token=max_tokens,
|
113 |
+
call_agent=multi_agent,
|
114 |
+
conversation=conversation,
|
115 |
+
max_round=max_round
|
116 |
)
|
|
|
|
|
|
|
117 |
|
118 |
chatbot.retry(
|
119 |
handle_retry,
|
|
|
122 |
multi_agent, conversation_state, max_round
|
123 |
)
|
124 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
125 |
# === Chat Interface setup
|
126 |
gr.ChatInterface(
|
127 |
fn=handle_chat,
|
|
|
142 |
return demo
|
143 |
|
144 |
|
145 |
+
# === HF Spaces + local launch entrypoint ===
|
146 |
if __name__ == "__main__":
|
147 |
agent = TxAgent(
|
148 |
model_name,
|
|
|
157 |
agent.init_model()
|
158 |
|
159 |
demo = create_ui()
|
160 |
+
demo.launch(show_error=True)
|