Spaces:
Sleeping
Sleeping
Create app.py
Browse filesadd app.py python script with model loading + Gradio interface from my Kaggle for fastAI Lesson 2
app.py
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from fastai.vision.all import *
|
| 2 |
+
import gradio as gr
|
| 3 |
+
|
| 4 |
+
# Load the model you trained and exported from Kaggle
|
| 5 |
+
learn = load_learner("model.pkl")
|
| 6 |
+
|
| 7 |
+
# Define a prediction function for Gradio
|
| 8 |
+
def classify_image(img):
|
| 9 |
+
pred, idx, probs = learn.predict(img)
|
| 10 |
+
return {learn.dls.vocab[i]: float(probs[i]) for i in range(len(probs))}
|
| 11 |
+
|
| 12 |
+
# Create a Gradio interface
|
| 13 |
+
interface = gr.Interface(
|
| 14 |
+
fn=classify_image,
|
| 15 |
+
inputs=gr.Image(type="pil"),
|
| 16 |
+
outputs=gr.Label()
|
| 17 |
+
)
|
| 18 |
+
|
| 19 |
+
# Launch the interface when the app runs
|
| 20 |
+
if __name__ == "__main__":
|
| 21 |
+
interface.launch()
|