Reality123b commited on
Commit
491769d
·
verified ·
1 Parent(s): e319620

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -7
app.py CHANGED
@@ -2,7 +2,14 @@ import os
2
  import base64
3
  import requests
4
  import gradio as gr
5
- from huggingface_hub import InferenceClient, ChatMessage
 
 
 
 
 
 
 
6
 
7
  class XylariaChat:
8
  def __init__(self):
@@ -26,7 +33,9 @@ class XylariaChat:
26
  self.persistent_memory = {}
27
 
28
  # System prompt with more detailed instructions
29
- self.system_prompt = """You are a helpful and harmless assistant. You are Xylaria developed by Sk Md Saad Amin(india, 12 year old). You should think step-by-step."""
 
 
30
 
31
  def store_information(self, key, value):
32
  """Store important information in persistent memory"""
@@ -240,11 +249,16 @@ class XylariaChat:
240
  placeholder="Type your message...",
241
  container=False
242
  )
243
- img = gr.Image(
244
- sources=["upload", "webcam"],
245
- type="filepath",
246
- label="Upload or Capture Image"
247
- )
 
 
 
 
 
248
 
249
  btn = gr.Button("Send", scale=1)
250
 
@@ -253,6 +267,13 @@ class XylariaChat:
253
  clear = gr.Button("Clear Conversation")
254
  clear_memory = gr.Button("Clear Memory")
255
 
 
 
 
 
 
 
 
256
  # Submit functionality with streaming and image support
257
  btn.click(
258
  fn=streaming_response,
 
2
  import base64
3
  import requests
4
  import gradio as gr
5
+ from huggingface_hub import InferenceClient
6
+ from dataclasses import dataclass
7
+
8
+ @dataclass
9
+ class ChatMessage:
10
+ """Custom ChatMessage class since huggingface_hub doesn't provide one"""
11
+ role: str
12
+ content: str
13
 
14
  class XylariaChat:
15
  def __init__(self):
 
33
  self.persistent_memory = {}
34
 
35
  # System prompt with more detailed instructions
36
+ self.system_prompt = """You are a helpful and harmless AI assistant named Xylaria.
37
+ Always think step-by-step and provide clear, thoughtful responses.
38
+ Be kind, ethical, and supportive in your interactions."""
39
 
40
  def store_information(self, key, value):
41
  """Store important information in persistent memory"""
 
249
  placeholder="Type your message...",
250
  container=False
251
  )
252
+
253
+ # Image upload as a separate button
254
+ with gr.Row():
255
+ img = gr.Image(
256
+ sources=["upload", "webcam"],
257
+ type="filepath",
258
+ label="Upload Image",
259
+ visible=False
260
+ )
261
+ upload_btn = gr.Button("Upload Image")
262
 
263
  btn = gr.Button("Send", scale=1)
264
 
 
267
  clear = gr.Button("Clear Conversation")
268
  clear_memory = gr.Button("Clear Memory")
269
 
270
+ # Image upload toggle
271
+ upload_btn.click(
272
+ fn=lambda: gr.update(visible=True),
273
+ inputs=None,
274
+ outputs=[img]
275
+ )
276
+
277
  # Submit functionality with streaming and image support
278
  btn.click(
279
  fn=streaming_response,