Spaces:
Sleeping
Sleeping
Commit
·
1997ff5
1
Parent(s):
69a1461
init
Browse files- app.py +29 -0
- exa1.jpeg +0 -0
- exa2.jpeg +0 -0
- model.pkl +3 -0
- requirements.txt +2 -0
app.py
ADDED
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from fastai.vision.all import *
|
2 |
+
import gradio as gr
|
3 |
+
import os
|
4 |
+
|
5 |
+
os.makedirs("uploads", exist_ok=True)
|
6 |
+
|
7 |
+
def classify_image(img):
|
8 |
+
learn = load_learner("model.pkl")
|
9 |
+
_, _, probs = learn.predict(img)
|
10 |
+
# Return a dictionary of label->confidence pairs
|
11 |
+
return dict(zip(learn.dls.vocab, map(float, probs)))
|
12 |
+
|
13 |
+
# Get a list of example images if they exist
|
14 |
+
examples = []
|
15 |
+
for filename in ["exa1.jpg", "exa2.jpg"]:
|
16 |
+
if os.path.exists(filename):
|
17 |
+
examples.append(filename)
|
18 |
+
|
19 |
+
# Create and launch the Gradio interface
|
20 |
+
interface = gr.Interface(
|
21 |
+
fn=classify_image,
|
22 |
+
inputs=gr.Image(type="pil"),
|
23 |
+
outputs=gr.Label(),
|
24 |
+
examples=examples,
|
25 |
+
title="German Bread Classification"
|
26 |
+
).launch(inline=True)
|
27 |
+
|
28 |
+
if __name__ == "__main__":
|
29 |
+
interface.launch(inline=False)
|
exa1.jpeg
ADDED
![]() |
exa2.jpeg
ADDED
![]() |
model.pkl
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:c005529b3bd79bd441f0ef025a93d88390edbd399b950c74b715ddc9e7d3509b
|
3 |
+
size 47009534
|
requirements.txt
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
fastai
|
2 |
+
gradio
|