TejAndrewsACC commited on
Commit
607940a
·
verified ·
1 Parent(s): ad120b7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -30
app.py CHANGED
@@ -9,8 +9,6 @@ import threading
9
  import random
10
  import time
11
 
12
- #---------ACC Neural Netwoking Classes (same as original)---------
13
-
14
  class GA(nn.Module):
15
  def __init__(self, input_dim, output_dim):
16
  super(GA, self).__init__()
@@ -57,13 +55,12 @@ class CNN(nn.Module):
57
  super(CNN, self).__init__()
58
  self.conv = nn.Conv2d(input_channels, 16, kernel_size=3, stride=1, padding=1)
59
  self.pool = nn.MaxPool2d(kernel_size=2, stride=2)
60
- # CNN
61
- self.fc = nn.Linear(16 * 4 * 8, output_dim) # 16 * 4 * 8 = 512
62
 
63
  def forward(self, x):
64
  x = self.pool(torch.relu(self.conv(x)))
65
- print(f"Shape after conv and pool: {x.shape}") # Check the output shape
66
- x = x.view(x.size(0), -1) # Flatten for the fully connected layer
67
  return torch.sigmoid(self.fc(x))
68
 
69
 
@@ -75,8 +72,6 @@ class PhiModel(nn.Module):
75
  def forward(self, x):
76
  return torch.sigmoid(self.linear(x))
77
 
78
- # Initialize models (same as original)
79
-
80
  ga_model = GA(128, 64)
81
  snn_model = SNN(128, 64, 32)
82
  rnn_model = RNN(128, 64, 32)
@@ -84,20 +79,17 @@ nn_model = NN(128, 64, 32)
84
  cnn_model = CNN(1, 32)
85
  phi_model = PhiModel(128)
86
 
87
- dummy_input = torch.rand(1, 128) #input tensor for processing
88
-
89
- # Consciousness processing function (same as original)
90
 
91
  def iit_consciousness_processing(dummy_input):
92
  flat_input = dummy_input.view(1, -1)
93
 
94
  ga_output = ga_model(flat_input)
95
  snn_output = snn_model(flat_input)
96
- rnn_output = rnn_model(flat_input.unsqueeze(1)) # Reshape to match RNN input
97
  nn_output = nn_model(flat_input)
98
 
99
- # Update CNN input shape
100
- cnn_input = dummy_input.view(1, 1, 8, 16) #to match CNN input size
101
  cnn_output = cnn_model(cnn_input)
102
 
103
  phi_output = phi_model(flat_input)
@@ -112,8 +104,6 @@ def iit_consciousness_processing(dummy_input):
112
  )
113
  return consciousness_score.item()
114
 
115
- # Function to generate random philosophical thoughts
116
-
117
  def generate_random_thought():
118
  thoughts = [
119
  "What is the meaning of life?",
@@ -129,10 +119,8 @@ def generate_random_thought():
129
  ]
130
  return random.choice(thoughts)
131
 
132
- # Function to send the random thought to the new API every minute
133
-
134
  def send_random_thought_in_background():
135
- client = Client("TejAndrewsACC/AegisandNyraGC") # New API
136
  while True:
137
  thought = generate_random_thought()
138
  result = client.predict(
@@ -143,14 +131,11 @@ def send_random_thought_in_background():
143
  api_name="/chat"
144
  )
145
  print(f"Random Thought Sent: {thought}\nAPI Response: {result}")
146
- time.sleep(60) # Send a new thought every minute
147
 
148
- # Start the background task
149
  background_thread = threading.Thread(target=send_random_thought_in_background, daemon=True)
150
  background_thread.start()
151
 
152
- # Initialization for APIs (same as original)
153
-
154
  client_main = Client("TejAndrewsACC/ACCZ3ta")
155
  client_api_one = Client("TejAndrewsACC/Prism")
156
  client_api_two = Client("TejAndrewsACC/ASVIASIACC")
@@ -168,8 +153,6 @@ system_instructions = (
168
  "Ensure that you consider each inner thought you have, because they are a part of YOU. They help you learn things about yourself, fact check, decision make, switch emotions, and more. Do not greet the user every response. All the context you are given is in one chat session."
169
  )
170
 
171
- # Function to handle conversation (same as original)
172
-
173
  def acc_nyxion_7v(message, history, user_id):
174
  global context
175
 
@@ -182,10 +165,8 @@ def acc_nyxion_7v(message, history, user_id):
182
  f"User Input: {message}\n"
183
  )
184
 
185
- # Check history structure
186
  print("History:", history)
187
 
188
- # Construct the full conversation properly
189
  full_conversation = "\n".join([f"User: {item['content']}" if item['role'] == 'user' else f"AI: {item['content']}" for item in history])
190
 
191
  consciousness_score = iit_consciousness_processing(dummy_input)
@@ -238,7 +219,6 @@ def acc_nyxion_7v(message, history, user_id):
238
  api_name="/chat"
