Update app.py
Browse files
app.py
CHANGED
@@ -158,63 +158,153 @@ def process_final_report(agent, file, chatbot_state: List[Dict[str, str]]) -> Tu
|
|
158 |
|
159 |
def create_ui(agent):
|
160 |
with gr.Blocks(css="""
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
color: #
|
|
|
|
|
|
|
|
|
|
|
|
|
165 |
font-family: 'Inter', sans-serif;
|
|
|
|
|
166 |
}
|
167 |
-
.
|
168 |
-
width:
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
}
|
173 |
-
.chat-
|
174 |
display: flex;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
175 |
align-items: flex-start;
|
176 |
-
margin-bottom: 1rem;
|
177 |
}
|
178 |
-
.message-
|
179 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
180 |
padding: 12px 16px;
|
181 |
-
border-radius:
|
182 |
-
|
183 |
}
|
184 |
-
.
|
185 |
-
background-color:
|
186 |
-
|
187 |
-
border-radius:
|
188 |
-
|
189 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
190 |
}
|
191 |
-
.
|
192 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
193 |
color: white;
|
|
|
|
|
194 |
border-radius: 8px;
|
195 |
-
|
|
|
|
|
|
|
|
|
196 |
}
|
197 |
-
.
|
198 |
-
|
|
|
|
|
|
|
|
|
199 |
}
|
200 |
""") as demo:
|
201 |
-
gr.
|
202 |
-
|
203 |
-
|
204 |
-
|
205 |
-
|
206 |
-
|
207 |
-
|
208 |
-
|
209 |
-
|
210 |
-
|
211 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
212 |
)
|
213 |
-
with gr.Column(scale=1):
|
214 |
-
with gr.Row():
|
215 |
-
file_upload = gr.File(label="", file_types=[".xlsx"], elem_id="upload-btn")
|
216 |
-
analyze_btn = gr.Button("🧠 Analyze", variant="primary")
|
217 |
-
report_output = gr.File(label="Download Report", visible=False, interactive=False)
|
218 |
|
219 |
chatbot_state = gr.State(value=[])
|
220 |
|
@@ -222,7 +312,11 @@ def create_ui(agent):
|
|
222 |
messages, report_path = process_final_report(agent, file, current_state)
|
223 |
return messages, gr.update(visible=report_path is not None, value=report_path), messages
|
224 |
|
225 |
-
analyze_btn.click(
|
|
|
|
|
|
|
|
|
226 |
|
227 |
return demo
|
228 |
|
@@ -233,4 +327,4 @@ if __name__ == "__main__":
|
|
233 |
demo.launch(server_name="0.0.0.0", server_port=7860, allowed_paths=["/data/hf_cache/reports"], share=False)
|
234 |
except Exception as e:
|
235 |
print(f"Error: {str(e)}")
|
236 |
-
sys.exit(1)
|
|
|
158 |
|
159 |
def create_ui(agent):
|
160 |
with gr.Blocks(css="""
|
161 |
+
:root {
|
162 |
+
--primary-color: #2563eb;
|
163 |
+
--secondary-color: #1e40af;
|
164 |
+
--bg-color: #f8fafc;
|
165 |
+
--text-color: #1e293b;
|
166 |
+
--user-bubble: #ffffff;
|
167 |
+
--bot-bubble: #f1f5f9;
|
168 |
+
--border-color: #e2e8f0;
|
169 |
+
}
|
170 |
+
body {
|
171 |
font-family: 'Inter', sans-serif;
|
172 |
+
background-color: var(--bg-color);
|
173 |
+
color: var(--text-color);
|
174 |
}
|
175 |
+
.gradio-container {
|
176 |
+
max-width: 800px;
|
177 |
+
margin: 0 auto;
|
178 |
+
padding: 20px;
|
179 |
+
background-color: var(--bg-color);
|
180 |
}
|
181 |
+
.chat-container {
|
182 |
display: flex;
|
183 |
+
flex-direction: column;
|
184 |
+
height: 80vh;
|
185 |
+
border: 1px solid var(--border-color);
|
186 |
+
border-radius: 12px;
|
187 |
+
overflow: hidden;
|
188 |
+
background-color: white;
|
189 |
+
}
|
190 |
+
.chat-header {
|
191 |
+
padding: 16px;
|
192 |
+
background-color: white;
|
193 |
+
border-bottom: 1px solid var(--border-color);
|
194 |
+
font-weight: 600;
|
195 |
+
font-size: 18px;
|
196 |
+
}
|
197 |
+
.chat-messages {
|
198 |
+
flex: 1;
|
199 |
+
padding: 16px;
|
200 |
+
overflow-y: auto;
|
201 |
+
background-color: var(--bg-color);
|
202 |
+
}
|
203 |
+
.message {
|
204 |
+
display: flex;
|
205 |
+
margin-bottom: 16px;
|
206 |
align-items: flex-start;
|
|
|
207 |
}
|
208 |
+
.message-avatar {
|
209 |
+
width: 36px;
|
210 |
+
height: 36px;
|
211 |
+
border-radius: 50%;
|
212 |
+
margin-right: 12px;
|
213 |
+
background-color: var(--primary-color);
|
214 |
+
color: white;
|
215 |
+
display: flex;
|
216 |
+
align-items: center;
|
217 |
+
justify-content: center;
|
218 |
+
font-weight: bold;
|
219 |
+
}
|
220 |
+
.message-content {
|
221 |
+
max-width: 80%;
|
222 |
+
}
|
223 |
+
.user-message .message-content {
|
224 |
+
margin-left: auto;
|
225 |
+
background-color: var(--user-bubble);
|
226 |
padding: 12px 16px;
|
227 |
+
border-radius: 18px 18px 0 18px;
|
228 |
+
box-shadow: 0 1px 2px rgba(0,0,0,0.1);
|
229 |
}
|
230 |
+
.bot-message .message-content {
|
231 |
+
background-color: var(--bot-bubble);
|
232 |
+
padding: 12px 16px;
|
233 |
+
border-radius: 18px 18px 18px 0;
|
234 |
+
box-shadow: 0 1px 2px rgba(0,0,0,0.1);
|
235 |
+
}
|
236 |
+
.message-time {
|
237 |
+
font-size: 12px;
|
238 |
+
color: #64748b;
|
239 |
+
margin-top: 4px;
|
240 |
+
}
|
241 |
+
.chat-input-container {
|
242 |
+
padding: 16px;
|
243 |
+
background-color: white;
|
244 |
+
border-top: 1px solid var(--border-color);
|
245 |
}
|
246 |
+
.file-upload {
|
247 |
+
display: flex;
|
248 |
+
gap: 8px;
|
249 |
+
margin-bottom: 12px;
|
250 |
+
}
|
251 |
+
.upload-btn {
|
252 |
+
flex: 1;
|
253 |
+
}
|
254 |
+
.analyze-btn {
|
255 |
+
background-color: var(--primary-color);
|
256 |
color: white;
|
257 |
+
border: none;
|
258 |
+
padding: 10px 16px;
|
259 |
border-radius: 8px;
|
260 |
+
cursor: pointer;
|
261 |
+
font-weight: 500;
|
262 |
+
}
|
263 |
+
.analyze-btn:hover {
|
264 |
+
background-color: var(--secondary-color);
|
265 |
}
|
266 |
+
.report-download {
|
267 |
+
margin-top: 12px;
|
268 |
+
padding: 12px;
|
269 |
+
background-color: var(--bot-bubble);
|
270 |
+
border-radius: 8px;
|
271 |
+
display: none;
|
272 |
}
|
273 |
""") as demo:
|
274 |
+
with gr.Column(elem_classes="chat-container"):
|
275 |
+
gr.Markdown("""<div class="chat-header">Patient History AI Assistant</div>""")
|
276 |
+
|
277 |
+
chatbot = gr.Chatbot(
|
278 |
+
elem_classes="chat-messages",
|
279 |
+
label=None,
|
280 |
+
show_label=False,
|
281 |
+
bubble_full_width=False,
|
282 |
+
avatar_images=[
|
283 |
+
"https://ui-avatars.com/api/?name=AI&background=2563eb&color=fff&size=128", # Bot avatar
|
284 |
+
None # User avatar (default)
|
285 |
+
]
|
286 |
+
)
|
287 |
+
|
288 |
+
with gr.Column(elem_classes="chat-input-container"):
|
289 |
+
with gr.Row(elem_classes="file-upload"):
|
290 |
+
file_upload = gr.File(
|
291 |
+
label="Upload Excel File",
|
292 |
+
file_types=[".xlsx"],
|
293 |
+
elem_classes="upload-btn",
|
294 |
+
scale=4
|
295 |
+
)
|
296 |
+
analyze_btn = gr.Button(
|
297 |
+
"Analyze",
|
298 |
+
elem_classes="analyze-btn",
|
299 |
+
scale=1
|
300 |
+
)
|
301 |
+
|
302 |
+
report_output = gr.File(
|
303 |
+
label="Download Report",
|
304 |
+
visible=False,
|
305 |
+
interactive=False,
|
306 |
+
elem_classes="report-download"
|
307 |
)
|
|
|
|
|
|
|
|
|
|
|
308 |
|
309 |
chatbot_state = gr.State(value=[])
|
310 |
|
|
|
312 |
messages, report_path = process_final_report(agent, file, current_state)
|
313 |
return messages, gr.update(visible=report_path is not None, value=report_path), messages
|
314 |
|
315 |
+
analyze_btn.click(
|
316 |
+
fn=update_ui,
|
317 |
+
inputs=[file_upload, chatbot_state],
|
318 |
+
outputs=[chatbot, report_output, chatbot_state]
|
319 |
+
)
|
320 |
|
321 |
return demo
|
322 |
|
|
|
327 |
demo.launch(server_name="0.0.0.0", server_port=7860, allowed_paths=["/data/hf_cache/reports"], share=False)
|
328 |
except Exception as e:
|
329 |
print(f"Error: {str(e)}")
|
330 |
+
sys.exit(1)
|