Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
@@ -1,25 +1,89 @@
|
|
1 |
-
from transformers import AutoModelForCausalLM, AutoTokenizer
|
2 |
import gradio as gr
|
|
|
|
|
|
|
3 |
import os
|
4 |
|
5 |
-
#
|
6 |
model_name = "nvidia/Hymba-1.5B-Instruct"
|
7 |
hf_token = os.getenv("DOWNLOAD")
|
8 |
-
|
9 |
-
# Load model and tokenizer
|
10 |
tokenizer = AutoTokenizer.from_pretrained(model_name, use_auth_token=hf_token)
|
11 |
model = AutoModelForCausalLM.from_pretrained(model_name, use_auth_token=hf_token)
|
12 |
|
13 |
-
|
14 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
15 |
|
16 |
-
|
17 |
-
|
18 |
-
prompt = f"{system_message}\n\nUser: {user_input}\nAssistant:"
|
19 |
inputs = tokenizer(prompt, return_tensors="pt")
|
20 |
outputs = model.generate(**inputs, max_new_tokens=150)
|
21 |
return tokenizer.decode(outputs[0], skip_special_tokens=True)
|
22 |
|
23 |
-
|
24 |
-
|
25 |
-
|
|
|
|
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
3 |
+
import torch
|
4 |
+
import torch.nn as nn
|
5 |
import os
|
6 |
|
7 |
+
# Model setup
|
8 |
model_name = "nvidia/Hymba-1.5B-Instruct"
|
9 |
hf_token = os.getenv("DOWNLOAD")
|
|
|
|
|
10 |
tokenizer = AutoTokenizer.from_pretrained(model_name, use_auth_token=hf_token)
|
11 |
model = AutoModelForCausalLM.from_pretrained(model_name, use_auth_token=hf_token)
|
12 |
|
13 |
+
class LargeNeuralNetwork(nn.Module):
|
14 |
+
def __init__(self):
|
15 |
+
super(LargeNeuralNetwork, self).__init__()
|
16 |
+
self.layer1 = nn.Linear(512, 2048)
|
17 |
+
self.layer2 = nn.Linear(2048, 4096)
|
18 |
+
self.layer3 = nn.Linear(4096, 8192)
|
19 |
+
self.layer4 = nn.Linear(8192, 16384)
|
20 |
+
self.layer5 = nn.Linear(16384, 32768)
|
21 |
+
self.relu = nn.ReLU()
|
22 |
+
self.output = nn.Linear(32768, 1)
|
23 |
+
|
24 |
+
def forward(self, x):
|
25 |
+
x = self.relu(self.layer1(x))
|
26 |
+
x = self.relu(self.layer2(x))
|
27 |
+
x = self.relu(self.layer3(x))
|
28 |
+
x = self.relu(self.layer4(x))
|
29 |
+
x = self.relu(self.layer5(x))
|
30 |
+
return self.output(x)
|
31 |
+
|
32 |
+
class LargeRecurrentNN(nn.Module):
|
33 |
+
def __init__(self):
|
34 |
+
super(LargeRecurrentNN, self).__init__()
|
35 |
+
self.rnn = nn.RNN(input_size=512, hidden_size=2048, num_layers=3, batch_first=True)
|
36 |
+
self.fc = nn.Linear(2048, 1)
|
37 |
+
|
38 |
+
def forward(self, x):
|
39 |
+
h0 = torch.zeros(3, x.size(0), 2048).to(x.device)
|
40 |
+
out, _ = self.rnn(x, h0)
|
41 |
+
out = self.fc(out[:, -1, :])
|
42 |
+
return out
|
43 |
+
|
44 |
+
class LargeConvolutionalNN(nn.Module):
|
45 |
+
def __init__(self):
|
46 |
+
super(LargeConvolutionalNN, self).__init__()
|
47 |
+
self.conv1 = nn.Conv2d(1, 32, kernel_size=3, stride=1, padding=1)
|
48 |
+
self.conv2 = nn.Conv2d(32, 64, kernel_size=3, stride=1, padding=1)
|
49 |
+
self.conv3 = nn.Conv2d(64, 128, kernel_size=3, stride=1, padding=1)
|
50 |
+
self.fc1 = nn.Linear(128*32*32, 1024)
|
51 |
+
self.fc2 = nn.Linear(1024, 1)
|
52 |
+
self.relu = nn.ReLU()
|
53 |
+
|
54 |
+
def forward(self, x):
|
55 |
+
x = self.relu(self.conv1(x))
|
56 |
+
x = self.relu(self.conv2(x))
|
57 |
+
x = self.relu(self.conv3(x))
|
58 |
+
x = x.view(x.size(0), -1)
|
59 |
+
x = self.relu(self.fc1(x))
|
60 |
+
return self.fc2(x)
|
61 |
+
|
62 |
+
class PhiModel(nn.Module):
|
63 |
+
def __init__(self):
|
64 |
+
super(PhiModel, self).__init__()
|
65 |
+
self.fc = nn.Linear(512, 1024)
|
66 |
+
|
67 |
+
def forward(self, x):
|
68 |
+
return self.fc(x)
|
69 |
+
|
70 |
+
class GeneticAlgorithm(nn.Module):
|
71 |
+
def __init__(self):
|
72 |
+
super(GeneticAlgorithm, self).__init__()
|
73 |
+
self.fc = nn.Linear(512, 1024)
|
74 |
+
|
75 |
+
def forward(self, x):
|
76 |
+
return self.fc(x)
|
77 |
|
78 |
+
def chat(message, history):
|
79 |
+
prompt = f"User: {message}\nAssistant:"
|
|
|
80 |
inputs = tokenizer(prompt, return_tensors="pt")
|
81 |
outputs = model.generate(**inputs, max_new_tokens=150)
|
82 |
return tokenizer.decode(outputs[0], skip_special_tokens=True)
|
83 |
|
84 |
+
gr.ChatInterface(
|
85 |
+
fn=chat,
|
86 |
+
type="messages",
|
87 |
+
title="Chatbot",
|
88 |
+
description="Interact with the AI assistant."
|
89 |
+
).launch()
|