runebloodstone commited on
Commit
952731e
·
verified ·
1 Parent(s): 41f9a38

Update app.py

Browse files

Field for bot ID.

Files changed (1) hide show
  1. app.py +87 -47
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() as app:
27
- gr.Markdown("## Chat with your Kin")
28
-
29
- api_secret = gr.Textbox(
30
- label="API Secret",
31
- placeholder="Enter your API secret...",
32
- type="password",
33
- show_label=True
34
- )
35
-
36
- bot_id = gr.Textbox(
37
- label="Bot ID",
38
- placeholder="Enter your BotID...",
39
- show_label=True
40
- )
41
-
42
- chatbot = gr.Chatbot(
43
- value=[],
44
- type='messages',
45
- height=400
46
- )
47
-
48
- msg = gr.Textbox(
49
- label="Message",
50
- placeholder="Type your message here...",
51
- show_label=False
52
- )
 
 
 
 
 
 
53
 
54
- def respond(message, chat_history, api_secret):
55
- if not message:
56
- return chat_history, ""
 
 
 
 
 
 
 
57
 
58
- bot_response = send_message_with_secret(message, chat_history, api_secret, bot_id)
59
- chat_history.append({"role": "user", "content": message})
60
- chat_history.append({"role": "assistant", "content": bot_response})
61
- return chat_history, ""
62
-
63
- msg.submit(
64
- respond,
65
- inputs=[msg, chatbot, api_secret, bot_id],
66
- outputs=[chatbot, msg]
67
- )
68
-
69
- send_btn = gr.Button("Send")
70
- send_btn.click(
71
- respond,
72
- inputs=[msg, chatbot, api_secret],
73
- outputs=[chatbot, msg]
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()