RomZay commited on
Commit
f565471
·
verified ·
1 Parent(s): 3411c78

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -12
app.py CHANGED
@@ -4,18 +4,12 @@ import json
4
  import os
5
 
6
  API_URL = "https://host.palple.polrambora.com/pmsq"
7
- API_TOKEN = os.getenv("POLLY")
8
- URL_HEADER = os.getenv("KEY")
9
- headers = {
10
- "authorization": "",
11
- "Content-Type": 'application/json',
12
- }
13
 
14
  ASSISTANT_PIC_PATH = "https://huggingface.co/spaces/PLRMB/P-MSQ-API-PREVIEW/resolve/main/API.png"
15
  USER_PIC_PATH = "https://huggingface.co/spaces/PLRMB/P-MSQ-API-PREVIEW/resolve/main/usr.png"
16
 
17
- sessions = {}
18
-
19
  def authorize(user, api_key):
20
  test_data = {
21
  "user": user,
@@ -34,11 +28,16 @@ def authorize(user, api_key):
34
 
35
  if response.status_code == 200:
36
  response_json = response.json()
37
- headers['authorization'] = api_key
38
  print(f"Response: {response_json}")
39
 
40
  if api_key not in sessions:
41
- sessions[api_key] = []
 
 
 
 
 
 
42
 
43
  return True
44
  else:
@@ -56,7 +55,9 @@ def authorize(user, api_key):
56
 
57
 
58
  def respond(message, api_key, system_message, max_tokens, top_p, temperature):
59
- history = sessions.get(api_key, [])
 
 
60
 
61
  messages = []
62
  for user_message, assistant_message, user_profile, assistant_profile, user_pic, assistant_pic in history:
@@ -93,7 +94,8 @@ def respond(message, api_key, system_message, max_tokens, top_p, temperature):
93
  assistant_reply = response_json["msq"]["message"][0]
94
 
95
  history.append((message, assistant_reply, "You", "P-ALPLE", USER_PIC_PATH, ASSISTANT_PIC_PATH))
96
- sessions[api_key] = history
 
97
  return history, assistant_reply
98
  else:
99
  return history, "Error: " + response.json().get("error", "Unknown error occurred.")
 
4
  import os
5
 
6
  API_URL = "https://host.palple.polrambora.com/pmsq"
7
+
8
+ sessions = {}
 
 
 
 
9
 
10
  ASSISTANT_PIC_PATH = "https://huggingface.co/spaces/PLRMB/P-MSQ-API-PREVIEW/resolve/main/API.png"
11
  USER_PIC_PATH = "https://huggingface.co/spaces/PLRMB/P-MSQ-API-PREVIEW/resolve/main/usr.png"
12
 
 
 
13
  def authorize(user, api_key):
14
  test_data = {
15
  "user": user,
 
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] = {
35
+ "history": [],
36
+ "headers": {
37
+ "authorization": api_key,
38
+ "Content-Type": 'application/json'
39
+ }
40
+ }
41
 
42
  return True
43
  else:
 
55
 
56
 
57
  def respond(message, api_key, system_message, max_tokens, top_p, temperature):
58
+ session = sessions.get(api_key, {})
59
+ history = session.get("history", [])
60
+ headers = session.get("headers", {})
61
 
62
  messages = []
63
  for user_message, assistant_message, user_profile, assistant_profile, user_pic, assistant_pic in history:
 
94
  assistant_reply = response_json["msq"]["message"][0]
95
 
96
  history.append((message, assistant_reply, "You", "P-ALPLE", USER_PIC_PATH, ASSISTANT_PIC_PATH))
97
+ sessions[api_key]["history"] = history
98
+
99
  return history, assistant_reply
100
  else:
101
  return history, "Error: " + response.json().get("error", "Unknown error occurred.")