Spaces:
Running
Update app.py
Browse filesMajor Update
- Send Button:
What Changed: A "Send" button has been added to the chat interface.
Why It Matters: Users can now click this button to send their messages instead of just pressing the Enter key. This makes it easier for people who prefer using a mouse or want a clearer way to submit their messages.
- Chat History:
What Changed: The application now keeps track of the conversation history during the session.
Why It Matters: Users can see all previous messages exchanged in the chat while they are using it. However, if they close the tab, the history will be lost. This feature helps users keep track of their conversation without needing to remember everything.
- Image Upload for Analysis:
What Changed: A feature has been added that allows users to upload images for the chatbot to analyze.
Why It Matters: Users can send pictures to the chatbot, which can then provide feedback or insights based on those images. This makes the chatbot more interactive and versatile, as it can now handle both text and images.
@@ -14,18 +14,31 @@ def chat_with_gemini(message, chat_history):
|
|
14 |
chat_history.append((message, bot_response)) # Append the user and bot messages as a tuple
|
15 |
return chat_history, chat_history
|
16 |
|
|
|
|
|
|
|
|
|
|
|
|
|
17 |
# Create a Gradio interface
|
18 |
with gr.Blocks() as iface:
|
19 |
gr.Markdown("# Ken Chatbot")
|
20 |
-
gr.Markdown("Ask me anything!")
|
21 |
|
22 |
chatbot = gr.Chatbot(elem_id="chatbot") # Initialize the chatbot with an element ID for styling
|
23 |
-
msg = gr.Textbox(label="Type your message here...", placeholder="Enter your message
|
|
|
24 |
state = gr.State([]) # Store chat history
|
25 |
|
26 |
-
#
|
27 |
-
|
28 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
29 |
|
30 |
# Custom CSS for styling the chatbot messages
|
31 |
gr.HTML("""
|
|
|
14 |
chat_history.append((message, bot_response)) # Append the user and bot messages as a tuple
|
15 |
return chat_history, chat_history
|
16 |
|
17 |
+
def analyze_image(image, chat_history):
|
18 |
+
# Convert the image to text or generate a response based on the image (placeholder function)
|
19 |
+
bot_response = llm.predict("Analyze this image.") # Replace with the actual image analysis function if available
|
20 |
+
chat_history.append(("Image sent", bot_response))
|
21 |
+
return chat_history, chat_history
|
22 |
+
|
23 |
# Create a Gradio interface
|
24 |
with gr.Blocks() as iface:
|
25 |
gr.Markdown("# Ken Chatbot")
|
26 |
+
gr.Markdown("Ask me anything or upload an image for analysis!")
|
27 |
|
28 |
chatbot = gr.Chatbot(elem_id="chatbot") # Initialize the chatbot with an element ID for styling
|
29 |
+
msg = gr.Textbox(label="Type your message here...", placeholder="Enter your message...")
|
30 |
+
send_btn = gr.Button("Send") # New Send button for submitting text messages
|
31 |
state = gr.State([]) # Store chat history
|
32 |
|
33 |
+
# Image upload component for image analysis
|
34 |
+
img_upload = gr.Image(type="filepath", label="Upload an image for analysis")
|
35 |
+
|
36 |
+
# Set up the interactions
|
37 |
+
send_btn.click(chat_with_gemini, [msg, state], [chatbot, state]) # Submit message on button click
|
38 |
+
send_btn.click(lambda: "", None, msg) # Clear text box on submit
|
39 |
+
|
40 |
+
# Image submission event for analysis
|
41 |
+
img_upload.change(analyze_image, [img_upload, state], [chatbot, state])
|
42 |
|
43 |
# Custom CSS for styling the chatbot messages
|
44 |
gr.HTML("""
|