Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,29 +1,30 @@
|
|
| 1 |
-
|
|
|
|
| 2 |
|
| 3 |
-
|
| 4 |
-
|
|
|
|
|
|
|
|
|
|
| 5 |
|
| 6 |
-
# %% ../drive/MyDrive/Colab Notebooks/cats_vs_dogs.ipynb 10
|
| 7 |
-
from fastai.vision.all import *
|
| 8 |
import gradio as gr
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
intf.launch(inline=False)
|
|
|
|
| 1 |
+
import torch
|
| 2 |
+
import torchvision
|
| 3 |
|
| 4 |
+
model = torchvision.models.resnet50(pretrained=False)
|
| 5 |
+
model.fc = nn.Linear(model.fc.in_features, num_classes)
|
| 6 |
+
model.load_state_dict(torch.load("model.pth"))
|
| 7 |
+
model.to(device)
|
| 8 |
+
model.eval()
|
| 9 |
|
|
|
|
|
|
|
| 10 |
import gradio as gr
|
| 11 |
+
from PIL import Image
|
| 12 |
+
|
| 13 |
+
# Define the function to make predictions
|
| 14 |
+
def predict(image):
|
| 15 |
+
image = transform(image).unsqueeze(0).to(device)
|
| 16 |
+
model.eval()
|
| 17 |
+
with torch.no_grad():
|
| 18 |
+
output = model(image)
|
| 19 |
+
_, predicted = torch.max(output.data, 1)
|
| 20 |
+
return dataset.classes[predicted.item()]
|
| 21 |
+
|
| 22 |
+
# Define the input and output components
|
| 23 |
+
image_input = gr.inputs.Image(type="pil", label="Upload Image")
|
| 24 |
+
label_output = gr.outputs.Label()
|
| 25 |
+
|
| 26 |
+
# Create the interface
|
| 27 |
+
interface = gr.Interface(fn=predict, inputs=image_input, outputs=label_output)
|
| 28 |
+
|
| 29 |
+
# Launch the interface
|
| 30 |
+
interface.launch()
|
|
|