Spaces:
Sleeping
Sleeping
update
Browse files
app.py
ADDED
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from fastai.vision.all import load_learner, PILImage
|
3 |
+
|
4 |
+
# Load the pre-trained FastAI model
|
5 |
+
model_path = "path_to_your_fastai_model.pkl"
|
6 |
+
learn = load_learner(model_path)
|
7 |
+
|
8 |
+
# Define the prediction function
|
9 |
+
def predict(image):
|
10 |
+
img = PILImage.create(image)
|
11 |
+
pred_class, pred_idx, probs = learn.predict(img)
|
12 |
+
return f"Prediction: {pred_class}, Probability: {probs[pred_idx]:.4f}"
|
13 |
+
|
14 |
+
# Create the Gradio interface
|
15 |
+
demo = gr.Interface(
|
16 |
+
fn=predict,
|
17 |
+
inputs=gr.Image(type="file"),
|
18 |
+
outputs="text",
|
19 |
+
title="Image validation",
|
20 |
+
description="Upload an image and get the model's text prediction."
|
21 |
+
)
|
22 |
+
|
23 |
+
demo.launch()
|