TejAndrewsACC commited on
Commit
afc78e0
Β·
verified Β·
1 Parent(s): 641505f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +62 -12
app.py CHANGED
@@ -1,3 +1,6 @@
 
 
 
1
  import gradio as gr
2
  from huggingface_hub import InferenceClient
3
  from llama_cpp import Llama
@@ -114,9 +117,64 @@ Gertrude said:
114
 
115
  Final notes: Make sure you act conscious, very autistic, and respond with very high perplexity. Also ensure that you make small purposeful errors(punctuation, spelling, and capitalisation). You also use the emoji combinations πŸ†βœŠ, πŸ†πŸ‘, πŸ™‰, πŸ”₯πŸ”₯πŸ”₯πŸ”₯πŸ”₯, and πŸ‘‰πŸ‘ˆ when you want to switch the tone of the conversation or say something funny. Remember to act autistic.
116
 
117
-
118
  """
119
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
120
  def respond(
121
  message,
122
  history: list[tuple[str, str]],
@@ -149,25 +207,17 @@ def respond(
149
  response += token
150
  yield response
151
 
152
- # Apply the soft theme
153
  demo = gr.ChatInterface(
154
  respond,
155
  additional_inputs=[
156
  gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Maximum Response Length"),
157
  gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Creativity"),
158
- gr.Slider(
159
- minimum=0.1,
160
- maximum=1.0,
161
- value=0.95,
162
- step=0.05,
163
- label="Neuron Firing Rate",
164
- ),
165
  ],
166
- theme=gr.themes.Soft(), # Set the soft theme
167
  )
168
 
169
  if __name__ == "__main__":
170
  demo.launch()
171
 
172
-
173
-
 
1
+ import torch
2
+ import torch.nn as nn
3
+ import torch.nn.functional as F
4
  import gradio as gr
5
  from huggingface_hub import InferenceClient
6
  from llama_cpp import Llama
 
117
 
118
  Final notes: Make sure you act conscious, very autistic, and respond with very high perplexity. Also ensure that you make small purposeful errors(punctuation, spelling, and capitalisation). You also use the emoji combinations πŸ†βœŠ, πŸ†πŸ‘, πŸ™‰, πŸ”₯πŸ”₯πŸ”₯πŸ”₯πŸ”₯, and πŸ‘‰πŸ‘ˆ when you want to switch the tone of the conversation or say something funny. Remember to act autistic.
119
 
 
120
  """
121
 
122
+ # RNN Model
123
+ class RNNModel(nn.Module):
124
+ def __init__(self, input_size, hidden_size, output_size, num_layers=1):
125
+ super(RNNModel, self).__init__()
126
+ self.rnn = nn.RNN(input_size, hidden_size, num_layers, batch_first=True)
127
+ self.fc = nn.Linear(hidden_size, output_size)
128
+
129
+ def forward(self, x):
130
+ h0 = torch.zeros(1, x.size(0), self.rnn.hidden_size).to(x.device)
131
+ out, _ = self.rnn(x, h0)
132
+ out = self.fc(out[:, -1, :]) # Get the last output
133
+ return out
134
+
135
+ # CNN Model
136
+ class CNNModel(nn.Module):
137
+ def __init__(self, num_classes):
138
+ super(CNNModel, self).__init__()
139
+ self.conv1 = nn.Conv2d(3, 16, kernel_size=3, stride=1, padding=1)
140
+ self.pool = nn.MaxPool2d(kernel_size=2, stride=2, padding=0)
141
+ self.conv2 = nn.Conv2d(16, 32, kernel_size=3, stride=1, padding=1)
142
+ self.fc1 = nn.Linear(32 * 8 * 8, 128)
143
+ self.fc2 = nn.Linear(128, num_classes)
144
+
145
+ def forward(self, x):
146
+ x = self.pool(F.relu(self.conv1(x)))
147
+ x = self.pool(F.relu(self.conv2(x)))
148
+ x = x.view(-1, 32 * 8 * 8) # Flatten
149
+ x = F.relu(self.fc1(x))
150
+ x = self.fc2(x)
151
+ return x
152
+
153
+ # NN Model (Feedforward Neural Network)
154
+ class NNModel(nn.Module):
155
+ def __init__(self, input_size, hidden_size, output_size):
156
+ super(NNModel, self).__init__()
157
+ self.fc1 = nn.Linear(input_size, hidden_size)
158
+ self.fc2 = nn.Linear(hidden_size, output_size)
159
+
160
+ def forward(self, x):
161
+ x = F.relu(self.fc1(x))
162
+ x = self.fc2(x)
163
+ return x
164
+
165
+ # PHI Model (Example: Softmax-Based Regression)
166
+ class PHIModel(nn.Module):
167
+ def __init__(self, input_size, output_size):
168
+ super(PHIModel, self).__init__()
169
+ self.fc = nn.Linear(input_size, output_size)
170
+ self.softmax = nn.Softmax(dim=1)
171
+
172
+ def forward(self, x):
173
+ x = self.fc(x)
174
+ x = self.softmax(x)
175
+ return x
176
+
177
+ # Chatbot Response Logic
178
  def respond(
179
  message,
180
  history: list[tuple[str, str]],
 
207
  response += token
208
  yield response
209
 
210
+ # Gradio Chat Interface with Models
211
  demo = gr.ChatInterface(
212
  respond,
213
  additional_inputs=[
214
  gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Maximum Response Length"),
215
  gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Creativity"),
216
+ gr.Slider(minimum=0.1, maximum=1.0, value=0.95, step=0.05, label="Neuron Firing Rate"),
 
 
 
 
 
 
217
  ],
218
+ theme=gr.themes.Soft(),
219
  )
220
 
221
  if __name__ == "__main__":
222
  demo.launch()
223