Spaces:
Sleeping
Sleeping
Update app.py
Browse filesField for bot ID.
app.py
CHANGED
@@ -4,6 +4,8 @@ import requests
|
|
4 |
def send_message_with_secret(message, history, api_secret, bot_id):
|
5 |
if not api_secret.strip():
|
6 |
return "Please enter your API secret in the field above."
|
|
|
|
|
7 |
|
8 |
API_URL = "https://api.kindroid.ai/v1/send-message"
|
9 |
headers = {
|
@@ -23,55 +25,93 @@ def send_message_with_secret(message, history, api_secret, bot_id):
|
|
23 |
except requests.exceptions.RequestException as e:
|
24 |
return f"An error occurred: {e}"
|
25 |
|
26 |
-
with gr.Blocks(
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
53 |
|
54 |
-
|
55 |
-
|
56 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
57 |
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
75 |
|
76 |
if __name__ == "__main__":
|
77 |
app.launch()
|
|
|
4 |
def send_message_with_secret(message, history, api_secret, bot_id):
|
5 |
if not api_secret.strip():
|
6 |
return "Please enter your API secret in the field above."
|
7 |
+
if not bot_id.strip():
|
8 |
+
return "Please enter your Bot ID."
|
9 |
|
10 |
API_URL = "https://api.kindroid.ai/v1/send-message"
|
11 |
headers = {
|
|
|
25 |
except requests.exceptions.RequestException as e:
|
26 |
return f"An error occurred: {e}"
|
27 |
|
28 |
+
with gr.Blocks(css="""
|
29 |
+
.message.user {
|
30 |
+
background-color: #2563eb !important;
|
31 |
+
color: white !important;
|
32 |
+
border-radius: 12px 12px 0 12px !important;
|
33 |
+
margin-left: auto !important;
|
34 |
+
margin-right: 1rem !important;
|
35 |
+
}
|
36 |
+
.message.bot {
|
37 |
+
background-color: #f3f4f6 !important;
|
38 |
+
border-radius: 12px 12px 12px 0 !important;
|
39 |
+
margin-right: auto !important;
|
40 |
+
margin-left: 1rem !important;
|
41 |
+
}
|
42 |
+
.message.user, .message.bot {
|
43 |
+
padding: 1rem !important;
|
44 |
+
margin-bottom: 1rem !important;
|
45 |
+
max-width: 80% !important;
|
46 |
+
display: inline-block !important;
|
47 |
+
}
|
48 |
+
.message-wrap {
|
49 |
+
display: flex !important;
|
50 |
+
flex-direction: column !important;
|
51 |
+
}
|
52 |
+
.contain {
|
53 |
+
margin: 0 auto;
|
54 |
+
max-width: 800px;
|
55 |
+
padding: 20px;
|
56 |
+
}
|
57 |
+
.input-row {
|
58 |
+
margin-bottom: 20px;
|
59 |
+
}
|
60 |
+
""") as app:
|
61 |
|
62 |
+
with gr.Column(elem_classes="contain"):
|
63 |
+
gr.Markdown("## Chat with your Kin")
|
64 |
+
|
65 |
+
with gr.Column(elem_classes="input-row"):
|
66 |
+
api_secret = gr.Textbox(
|
67 |
+
label="API Secret",
|
68 |
+
placeholder="Enter your API secret...",
|
69 |
+
type="password",
|
70 |
+
show_label=True
|
71 |
+
)
|
72 |
|
73 |
+
bot_id = gr.Textbox(
|
74 |
+
label="Bot ID",
|
75 |
+
placeholder="Enter your Bot ID...",
|
76 |
+
show_label=True
|
77 |
+
)
|
78 |
+
|
79 |
+
chatbot = gr.Chatbot(
|
80 |
+
value=[],
|
81 |
+
type='messages',
|
82 |
+
height=400
|
83 |
+
)
|
84 |
+
|
85 |
+
with gr.Row():
|
86 |
+
msg = gr.Textbox(
|
87 |
+
label="Message",
|
88 |
+
placeholder="Type your message here...",
|
89 |
+
show_label=False,
|
90 |
+
scale=9
|
91 |
+
)
|
92 |
+
|
93 |
+
send_btn = gr.Button("Send", scale=1)
|
94 |
+
|
95 |
+
def respond(message, chat_history, api_secret, bot_id):
|
96 |
+
if not message:
|
97 |
+
return chat_history, ""
|
98 |
+
|
99 |
+
bot_response = send_message_with_secret(message, chat_history, api_secret, bot_id)
|
100 |
+
chat_history.append({"role": "user", "content": message})
|
101 |
+
chat_history.append({"role": "assistant", "content": bot_response})
|
102 |
+
return chat_history, ""
|
103 |
+
|
104 |
+
msg.submit(
|
105 |
+
respond,
|
106 |
+
inputs=[msg, chatbot, api_secret, bot_id],
|
107 |
+
outputs=[chatbot, msg]
|
108 |
+
)
|
109 |
+
|
110 |
+
send_btn.click(
|
111 |
+
respond,
|
112 |
+
inputs=[msg, chatbot, api_secret, bot_id],
|
113 |
+
outputs=[chatbot, msg]
|
114 |
+
)
|
115 |
|
116 |
if __name__ == "__main__":
|
117 |
app.launch()
|