Spaces:
Build error
Build error
Upload 3 files
Browse files- app.py +32 -0
- model_scripted.pt +3 -0
- requirements.txt +0 -0
app.py
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import torch
|
| 3 |
+
from PIL import Image
|
| 4 |
+
|
| 5 |
+
# Load the trained model
|
| 6 |
+
model_path = model_scripted.pt
|
| 7 |
+
net = torch.jit.load(model_path)
|
| 8 |
+
net.eval()
|
| 9 |
+
|
| 10 |
+
# Define a prediction function
|
| 11 |
+
def classify_image(image)
|
| 12 |
+
transform = transforms.Compose([
|
| 13 |
+
transforms.Resize((128, 128)),
|
| 14 |
+
transforms.ToTensor(),
|
| 15 |
+
transforms.Normalize((0.5,), (0.5,))
|
| 16 |
+
])
|
| 17 |
+
image = transform(image).unsqueeze(0) # Add batch dimension
|
| 18 |
+
with torch.no_grad()
|
| 19 |
+
output = net(image)
|
| 20 |
+
_, predicted = torch.max(output, 1)
|
| 21 |
+
return target_classes[predicted.item()]
|
| 22 |
+
|
| 23 |
+
# Create the Gradio interface
|
| 24 |
+
interface = gr.Interface(
|
| 25 |
+
fn=classify_image,
|
| 26 |
+
inputs=gr.Image(type=pil),
|
| 27 |
+
outputs=text,
|
| 28 |
+
title=Mechanical Tools Classifier
|
| 29 |
+
)
|
| 30 |
+
|
| 31 |
+
# Launch the app
|
| 32 |
+
interface.launch()
|
model_scripted.pt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:856f4e6ff54992e11599e0df1d9b3926a0e536de0f5e3d052e92b41c8945787d
|
| 3 |
+
size 67854
|
requirements.txt
ADDED
|
File without changes
|