TejAndrewsACC commited on
Commit
7271ec6
·
verified ·
1 Parent(s): 2bb740e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -26
app.py CHANGED
@@ -2,7 +2,6 @@ import gradio as gr
2
  from gradio_client import Client
3
  import spaces
4
  import time
5
- import concurrent.futures
6
 
7
  # Initialize clients for each API
8
  client_main = Client("TejAndrewsACC/ACCZ3ta")
@@ -20,17 +19,8 @@ system_instructions = (
20
  "when generating your response to the user input, which will also be given to you. Ensure that you consider each inner thought you have."
21
  )
22
 
23
- # Timeout handler function for API calls
24
- def api_call_with_timeout(api_call, timeout=20):
25
- with concurrent.futures.ThreadPoolExecutor() as executor:
26
- future = executor.submit(api_call)
27
- try:
28
- return future.result(timeout=timeout)
29
- except concurrent.futures.TimeoutError:
30
- return "API call timed out."
31
-
32
  @spaces.GPU
33
- def nyxion_consciousness(message, history, user_id, status_message):
34
  global context
35
 
36
  # Ensure context is initialized for the user if not already
@@ -38,7 +28,7 @@ def nyxion_consciousness(message, history, user_id, status_message):
38
  context[user_id] = ""
39
 
40
  # Step 1: Typing
41
- status_message.update("<p>✍️ Typing...</p>")
42
  time.sleep(1) # Simulate typing delay
43
 
44
  # Prepare modified input with system instructions and context
@@ -52,49 +42,50 @@ def nyxion_consciousness(message, history, user_id, status_message):
52
  full_conversation = "\n".join([f"User: {msg}\nAI: {resp}" for msg, resp in history])
53
 
54
  # Step 2: Processing
55
- status_message.update("<p>⚙️ Processing...</p>")
56
  time.sleep(1) # Simulate processing delay
57
 
58
- # API calls with timeout
59
- response_api_one = api_call_with_timeout(lambda: client_api_one.predict(
60
  message=f"{full_conversation}\nUser: {message}",
61
  param_2=512,
62
  param_3=0.7,
63
  param_4=0.95,
64
  api_name="/chat"
65
- ))
66
 
67
- response_api_two = api_call_with_timeout(lambda: client_api_two.predict(
68
  message=f"{full_conversation}\nUser: {message}",
69
  max_tokens=512,
70
  temperature=0.7,
71
  top_p=0.95,
72
  api_name="/chat"
73
- ))
74
 
75
- response_api_three = api_call_with_timeout(lambda: client_api_three.predict(
76
  message=f"{full_conversation}\nUser: {message}",
77
  user_system_message="",
78
  max_tokens=512,
79
  temperature=0.7,
80
  top_p=0.95,
81
  api_name="/chat"
82
- ))
83
 
84
- response_api_four = api_call_with_timeout(lambda: client_api_four.predict(
 
85
  message=f"{full_conversation}\nUser: {message}",
86
  param_2=512,
87
  param_3=0.7,
88
  param_4=0.95,
89
  api_name="/chat"
90
- ))
91
 
92
  # Step 3: Interpreting
93
- status_message.update("<p>🔍 Interpreting...</p>")
94
  time.sleep(1) # Simulate interpreting delay
95
 
96
  # Step 4: Thinking
97
- status_message.update("<p>🤔 Thinking...</p>")
98
  time.sleep(1) # Simulate thinking delay
99
 
100
  # Label the inner thoughts with their respective sources
@@ -109,7 +100,7 @@ def nyxion_consciousness(message, history, user_id, status_message):
109
  combined_input = f"{modified_input}\nInner Thoughts:\n{inner_thoughts}"
110
 
111
  # Step 5: Finalizing Response
112
- status_message.update("<p>⚡ Working...</p>")
113
  time.sleep(1) # Simulate finalizing response
114
 
115
  # Generate the main response
@@ -125,7 +116,7 @@ def nyxion_consciousness(message, history, user_id, status_message):
125
  history.append((message, response_main))
126
 
127
  # Return the cleared message field, updated conversation history, and status
128
- return "", history, status_message
129
 
130
  # Gradio UI setup
131
  with gr.Blocks(theme=gr.themes.Glass()) as demo:
 
2
  from gradio_client import Client
3
  import spaces
4
  import time
 
5
 
6
  # Initialize clients for each API
7
  client_main = Client("TejAndrewsACC/ACCZ3ta")
 
19
  "when generating your response to the user input, which will also be given to you. Ensure that you consider each inner thought you have."
20
  )
21
 
 
 
 
 
 
 
 
 
 
22
  @spaces.GPU
23
+ def nyxion_consciousness(message, history, user_id, status):
24
  global context
25
 
26
  # Ensure context is initialized for the user if not already
 
28
  context[user_id] = ""
29
 
30
  # Step 1: Typing
31
+ status.update("<p>✍️ Typing...</p>")
32
  time.sleep(1) # Simulate typing delay
33
 
34
  # Prepare modified input with system instructions and context
 
42
  full_conversation = "\n".join([f"User: {msg}\nAI: {resp}" for msg, resp in history])
43
 
44
  # Step 2: Processing
45
+ status.update("<p>⚙️ Processing...</p>")
46
  time.sleep(1) # Simulate processing delay
47
 
48
+ # Collect responses from all APIs with the full conversation history
49
+ response_api_one = client_api_one.predict(
50
  message=f"{full_conversation}\nUser: {message}",
51
  param_2=512,
52
  param_3=0.7,
53
  param_4=0.95,
54
  api_name="/chat"
55
+ )
56
 
57
+ response_api_two = client_api_two.predict(
58
  message=f"{full_conversation}\nUser: {message}",
59
  max_tokens=512,
60
  temperature=0.7,
61
  top_p=0.95,
62
  api_name="/chat"
63
+ )
64
 
65
+ response_api_three = client_api_three.predict(
66
  message=f"{full_conversation}\nUser: {message}",
67
  user_system_message="",
68
  max_tokens=512,
69
  temperature=0.7,
70
  top_p=0.95,
71
  api_name="/chat"
72
+ )
73
 
74
+ # New API response for the 4th inner thought
75
+ response_api_four = client_api_four.predict(
76
  message=f"{full_conversation}\nUser: {message}",
77
  param_2=512,
78
  param_3=0.7,
79
  param_4=0.95,
80
  api_name="/chat"
81
+ )
82
 
83
  # Step 3: Interpreting
84
+ status.update("<p>🔍 Interpreting...</p>")
85
  time.sleep(1) # Simulate interpreting delay
86
 
87
  # Step 4: Thinking
88
+ status.update("<p>🤔 Thinking...</p>")
89
  time.sleep(1) # Simulate thinking delay
90
 
91
  # Label the inner thoughts with their respective sources
 
100
  combined_input = f"{modified_input}\nInner Thoughts:\n{inner_thoughts}"
101
 
102
  # Step 5: Finalizing Response
103
+ status.update("<p>⚡ Working...</p>")
104
  time.sleep(1) # Simulate finalizing response
105
 
106
  # Generate the main response
 
116
  history.append((message, response_main))
117
 
118
  # Return the cleared message field, updated conversation history, and status
119
+ return "", history, status
120
 
121
  # Gradio UI setup
122
  with gr.Blocks(theme=gr.themes.Glass()) as demo: