Spaces:
Runtime error
Runtime error
Commit ·
f68b432
1
Parent(s): 0f42065
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,6 +1,31 @@
|
|
| 1 |
import requests
|
| 2 |
-
|
| 3 |
import gradio as gr
|
| 4 |
-
import
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
|
| 6 |
-
|
|
|
|
|
|
| 1 |
import requests
|
|
|
|
| 2 |
import gradio as gr
|
| 3 |
+
from fastai.vision.all import *
|
| 4 |
+
import pickle
|
| 5 |
+
|
| 6 |
+
# Load the trained model
|
| 7 |
+
with open("model.pkl", "rb") as f:
|
| 8 |
+
learn = pickle.load(f)
|
| 9 |
+
|
| 10 |
+
# Define the predict function
|
| 11 |
+
def predict(image):
|
| 12 |
+
# Load the input image
|
| 13 |
+
img = PILImage.create(image)
|
| 14 |
+
|
| 15 |
+
# Perform inference
|
| 16 |
+
predicted_class, _, _ = learn.predict(img)
|
| 17 |
+
|
| 18 |
+
return predicted_class
|
| 19 |
+
|
| 20 |
+
# Create Gradio interface
|
| 21 |
+
iface = gr.Interface(
|
| 22 |
+
fn=predict,
|
| 23 |
+
inputs=gr.Image(upload_button=True, label="Upload a picture of a dog"),
|
| 24 |
+
outputs="text",
|
| 25 |
+
live=True,
|
| 26 |
+
title="Dog Breed Classifier",
|
| 27 |
+
description="Upload a picture of a dog, and the model will classify it as Labrador, Husky, or Bulldog.",
|
| 28 |
+
)
|
| 29 |
|
| 30 |
+
# Launch the Gradio interface
|
| 31 |
+
iface.launch()
|