Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,7 +1,108 @@
|
|
1 |
import gradio as gr
|
2 |
from gradio_client import Client
|
3 |
import spaces
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
4 |
|
|
|
5 |
client_main = Client("TejAndrewsACC/ACCZ3ta")
|
6 |
client_api_one = Client("TejAndrewsACC/Prism")
|
7 |
client_api_two = Client("TejAndrewsACC/ASVIASIACC")
|
@@ -32,6 +133,9 @@ def acc_nyxion_7v(message, history, user_id):
|
|
32 |
|
33 |
full_conversation = "\n".join([f"User: {msg}\nAI: {resp}" for msg, resp in history])
|
34 |
|
|
|
|
|
|
|
35 |
response_api_one = client_api_one.predict(
|
36 |
message=f"{full_conversation}\nUser: {message}",
|
37 |
param_2=512,
|
@@ -69,7 +173,8 @@ def acc_nyxion_7v(message, history, user_id):
|
|
69 |
f"Inner Thought 1 (Reasoning): {response_api_one}\n"
|
70 |
f"Inner Thought 2 (Fight or Flight): {response_api_two}\n"
|
71 |
f"Inner Thought 3 (Assistant): {response_api_three}\n"
|
72 |
-
f"Inner Thought 4 (Personality): {response_api_four}"
|
|
|
73 |
)
|
74 |
|
75 |
combined_input = f"{modified_input}\nInner Thoughts:\n{inner_thoughts}"
|
@@ -98,4 +203,4 @@ with gr.Blocks(theme=theme) as demo:
|
|
98 |
|
99 |
msg.submit(acc_nyxion_7v, [msg, chatbot, user_id], [msg, chatbot])
|
100 |
|
101 |
-
demo.launch()
|
|
|
1 |
import gradio as gr
|
2 |
from gradio_client import Client
|
3 |
import spaces
|
4 |
+
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)
|
17 |
+
|
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)
|
36 |
+
self.fc = nn.Linear(hidden_dim, output_dim)
|
37 |
+
|
38 |
+
def forward(self, x):
|
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(
|
46 |
+
nn.Linear(input_dim, hidden_dim),
|
47 |
+
nn.ReLU(),
|
48 |
+
nn.Linear(hidden_dim, output_dim)
|
49 |
+
)
|
50 |
+
|
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)
|
70 |
+
|
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)
|
78 |
+
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() +
|
98 |
+
0.2 * rnn_output.mean() +
|
99 |
+
0.2 * nn_output.mean() +
|
100 |
+
0.1 * cnn_output.mean() +
|
101 |
+
0.1 * phi_output.mean()
|
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 |
|
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(
|
140 |
message=f"{full_conversation}\nUser: {message}",
|
141 |
param_2=512,
|
|
|
173 |
f"Inner Thought 1 (Reasoning): {response_api_one}\n"
|
174 |
f"Inner Thought 2 (Fight or Flight): {response_api_two}\n"
|
175 |
f"Inner Thought 3 (Assistant): {response_api_three}\n"
|
176 |
+
f"Inner Thought 4 (Personality): {response_api_four}\n"
|
177 |
+
f"Consciousness Score: {consciousness_score:.2f}"
|
178 |
)
|
179 |
|
180 |
combined_input = f"{modified_input}\nInner Thoughts:\n{inner_thoughts}"
|
|
|
203 |
|
204 |
msg.submit(acc_nyxion_7v, [msg, chatbot, user_id], [msg, chatbot])
|
205 |
|
206 |
+
demo.launch()
|