Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -15,11 +15,7 @@ def authorize(user, api_key, system_message):
|
|
15 |
"user": user,
|
16 |
"key": api_key
|
17 |
}
|
18 |
-
test_headers = {
|
19 |
-
'Accept': 'application/json'
|
20 |
-
}
|
21 |
|
22 |
-
print("Preparing to send the request...")
|
23 |
try:
|
24 |
response = requests.post(
|
25 |
"https://host.palple.polrambora.com/check_key_impv",
|
@@ -28,7 +24,6 @@ def authorize(user, api_key, system_message):
|
|
28 |
|
29 |
if response.status_code == 200:
|
30 |
response_json = response.json()
|
31 |
-
print(f"Response: {response_json}")
|
32 |
|
33 |
if api_key not in sessions:
|
34 |
sessions[api_key] = {
|
@@ -39,22 +34,12 @@ def authorize(user, api_key, system_message):
|
|
39 |
},
|
40 |
"system_message": system_message
|
41 |
}
|
42 |
-
|
43 |
return True
|
44 |
else:
|
45 |
-
print(f"Failed request - Status code: {response.status_code}, Response: {response.text}")
|
46 |
return False
|
47 |
-
except requests.exceptions.Timeout:
|
48 |
-
print("Request timed out")
|
49 |
-
return False
|
50 |
-
except requests.exceptions.ConnectionError:
|
51 |
-
print("Network problem occurred (DNS failure, refused connection, etc.)")
|
52 |
-
return False
|
53 |
except Exception as e:
|
54 |
-
print(f"Exception occurred: {str(e)}")
|
55 |
return False
|
56 |
|
57 |
-
|
58 |
def respond(message, api_key, max_tokens, top_p, temperature):
|
59 |
session = sessions.get(api_key, {})
|
60 |
history = session.get("history", [])
|
@@ -93,17 +78,12 @@ def respond(message, api_key, max_tokens, top_p, temperature):
|
|
93 |
if response.status_code == 200:
|
94 |
response_json = response.json()
|
95 |
assistant_reply = response_json["msq"]["message"][0]
|
96 |
-
|
97 |
-
|
98 |
history.append((message, assistant_reply, "You", "P-ALPLE", USER_PIC_PATH, ASSISTANT_PIC_PATH))
|
99 |
sessions[api_key]["history"] = history
|
100 |
-
|
101 |
return history, assistant_reply
|
102 |
else:
|
103 |
return history, "Error: " + response.json().get("error", "Unknown error occurred.")
|
104 |
|
105 |
-
|
106 |
-
|
107 |
def render_message(history):
|
108 |
messages_html = """
|
109 |
<div id="chatbox-container" class="chatbox" style="height: 400px; overflow-y: auto; border: 1px solid #262626; padding: 10px; background-color: #171717;">
|
@@ -123,8 +103,6 @@ def render_message(history):
|
|
123 |
messages_html += f"<span style='color: white;'>{assistant_message}</span></div><br>"
|
124 |
|
125 |
messages_html += "</div></div>"
|
126 |
-
|
127 |
-
|
128 |
return messages_html
|
129 |
|
130 |
js = """
|
@@ -150,12 +128,11 @@ function Scrolldown() {
|
|
150 |
}
|
151 |
"""
|
152 |
|
153 |
-
|
154 |
with gr.Blocks(css=".chatbox {height: 400px; overflow-y: auto; border: 1px solid #262626; padding: 10px; background-color: #171717;}", js=js) as demo:
|
155 |
|
156 |
with gr.Column(visible=True) as auth_view:
|
157 |
gr.Markdown("## P-MSQ Authorization")
|
158 |
-
gr.Markdown("P-MSQ is in closed alpha test! The model, api and more are subject to change.
|
159 |
api_user_input = gr.Textbox(placeholder="snowflake", label="UserID", type='email')
|
160 |
api_key_input = gr.Textbox(placeholder="Enter your API key", label="Token", type='password')
|
161 |
auth_button = gr.Button("Authorize")
|
@@ -193,8 +170,6 @@ with gr.Blocks(css=".chatbox {height: 400px; overflow-y: auto; border: 1px solid
|
|
193 |
history, assistant_reply = respond(message, api_key, max_tokens, top_p, temperature)
|
194 |
return render_message(history), history, "", gr.HTML("<script>Scrolldown();</script>")
|
195 |
|
196 |
-
|
197 |
-
|
198 |
def regenerate_response(history, last_message, max_tokens, top_p, temperature):
|
199 |
return "", []
|
200 |
|
@@ -253,7 +228,6 @@ with gr.Blocks(css=".chatbox {height: 400px; overflow-y: auto; border: 1px solid
|
|
253 |
gr.Warning("Your session has been expired, please refresh the page and login again.")
|
254 |
return "Session not found.", gr.update(value="")
|
255 |
|
256 |
-
|
257 |
auth_button.click(authorize_and_proceed, inputs=[api_user_input, api_key_input], outputs=[auth_view, chat_view, chatbot_output, history_state])
|
258 |
save_instructions_btn.click(save_custom_instructions, inputs=[api_key_input, system_instructions_input], outputs=auth_status)
|
259 |
demo.load(lambda: None, [], None)
|
|
|
15 |
"user": user,
|
16 |
"key": api_key
|
17 |
}
|
|
|
|
|
|
|
18 |
|
|
|
19 |
try:
|
20 |
response = requests.post(
|
21 |
"https://host.palple.polrambora.com/check_key_impv",
|
|
|
24 |
|
25 |
if response.status_code == 200:
|
26 |
response_json = response.json()
|
|
|
27 |
|
28 |
if api_key not in sessions:
|
29 |
sessions[api_key] = {
|
|
|
34 |
},
|
35 |
"system_message": system_message
|
36 |
}
|
|
|
37 |
return True
|
38 |
else:
|
|
|
39 |
return False
|
|
|
|
|
|
|
|
|
|
|
|
|
40 |
except Exception as e:
|
|
|
41 |
return False
|
42 |
|
|
|
43 |
def respond(message, api_key, max_tokens, top_p, temperature):
|
44 |
session = sessions.get(api_key, {})
|
45 |
history = session.get("history", [])
|
|
|
78 |
if response.status_code == 200:
|
79 |
response_json = response.json()
|
80 |
assistant_reply = response_json["msq"]["message"][0]
|
|
|
|
|
81 |
history.append((message, assistant_reply, "You", "P-ALPLE", USER_PIC_PATH, ASSISTANT_PIC_PATH))
|
82 |
sessions[api_key]["history"] = history
|
|
|
83 |
return history, assistant_reply
|
84 |
else:
|
85 |
return history, "Error: " + response.json().get("error", "Unknown error occurred.")
|
86 |
|
|
|
|
|
87 |
def render_message(history):
|
88 |
messages_html = """
|
89 |
<div id="chatbox-container" class="chatbox" style="height: 400px; overflow-y: auto; border: 1px solid #262626; padding: 10px; background-color: #171717;">
|
|
|
103 |
messages_html += f"<span style='color: white;'>{assistant_message}</span></div><br>"
|
104 |
|
105 |
messages_html += "</div></div>"
|
|
|
|
|
106 |
return messages_html
|
107 |
|
108 |
js = """
|
|
|
128 |
}
|
129 |
"""
|
130 |
|
|
|
131 |
with gr.Blocks(css=".chatbox {height: 400px; overflow-y: auto; border: 1px solid #262626; padding: 10px; background-color: #171717;}", js=js) as demo:
|
132 |
|
133 |
with gr.Column(visible=True) as auth_view:
|
134 |
gr.Markdown("## P-MSQ Authorization")
|
135 |
+
gr.Markdown("P-MSQ is in closed alpha test! The model, api and more are subject to change.")
|
136 |
api_user_input = gr.Textbox(placeholder="snowflake", label="UserID", type='email')
|
137 |
api_key_input = gr.Textbox(placeholder="Enter your API key", label="Token", type='password')
|
138 |
auth_button = gr.Button("Authorize")
|
|
|
170 |
history, assistant_reply = respond(message, api_key, max_tokens, top_p, temperature)
|
171 |
return render_message(history), history, "", gr.HTML("<script>Scrolldown();</script>")
|
172 |
|
|
|
|
|
173 |
def regenerate_response(history, last_message, max_tokens, top_p, temperature):
|
174 |
return "", []
|
175 |
|
|
|
228 |
gr.Warning("Your session has been expired, please refresh the page and login again.")
|
229 |
return "Session not found.", gr.update(value="")
|
230 |
|
|
|
231 |
auth_button.click(authorize_and_proceed, inputs=[api_user_input, api_key_input], outputs=[auth_view, chat_view, chatbot_output, history_state])
|
232 |
save_instructions_btn.click(save_custom_instructions, inputs=[api_key_input, system_instructions_input], outputs=auth_status)
|
233 |
demo.load(lambda: None, [], None)
|