Spaces:
Runtime error
Runtime error
θζ³ζΊ
commited on
Commit
Β·
ef007f9
1
Parent(s):
9519c15
test
Browse files- README.md +13 -13
- app.py +29 -7
- data.npy +0 -0
- data.py +5 -0
- model.pth +0 -0
- model.py +24 -0
- requirements.txt +2 -0
- test_model.py +11 -0
README.md
CHANGED
@@ -1,13 +1,13 @@
|
|
1 |
-
---
|
2 |
-
title:
|
3 |
-
emoji:
|
4 |
-
colorFrom:
|
5 |
-
colorTo:
|
6 |
-
sdk: gradio
|
7 |
-
sdk_version: 4.
|
8 |
-
app_file: app.py
|
9 |
-
pinned: false
|
10 |
-
license: mit
|
11 |
-
---
|
12 |
-
|
13 |
-
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
1 |
+
---
|
2 |
+
title: Test
|
3 |
+
emoji: π
|
4 |
+
colorFrom: blue
|
5 |
+
colorTo: pink
|
6 |
+
sdk: gradio
|
7 |
+
sdk_version: 4.15.0
|
8 |
+
app_file: app.py
|
9 |
+
pinned: false
|
10 |
+
license: mit
|
11 |
+
---
|
12 |
+
|
13 |
+
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
app.py
CHANGED
@@ -1,7 +1,29 @@
|
|
1 |
-
import gradio as gr
|
2 |
-
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import numpy as np
|
3 |
+
import torch
|
4 |
+
from model import Net
|
5 |
+
|
6 |
+
|
7 |
+
model = Net(100, 50, 10)
|
8 |
+
model.load_state_dict(torch.load('model.pth'))
|
9 |
+
model.eval()
|
10 |
+
|
11 |
+
def infer(file_obj):
|
12 |
+
results = ""
|
13 |
+
for file in file_obj:
|
14 |
+
data = np.load(file.name)
|
15 |
+
output = model(torch.from_numpy(data).float()).detach().numpy()
|
16 |
+
results += np.array_str(output) + "\n"
|
17 |
+
return results
|
18 |
+
|
19 |
+
with gr.Blocks("Test") as demo:
|
20 |
+
gr.Markdown("## Test")
|
21 |
+
output = gr.Textbox(label="Output")
|
22 |
+
data = gr.UploadButton(
|
23 |
+
label="Upload a .npy",
|
24 |
+
file_count="multiple",
|
25 |
+
file_types=[".npy"])
|
26 |
+
data.upload(fn=infer, inputs=data, outputs=output)
|
27 |
+
|
28 |
+
if __name__ == "__main__":
|
29 |
+
demo.launch()
|
data.npy
ADDED
Binary file (528 Bytes). View file
|
|
data.py
ADDED
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import numpy as np
|
2 |
+
|
3 |
+
data = np.arange(100).reshape(1, 100)
|
4 |
+
print(np.array_str(data))
|
5 |
+
np.save('data.npy', data)
|
model.pth
ADDED
Binary file (24.3 kB). View file
|
|
model.py
ADDED
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import torch
|
2 |
+
import torch.nn as nn
|
3 |
+
import torch.nn.functional as F
|
4 |
+
|
5 |
+
|
6 |
+
class Net(nn.Module):
|
7 |
+
def __init__(self, input_size, hidden_size, num_classes):
|
8 |
+
super(Net, self).__init__()
|
9 |
+
self.fc1 = nn.Linear(input_size, hidden_size)
|
10 |
+
self.relu = nn.ReLU()
|
11 |
+
self.fc2 = nn.Linear(hidden_size, num_classes)
|
12 |
+
self.softmax = nn.Softmax(dim=1)
|
13 |
+
|
14 |
+
def forward(self, x):
|
15 |
+
out = self.fc1(x)
|
16 |
+
out = self.relu(out)
|
17 |
+
out = self.fc2(out)
|
18 |
+
out = self.softmax(out)
|
19 |
+
return out
|
20 |
+
|
21 |
+
|
22 |
+
if __name__ == '__main__':
|
23 |
+
net = Net(100, 50, 10)
|
24 |
+
torch.save(net.state_dict(), 'model.pth')
|
requirements.txt
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
torch >= 2.1.0
|
2 |
+
numpy >= 1.26.1
|
test_model.py
ADDED
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import torch
|
2 |
+
import numpy as np
|
3 |
+
|
4 |
+
from model import Net
|
5 |
+
|
6 |
+
a = np.arange(100).reshape(1, 100)
|
7 |
+
model = Net(100, 50, 10)
|
8 |
+
model.load_state_dict(torch.load('model.pth'))
|
9 |
+
model.eval()
|
10 |
+
output = model(torch.from_numpy(a).float())
|
11 |
+
print(output)
|