ajitsi commited on
Commit
604e2e1
·
1 Parent(s): 15c8665

adding model changes

Browse files
Files changed (2) hide show
  1. app.py +28 -4
  2. pytorch_model.bin +3 -0
app.py CHANGED
@@ -1,7 +1,31 @@
 
1
  import gradio as gr
 
 
2
 
3
- def greet(name):
4
- return "Hello " + name + "!!"
 
 
5
 
6
- demo = gr.Interface(fn=greet, inputs="text", outputs="text")
7
- demo.launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import torch
2
  import gradio as gr
3
+ from torchvision import transforms
4
+ from tinyvgg import TinyVGG # Replace with your actual model import
5
 
6
+ # Load the model
7
+ model = TinyVGG(input_shape=3, hidden_units=64, output_shape=10)
8
+ model.load_state_dict(torch.load("pytorch_model.bin", map_location=torch.device("cpu")))
9
+ model.eval()
10
 
11
+ # Define a preprocessing pipeline
12
+ preprocess = transforms.Compose([
13
+ transforms.Resize((64, 64)),
14
+ transforms.ToTensor()
15
+ ])
16
+
17
+ # Inference function
18
+ def predict(image):
19
+ image = preprocess(image).unsqueeze(0) # Add batch dimension
20
+ with torch.no_grad():
21
+ outputs = model(image)
22
+ return outputs.argmax(dim=1).item()
23
+
24
+ # Gradio Interface
25
+ iface = gr.Interface(
26
+ fn=predict,
27
+ inputs=gr.Image(shape=(64, 64)),
28
+ outputs="label"
29
+ )
30
+
31
+ iface.launch()
pytorch_model.bin ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:ba177342f60f6f6936a7226712297ee23063158f152bf7377b0d7c6c47351b72
3
+ size 37090