Spaces:
Sleeping
Sleeping
gpbhupinder
commited on
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
### app.py
|
2 |
+
import gradio as gr
|
3 |
+
import torch
|
4 |
+
from loaded_model import CNNModel
|
5 |
+
import loaded_model
|
6 |
+
|
7 |
+
model = CNNModel()
|
8 |
+
model.load_state_dict(torch.load(f="https://huggingface.co/spaces/gpbhupinder/test/blob/main/model_-%2023%20june%202024%2019_22.pt"))
|
9 |
+
|
10 |
+
|
11 |
+
# Define a function to make predictions with your model
|
12 |
+
def classify_image(image):
|
13 |
+
# Preprocess the image
|
14 |
+
preprocess = loaded_model.create_transformer()
|
15 |
+
|
16 |
+
image_tensor = preprocess(image)
|
17 |
+
image_tensor = image_tensor.unsqueeze(0)
|
18 |
+
|
19 |
+
# Make prediction
|
20 |
+
with torch.no_grad():
|
21 |
+
output = model(image_tensor)
|
22 |
+
_, predicted_class = torch.max(output, 1)
|
23 |
+
|
24 |
+
return f"Predicted class: {predicted_class.item()}"
|
25 |
+
|
26 |
+
|
27 |
+
gr.Interface(fn=classify_image, inputs="sketchpad", outputs="label").launch()
|