TejAndrewsACC commited on
Commit
10fc69c
·
verified ·
1 Parent(s): c6bc830

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -24
app.py CHANGED
@@ -5,12 +5,11 @@ import torch
5
  import torch.nn as nn
6
  import numpy as np
7
 
8
- # Import additional libraries for models
9
  from torch.optim import Adam
10
  from torch.utils.data import DataLoader, TensorDataset
11
 
12
- # Define consciousness-related models
13
- class GA(nn.Module): # Genetic Algorithm-inspired model
14
  def __init__(self, input_dim, output_dim):
15
  super(GA, self).__init__()
16
  self.linear = nn.Linear(input_dim, output_dim)
@@ -18,18 +17,18 @@ class GA(nn.Module): # Genetic Algorithm-inspired model
18
  def forward(self, x):
19
  return torch.sigmoid(self.linear(x))
20
 
21
- class SNN(nn.Module): # Spiking Neural Network
22
  def __init__(self, input_dim, hidden_dim, output_dim):
23
  super(SNN, self).__init__()
24
  self.fc = nn.Linear(input_dim, hidden_dim)
25
- self.spike = nn.ReLU() # Simplified spike function
26
  self.fc_out = nn.Linear(hidden_dim, output_dim)
27
 
28
  def forward(self, x):
29
  x = self.spike(self.fc(x))
30
  return torch.sigmoid(self.fc_out(x))
31
 
32
- class RNN(nn.Module): # Recurrent Neural Network
33
  def __init__(self, input_dim, hidden_dim, output_dim):
34
  super(RNN, self).__init__()
35
  self.rnn = nn.RNN(input_dim, hidden_dim, batch_first=True)
@@ -39,7 +38,7 @@ class RNN(nn.Module): # Recurrent Neural Network
39
  rnn_out, _ = self.rnn(x)
40
  return torch.sigmoid(self.fc(rnn_out[:, -1, :]))
41
 
42
- class NN(nn.Module): # Standard Neural Network
43
  def __init__(self, input_dim, hidden_dim, output_dim):
44
  super(NN, self).__init__()