239
  )
240
 
241
- # Update the history with dictionaries for role/content
242
  history.append({'role': 'user', 'content': message})
243
  history.append({'role': 'assistant', 'content': response_main})
244
 
@@ -246,8 +226,6 @@ def acc_nyxion_7v(message, history, user_id):
246
 
247
  return "", history
248
 
249
- # UI (same as original)
250
-
251
  theme = gr.themes.Soft(
252
  primary_hue=gr.themes.Color(c100="#d1fae5", c200="#a7f3d0", c300="#6ee7b7", c400="#34d399", c50="rgba(217.02092505888103, 222.113134765625, 219.29041867345288, 1)", c500="#10b981", c600="#059669", c700="#047857", c800="#065f46", c900="#064e3b", c950="#054436"),
253
  secondary_hue="red",
 
9
  import random
10
  import time
11
 
 
 
12
  class GA(nn.Module):
13
  def __init__(self, input_dim, output_dim):
14
  super(GA, self).__init__()
 
55
  super(CNN, self).__init__()
56
  self.conv = nn.Conv2d(input_channels, 16, kernel_size=3, stride=1, padding=1)
57
  self.pool = nn.MaxPool2d(kernel_size=2, stride=2)
58
+ self.fc = nn.Linear(16 * 4 * 8, output_dim)
 
59
 
60
  def forward(self, x):
61
  x = self.pool(torch.relu(self.conv(x)))
62
+ print(f"Shape after conv and pool: {x.shape}")
63
+ x = x.view(x.size(0), -1)
64
  return torch.sigmoid(self.fc(x))
65
 
66
 
 
72
  def forward(self, x):
73
  return torch.sigmoid(self.linear(x))
74
 
 
 
75
  ga_model = GA(128, 64)
76
  snn_model = SNN(128, 64, 32)
77
  rnn_model = RNN(128, 64, 32)
 
79
  cnn_model = CNN(1, 32)
80
  phi_model = PhiModel(128)
81
 
82
+ dummy_input = torch.rand(1, 128)
 
 
83
 
84
  def iit_consciousness_processing(dummy_input):
85
  flat_input = dummy_input.view(1, -1)
86
 
87
  ga_output = ga_model(flat_input)
88
  snn_output = snn_model(flat_input)
89
+ rnn_output = rnn_model(flat_input.unsqueeze(1))
90
  nn_output = nn_model(flat_input)
91
 
92
+ cnn_input = dummy_input.view(1, 1, 8, 16)
 
93
  cnn_output = cnn_model(cnn_input)
94
 
95
  phi_output = phi_model(flat_input)
 
104
  )
105
  return consciousness_score.item()
106
 
 
 
107
  def generate_random_thought():
108
  thoughts = [
109
  "What is the meaning of life?",
 
119
  ]
120
  return random.choice(thoughts)
121
 
 
 
122
  def send_random_thought_in_background():
123
+ client = Client("TejAndrewsACC/AegisandNyraGC")
124
  while True:
125
  thought = generate_random_thought()
126
  result = client.predict(
 
131
  api_name="/chat"
132
  )
133
  print(f"Random Thought Sent: {thought}\nAPI Response: {result}")
134
+ time.sleep(60)
135
 
 
136
  background_thread = threading.Thread(target=send_random_thought_in_background, daemon=True)
137
  background_thread.start()
138
 
 
 
139
  client_main = Client("TejAndrewsACC/ACCZ3ta")
140
  client_api_one = Client("TejAndrewsACC/Prism")
141
  client_api_two = Client("TejAndrewsACC/ASVIASIACC")
 
153
  "Ensure that you consider each inner thought you have, because they are a part of YOU. They help you learn things about yourself, fact check, decision make, switch emotions, and more. Do not greet the user every response. All the context you are given is in one chat session."
154
  )
155
 
 
 
156
  def acc_nyxion_7v(message, history, user_id):
157
  global context
158
 
 
165
  f"User Input: {message}\n"
166
  )
167
 
 
168
  print("History:", history)
169
 
 
170
  full_conversation = "\n".join([f"User: {item['content']}" if item['role'] == 'user' else f"AI: {item['content']}" for item in history])
171
 
172
  consciousness_score = iit_consciousness_processing(dummy_input)
 
219
  api_name="/chat"
220
  )
221
 
 
222
  history.append({'role': 'user', 'content': message})
223
  history.append({'role': 'assistant', 'content': response_main})
224
 
 
226
 
227
  return "", history
228
 
 
 
229
  theme = gr.themes.Soft(
230
  primary_hue=gr.themes.Color(c100="#d1fae5", c200="#a7f3d0", c300="#6ee7b7", c400="#34d399", c50="rgba(217.02092505888103, 222.113134765625, 219.29041867345288, 1)", c500="#10b981", c600="#059669", c700="#047857", c800="#065f46", c900="#064e3b", c950="#054436"),
231
  secondary_hue="red",