Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -223,7 +223,7 @@ class XylariaChat:
|
|
223 |
if len(self.conversation_history) > 10:
|
224 |
self.conversation_history = self.conversation_history[-10:]
|
225 |
|
226 |
-
# Custom CSS for Inter font
|
227 |
custom_css = """
|
228 |
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');
|
229 |
|
@@ -240,6 +240,43 @@ class XylariaChat:
|
|
240 |
.gradio-container button {
|
241 |
font-family: 'Inter', sans-serif !important;
|
242 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
243 |
"""
|
244 |
|
245 |
with gr.Blocks(theme='soft', css=custom_css) as demo:
|
@@ -249,28 +286,28 @@ class XylariaChat:
|
|
249 |
label="Xylaria 1.4 Senoa",
|
250 |
height=500,
|
251 |
show_copy_button=True,
|
252 |
-
|
253 |
)
|
254 |
|
255 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
256 |
with gr.Row():
|
257 |
with gr.Column(scale=4):
|
258 |
txt = gr.Textbox(
|
259 |
-
show_label=False,
|
260 |
-
placeholder="Type your message...",
|
261 |
container=False
|
262 |
)
|
263 |
-
|
264 |
-
# Image upload as a separate button
|
265 |
-
with gr.Row():
|
266 |
-
img = gr.Image(
|
267 |
-
sources=["upload", "webcam"],
|
268 |
-
type="filepath",
|
269 |
-
label="Upload Image",
|
270 |
-
visible=False
|
271 |
-
)
|
272 |
-
upload_btn = gr.Button("Upload Image")
|
273 |
-
|
274 |
btn = gr.Button("Send", scale=1)
|
275 |
|
276 |
# Clear history and memory buttons
|
@@ -278,44 +315,45 @@ class XylariaChat:
|
|
278 |
clear = gr.Button("Clear Conversation")
|
279 |
clear_memory = gr.Button("Clear Memory")
|
280 |
|
281 |
-
|
282 |
-
|
283 |
-
|
284 |
-
|
285 |
-
|
286 |
-
|
|
|
287 |
|
288 |
-
|
289 |
-
|
290 |
-
|
291 |
-
|
292 |
-
|
293 |
-
|
294 |
-
|
295 |
-
|
296 |
-
|
297 |
-
|
298 |
-
|
299 |
|
300 |
-
|
301 |
-
|
302 |
-
|
303 |
-
|
304 |
-
|
305 |
-
|
306 |
-
|
307 |
|
308 |
-
|
309 |
-
|
310 |
-
|
311 |
-
|
312 |
-
|
313 |
-
|
314 |
-
|
|
|
|
|
|
|
315 |
|
316 |
-
# Ensure memory is cleared when the interface is closed
|
317 |
-
demo.load(self.reset_conversation, None, None)
|
318 |
-
|
319 |
return demo
|
320 |
|
321 |
# Launch the interface
|
|
|
223 |
if len(self.conversation_history) > 10:
|
224 |
self.conversation_history = self.conversation_history[-10:]
|
225 |
|
226 |
+
# Custom CSS for Inter font and improved styling
|
227 |
custom_css = """
|
228 |
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');
|
229 |
|
|
|
240 |
.gradio-container button {
|
241 |
font-family: 'Inter', sans-serif !important;
|
242 |
}
|
243 |
+
|
244 |
+
/* Image Upload Styling */
|
245 |
+
.image-container {
|
246 |
+
border: 1px solid #ccc;
|
247 |
+
border-radius: 8px;
|
248 |
+
padding: 10px;
|
249 |
+
margin-bottom: 10px;
|
250 |
+
display: flex;
|
251 |
+
flex-direction: column;
|
252 |
+
align-items: center;
|
253 |
+
gap: 10px;
|
254 |
+
background-color: #f8f8f8;
|
255 |
+
}
|
256 |
+
|
257 |
+
.image-preview {
|
258 |
+
max-width: 200px;
|
259 |
+
max-height: 200px;
|
260 |
+
border-radius: 8px;
|
261 |
+
}
|
262 |
+
|
263 |
+
.image-buttons {
|
264 |
+
display: flex;
|
265 |
+
gap: 10px;
|
266 |
+
}
|
267 |
+
|
268 |
+
.image-buttons button {
|
269 |
+
padding: 8px 15px;
|
270 |
+
border-radius: 5px;
|
271 |
+
background-color: #4CAF50;
|
272 |
+
color: white;
|
273 |
+
border: none;
|
274 |
+
cursor: pointer;
|
275 |
+
}
|
276 |
+
|
277 |
+
.image-buttons button:hover {
|
278 |
+
background-color: #367c39;
|
279 |
+
}
|
280 |
"""
|
281 |
|
282 |
with gr.Blocks(theme='soft', css=custom_css) as demo:
|
|
|
286 |
label="Xylaria 1.4 Senoa",
|
287 |
height=500,
|
288 |
show_copy_button=True,
|
|
|
289 |
)
|
290 |
|
291 |
+
# Enhanced Image Upload Section
|
292 |
+
with gr.Accordion("Image Input", open=False):
|
293 |
+
with gr.Column() as image_container: # Use a Column for the image container
|
294 |
+
img = gr.Image(
|
295 |
+
sources=["upload", "webcam"],
|
296 |
+
type="filepath",
|
297 |
+
label="", # Remove label as it's redundant
|
298 |
+
elem_classes="image-preview", # Add a class for styling
|
299 |
+
)
|
300 |
+
with gr.Row():
|
301 |
+
clear_image_btn = gr.Button("Clear Image")
|
302 |
+
|
303 |
+
# Input row with improved layout
|
304 |
with gr.Row():
|
305 |
with gr.Column(scale=4):
|
306 |
txt = gr.Textbox(
|
307 |
+
show_label=False,
|
308 |
+
placeholder="Type your message...",
|
309 |
container=False
|
310 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
311 |
btn = gr.Button("Send", scale=1)
|
312 |
|
313 |
# Clear history and memory buttons
|
|
|
315 |
clear = gr.Button("Clear Conversation")
|
316 |
clear_memory = gr.Button("Clear Memory")
|
317 |
|
318 |
+
# Clear image functionality
|
319 |
+
clear_image_btn.click(
|
320 |
+
fn=lambda: None,
|
321 |
+
inputs=None,
|
322 |
+
outputs=[img],
|
323 |
+
queue=False
|
324 |
+
)
|
325 |
|
326 |
+
# Submit functionality with streaming and image support
|
327 |
+
btn.click(
|
328 |
+
fn=streaming_response,
|
329 |
+
inputs=[txt, chatbot, img],
|
330 |
+
outputs=[txt, chatbot, img]
|
331 |
+
)
|
332 |
+
txt.submit(
|
333 |
+
fn=streaming_response,
|
334 |
+
inputs=[txt, chatbot, img],
|
335 |
+
outputs=[txt, chatbot, img]
|
336 |
+
)
|
337 |
|
338 |
+
# Clear conversation history
|
339 |
+
clear.click(
|
340 |
+
fn=lambda: None,
|
341 |
+
inputs=None,
|
342 |
+
outputs=[chatbot],
|
343 |
+
queue=False
|
344 |
+
)
|
345 |
|
346 |
+
# Clear persistent memory and reset conversation
|
347 |
+
clear_memory.click(
|
348 |
+
fn=self.reset_conversation,
|
349 |
+
inputs=None,
|
350 |
+
outputs=[chatbot],
|
351 |
+
queue=False
|
352 |
+
)
|
353 |
+
|
354 |
+
# Ensure memory is cleared when the interface is closed
|
355 |
+
demo.load(self.reset_conversation, None, None)
|
356 |
|
|
|
|
|
|
|
357 |
return demo
|
358 |
|
359 |
# Launch the interface
|