Spaces:
Running
Running
CatherineProtas
commited on
Commit
•
0ab6864
1
Parent(s):
488bbc2
Upload 5 files
Browse files- app.py +36 -0
- dar.jpg +0 -0
- dar2.jpg +0 -0
- dar3.jpg +0 -0
- fog_classifier.pkl +3 -0
app.py
ADDED
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from fastai.vision.all import *
|
3 |
+
from fastai.vision.all import PILImage
|
4 |
+
|
5 |
+
# Load the trained model
|
6 |
+
learn = load_learner('fog_classifier.pkl')
|
7 |
+
|
8 |
+
# Get the labels from the data loaders
|
9 |
+
labels = learn.dls.vocab
|
10 |
+
|
11 |
+
# Define the prediction function
|
12 |
+
def predict(img):
|
13 |
+
img = PILImage.create(img)
|
14 |
+
img = img.resize((512, 512))
|
15 |
+
pred, pred_idx, probs = learn.predict(img)
|
16 |
+
return {labels[i]: float(probs[i]) for i in range(len(labels))}
|
17 |
+
|
18 |
+
# Example images for demonstration
|
19 |
+
examples = [
|
20 |
+
"dar3.jpg",
|
21 |
+
"dar2.jpg"
|
22 |
+
]
|
23 |
+
|
24 |
+
# Create the Gradio interface
|
25 |
+
interface = gr.Interface(
|
26 |
+
fn=predict,
|
27 |
+
inputs=gr.Image(),
|
28 |
+
outputs=gr.Label(num_top_classes=3),
|
29 |
+
examples=examples # Move examples here
|
30 |
+
)
|
31 |
+
|
32 |
+
# Enable the queue to handle POST requests
|
33 |
+
interface.queue(api_open=True)
|
34 |
+
|
35 |
+
# Launch the interface
|
36 |
+
interface.launch()
|
dar.jpg
ADDED
dar2.jpg
ADDED
dar3.jpg
ADDED
fog_classifier.pkl
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:261d104955b6d3efc06d3e3b25ab104b790c60a7ef78d79665cad81f35ffaff7
|
3 |
+
size 348590778
|