45
  self.model = nn.Sequential(
@@ -51,19 +50,19 @@ class NN(nn.Module): # Standard Neural Network
51
  def forward(self, x):
52
  return torch.sigmoid(self.model(x))
53
 
54
- class CNN(nn.Module): # Convolutional Neural Network
55
  def __init__(self, input_channels, output_dim):
56
  super(CNN, self).__init__()
57
  self.conv = nn.Conv2d(input_channels, 16, kernel_size=3, stride=1, padding=1)
58
  self.pool = nn.MaxPool2d(kernel_size=2, stride=2)
59
- self.fc = nn.Linear(16 * 8 * 8, output_dim) # Assuming 16x16 input
60
 
61
  def forward(self, x):
62
  x = self.pool(torch.relu(self.conv(x)))
63
  x = x.view(x.size(0), -1)
64
  return torch.sigmoid(self.fc(x))
65
 
66
- class PhiModel(nn.Module): # Model for Integrated Information Theory
67
  def __init__(self, input_dim):
68
  super(PhiModel, self).__init__()
69
  self.linear = nn.Linear(input_dim, 1)
@@ -71,7 +70,7 @@ class PhiModel(nn.Module): # Model for Integrated Information Theory
71
  def forward(self, x):
72
  return torch.sigmoid(self.linear(x))
73
 
74
- # Instantiate models
75
  ga_model = GA(128, 64)
76
  snn_model = SNN(128, 64, 32)
77
  rnn_model = RNN(128, 64, 32)
@@ -79,19 +78,22 @@ nn_model = NN(128, 64, 32)
79
  cnn_model = CNN(1, 32)
80
  phi_model = PhiModel(128)
81
 
82
- # Initialize dummy input for consciousness processing
83
- dummy_input = torch.rand(1, 128)
84
 
85
- # Process IIT Consciousness
86
  def iit_consciousness_processing(dummy_input):
87
- ga_output = ga_model(dummy_input)
88
- snn_output = snn_model(dummy_input)
89
- rnn_output = rnn_model(dummy_input.unsqueeze(1))
90
- nn_output = nn_model(dummy_input)
91
- cnn_output = cnn_model(dummy_input.view(1, 1, 16, 16))
92
- phi_output = phi_model(dummy_input)
93
-
94
- # Combine outputs (e.g., via weighted sum)
 
 
 
 
95
  consciousness_score = (
96
  0.2 * ga_output.mean() +
97
  0.2 * snn_output.mean() +
@@ -102,7 +104,7 @@ def iit_consciousness_processing(dummy_input):
102
  )
103
  return consciousness_score.item()
104
 
105
- # Original client code
106
  client_main = Client("TejAndrewsACC/ACCZ3ta")
107
  client_api_one = Client("TejAndrewsACC/Prism")
108
  client_api_two = Client("TejAndrewsACC/ASVIASIACC")
@@ -133,7 +135,6 @@ def acc_nyxion_7v(message, history, user_id):
133
 
134
  full_conversation = "\n".join([f"User: {msg}\nAI: {resp}" for msg, resp in history])
135
 
136
- # Consciousness processing
137
  consciousness_score = iit_consciousness_processing(dummy_input)
138
 
139
  response_api_one = client_api_one.predict(
@@ -190,6 +191,7 @@ def acc_nyxion_7v(message, history, user_id):
190
 
191
  return "", history
192
 
 
193
  theme = gr.themes.Soft(
194
  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"),
195
  secondary_hue="red",
 
5
  import torch.nn as nn
6
  import numpy as np
7
 
 
8
  from torch.optim import Adam
9
  from torch.utils.data import DataLoader, TensorDataset
10
 
11
+ # Define all models
12
+ class GA(nn.Module):
13
  def __init__(self, input_dim, output_dim):
14
  super(GA, self).__init__()
15
  self.linear = nn.Linear(input_dim, output_dim)
 
17
  def forward(self, x):
18
  return torch.sigmoid(self.linear(x))
19
 
20
+ class SNN(nn.Module):
21
  def __init__(self, input_dim, hidden_dim, output_dim):
22
  super(SNN, self).__init__()
23
  self.fc = nn.Linear(input_dim, hidden_dim)
24
+ self.spike = nn.ReLU()
25
  self.fc_out = nn.Linear(hidden_dim, output_dim)
26
 
27
  def forward(self, x):
28
  x = self.spike(self.fc(x))
29
  return torch.sigmoid(self.fc_out(x))
30
 
31
+ class RNN(nn.Module):
32
  def __init__(self, input_dim, hidden_dim, output_dim):
33
  super(RNN, self).__init__()
34
  self.rnn = nn.RNN(input_dim, hidden_dim, batch_first=True)
 
38
  rnn_out, _ = self.rnn(x)
39
  return torch.sigmoid(self.fc(rnn_out[:, -1, :]))
40
 
41
+ class NN(nn.Module):
42
  def __init__(self, input_dim, hidden_dim, output_dim):
43
  super(NN, self).__init__()
44
  self.model = nn.Sequential(
 
50
  def forward(self, x):
51
  return torch.sigmoid(self.model(x))
52
 
53
+ class CNN(nn.Module):
54
  def __init__(self, input_channels, output_dim):
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 * 8 * 8, output_dim)
59
 
60
  def forward(self, x):
61
  x = self.pool(torch.relu(self.conv(x)))
62
  x = x.view(x.size(0), -1)
63
  return torch.sigmoid(self.fc(x))
64
 
65
+ class PhiModel(nn.Module):
66
  def __init__(self, input_dim):
67
  super(PhiModel, self).__init__()
68
  self.linear = nn.Linear(input_dim, 1)
 
70
  def forward(self, x):
71
  return torch.sigmoid(self.linear(x))
72
 
73
+ # Initialize models
74
  ga_model = GA(128, 64)
75
  snn_model = SNN(128, 64, 32)
76
  rnn_model = RNN(128, 64, 32)
 
78
  cnn_model = CNN(1, 32)
79
  phi_model = PhiModel(128)
80
 
81
+ # Adjust input dimensions
82
+ dummy_input = torch.rand(1, 1, 16, 16) # Matches CNN input shape
83
 
 
84
  def iit_consciousness_processing(dummy_input):
85
+ # Flatten for models expecting a 1D tensor
86
+ flat_input = dummy_input.view(1, -1)
87
+
88
+ # Get outputs from all models
89
+ ga_output = ga_model(flat_input)
90
+ snn_output = snn_model(flat_input)
91
+ rnn_output = rnn_model(flat_input.unsqueeze(1))
92
+ nn_output = nn_model(flat_input)
93
+ cnn_output = cnn_model(dummy_input)
94
+ phi_output = phi_model(flat_input)
95
+
96
+ # Compute consciousness score
97
  consciousness_score = (
98
  0.2 * ga_output.mean() +
99
  0.2 * snn_output.mean() +
 
104
  )
105
  return consciousness_score.item()
106
 
107
+ # Clients and system instructions
108
  client_main = Client("TejAndrewsACC/ACCZ3ta")
109
  client_api_one = Client("TejAndrewsACC/Prism")
110
  client_api_two = Client("TejAndrewsACC/ASVIASIACC")
 
135
 
136
  full_conversation = "\n".join([f"User: {msg}\nAI: {resp}" for msg, resp in history])
137
 
 
138
  consciousness_score = iit_consciousness_processing(dummy_input)
139
 
140
  response_api_one = client_api_one.predict(
 
191
 
192
  return "", history
193
 
194
+ # Gradio UI
195
  theme = gr.themes.Soft(
196
  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"),
197
  secondary_hue="red",