Spaces:
Sleeping
Sleeping
Update app.py
Browse filesFixed interface.
app.py
CHANGED
@@ -1,6 +1,5 @@
|
|
1 |
import gradio as gr
|
2 |
import requests
|
3 |
-
from functools import partial
|
4 |
|
5 |
def send_message_with_secret(message, history, api_secret):
|
6 |
if not api_secret.strip():
|
@@ -26,49 +25,6 @@ def send_message_with_secret(message, history, api_secret):
|
|
26 |
except requests.exceptions.RequestException as e:
|
27 |
return f"An error occurred: {e}"
|
28 |
|
29 |
-
def create_chat_interface(api_secret):
|
30 |
-
# Partially apply the api_secret to the send_message function
|
31 |
-
send_fn = partial(send_message_with_secret, api_secret=api_secret)
|
32 |
-
|
33 |
-
return gr.ChatInterface(
|
34 |
-
fn=send_fn,
|
35 |
-
title="Chat with Your Kin",
|
36 |
-
description="Send messages and receive responses in a chat-like interface",
|
37 |
-
examples=[
|
38 |
-
["Hello! How are you today?"],
|
39 |
-
["Tell me about yourself"],
|
40 |
-
],
|
41 |
-
theme=gr.themes.Soft(
|
42 |
-
primary_hue="blue",
|
43 |
-
secondary_hue="gray",
|
44 |
-
),
|
45 |
-
css="""
|
46 |
-
.message.user {
|
47 |
-
background-color: #2563eb !important;
|
48 |
-
color: white !important;
|
49 |
-
border-radius: 12px 12px 0 12px !important;
|
50 |
-
margin-left: auto !important;
|
51 |
-
margin-right: 1rem !important;
|
52 |
-
}
|
53 |
-
.message.bot {
|
54 |
-
background-color: #f3f4f6 !important;
|
55 |
-
border-radius: 12px 12px 12px 0 !important;
|
56 |
-
margin-right: auto !important;
|
57 |
-
margin-left: 1rem !important;
|
58 |
-
}
|
59 |
-
.message.user, .message.bot {
|
60 |
-
padding: 1rem !important;
|
61 |
-
margin-bottom: 1rem !important;
|
62 |
-
max-width: 80% !important;
|
63 |
-
display: inline-block !important;
|
64 |
-
}
|
65 |
-
.message-wrap {
|
66 |
-
display: flex !important;
|
67 |
-
flex-direction: column !important;
|
68 |
-
}
|
69 |
-
"""
|
70 |
-
)
|
71 |
-
|
72 |
with gr.Blocks() as app:
|
73 |
gr.Markdown("## AI Chat Interface")
|
74 |
|
@@ -79,15 +35,38 @@ with gr.Blocks() as app:
|
|
79 |
show_label=True
|
80 |
)
|
81 |
|
82 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
83 |
|
84 |
-
|
85 |
-
|
|
|
|
|
|
|
86 |
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
|
|
91 |
)
|
92 |
|
93 |
if __name__ == "__main__":
|
|
|
1 |
import gradio as gr
|
2 |
import requests
|
|
|
3 |
|
4 |
def send_message_with_secret(message, history, api_secret):
|
5 |
if not api_secret.strip():
|
|
|
25 |
except requests.exceptions.RequestException as e:
|
26 |
return f"An error occurred: {e}"
|
27 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
28 |
with gr.Blocks() as app:
|
29 |
gr.Markdown("## AI Chat Interface")
|
30 |
|
|
|
35 |
show_label=True
|
36 |
)
|
37 |
|
38 |
+
chatbot = gr.Chatbot(
|
39 |
+
value=[],
|
40 |
+
type='messages',
|
41 |
+
height=400
|
42 |
+
)
|
43 |
+
|
44 |
+
msg = gr.Textbox(
|
45 |
+
label="Message",
|
46 |
+
placeholder="Type your message here...",
|
47 |
+
show_label=False
|
48 |
+
)
|
49 |
+
|
50 |
+
def respond(message, chat_history, api_secret):
|
51 |
+
if not message:
|
52 |
+
return chat_history, ""
|
53 |
+
|
54 |
+
bot_response = send_message_with_secret(message, chat_history, api_secret)
|
55 |
+
chat_history.append({"role": "user", "content": message})
|
56 |
+
chat_history.append({"role": "assistant", "content": bot_response})
|
57 |
+
return chat_history, ""
|
58 |
|
59 |
+
msg.submit(
|
60 |
+
respond,
|
61 |
+
inputs=[msg, chatbot, api_secret],
|
62 |
+
outputs=[chatbot, msg]
|
63 |
+
)
|
64 |
|
65 |
+
send_btn = gr.Button("Send")
|
66 |
+
send_btn.click(
|
67 |
+
respond,
|
68 |
+
inputs=[msg, chatbot, api_secret],
|
69 |
+
outputs=[chatbot, msg]
|
70 |
)
|
71 |
|
72 |
if __name__ == "__main__":
|