Spaces:
Sleeping
Sleeping
DrChamyoung
commited on
Commit
•
c348026
1
Parent(s):
47b4f9c
Update app.py
Browse files
app.py
CHANGED
@@ -1,50 +1,38 @@
|
|
1 |
-
## import gradio as gr
|
2 |
-
#
|
3 |
-
## def greet(name):
|
4 |
-
## return "Hello " + name + "!!"
|
5 |
-
#
|
6 |
-
## iface = gr.Interface(fn=greet, inputs="text", outputs="text")
|
7 |
-
## iface.launch()
|
8 |
-
|
9 |
import gradio as gr
|
10 |
from fastai.vision.all import *
|
11 |
-
import skimage
|
12 |
import pathlib
|
|
|
|
|
13 |
temp = pathlib.PosixPath
|
14 |
pathlib.PosixPath = pathlib.WindowsPath
|
15 |
pathlib.PosixPath = temp
|
16 |
|
|
|
17 |
learn = load_learner('model.pkl')
|
18 |
labels = learn.dls.vocab
|
|
|
|
|
19 |
def predict(img):
|
20 |
img = PILImage.create(img)
|
21 |
-
pred,pred_idx,probs = learn.predict(img)
|
22 |
return {labels[i]: float(probs[i]) for i in range(len(labels))}
|
23 |
|
|
|
24 |
title = "Female/Male Classifier"
|
25 |
description = "A Female/Male classifier trained on the duckduckgo search result with fastai. Created as a demo for Gradio and HuggingFace Spaces."
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
'femaleAngry1.jpg', 'femaleAngry2.jpg',
|
30 |
-
'femaleMuscle1.jpg', 'femaleMuscle2.jpg',
|
31 |
-
'maleAsian.jpg', 'maleEurope.jpg',
|
32 |
-
'femaleAsian.jpg', 'femaleDefault.jpg',
|
33 |
-
'maleCrying2.jpg', 'maleCrying2No.jpg']
|
34 |
-
#interpretation='default'
|
35 |
-
enable_queue=True
|
36 |
-
#
|
37 |
-
## gr.Interface(fn=predict,inputs=gr.inputs.Image(shape=(512, 512)),outputs=gr.outputs.Label(),title=title,description=description,article=article,examples=examples,interpretation=interpretation,enable_queue=enable_queue).launch()
|
38 |
-
#
|
39 |
inter = gr.Interface(
|
40 |
fn=predict,
|
41 |
-
inputs=gr.Image(shape=(512, 512)),
|
42 |
-
outputs=gr.
|
43 |
title=title,
|
44 |
description=description,
|
45 |
examples=examples,
|
46 |
cache_examples=True,
|
47 |
-
examples_per_page=2
|
|
|
48 |
|
49 |
inter.queue()
|
50 |
-
inter.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
from fastai.vision.all import *
|
|
|
3 |
import pathlib
|
4 |
+
|
5 |
+
# Adjust the path handling for compatibility between different OS
|
6 |
temp = pathlib.PosixPath
|
7 |
pathlib.PosixPath = pathlib.WindowsPath
|
8 |
pathlib.PosixPath = temp
|
9 |
|
10 |
+
# Load your pre-trained model
|
11 |
learn = load_learner('model.pkl')
|
12 |
labels = learn.dls.vocab
|
13 |
+
|
14 |
+
# Prediction function
|
15 |
def predict(img):
|
16 |
img = PILImage.create(img)
|
17 |
+
pred, pred_idx, probs = learn.predict(img)
|
18 |
return {labels[i]: float(probs[i]) for i in range(len(labels))}
|
19 |
|
20 |
+
# Title and description
|
21 |
title = "Female/Male Classifier"
|
22 |
description = "A Female/Male classifier trained on the duckduckgo search result with fastai. Created as a demo for Gradio and HuggingFace Spaces."
|
23 |
+
examples = ['femaleDefault.jpg', 'maleDefault.jpg', 'dragQueen1.jpg', 'dragQueen2.jpg', 'femaleAngry1.jpg', 'femaleAngry2.jpg', 'femaleMuscle1.jpg', 'femaleMuscle2.jpg', 'maleAsian.jpg', 'maleEurope.jpg', 'femaleAsian.jpg', 'femaleDefault.jpg', 'maleCrying2.jpg', 'maleCrying2No.jpg']
|
24 |
+
|
25 |
+
# Update the Gradio Interface without using deprecated arguments
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
26 |
inter = gr.Interface(
|
27 |
fn=predict,
|
28 |
+
inputs=gr.Image(type="pil", shape=(512, 512)), # "type='pil'" specifies the image type
|
29 |
+
outputs=gr.Label(),
|
30 |
title=title,
|
31 |
description=description,
|
32 |
examples=examples,
|
33 |
cache_examples=True,
|
34 |
+
examples_per_page=2
|
35 |
+
)
|
36 |
|
37 |
inter.queue()
|
38 |
+
inter.launch()
|