Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,30 +1,60 @@
|
|
| 1 |
-
from fastai.vision.all import *
|
| 2 |
-
import gradio as gr
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
|
| 5 |
-
#is_black(x) : return x[0].isupper()
|
| 6 |
|
| 7 |
def input_img(img):
|
| 8 |
-
learn
|
| 9 |
-
race,_,probs = learn.predict(img)
|
| 10 |
-
#
|
| 11 |
processed_output=(f"This is a: {race}./nProbability it's a black person: {probs[0]:.4f}.\nProbability it's a white person: {probs[1]:.4f}")
|
| 12 |
return processed_output
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
|
|
|
|
|
|
| 18 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
image=gr.inputs.Image(shape=(192,192))
|
| 20 |
label=gr.outputs.Label()
|
| 21 |
examples=('Black people','White people')
|
| 22 |
-
|
| 23 |
-
demo
|
| 24 |
-
demo.launch(inline=False)
|
| 25 |
-
|
| 26 |
-
#image=gr.inputs.Image(shape=(192,192))
|
| 27 |
-
#label=gr.outputs.Label()
|
| 28 |
-
#examples=('Black people','White people')
|
| 29 |
-
#demo = gr.Interface(fn=func_classi, inputs=[gr.func_classi()], outputs=[gr.Textbook(label="Results")])
|
| 30 |
-
#demo.launch(inline=False)
|
|
|
|
| 1 |
+
# from fastai.vision.all import *
|
| 2 |
+
# import gradio as gr
|
| 3 |
+
|
| 4 |
+
|
| 5 |
+
# #is_black(x) : return x[0].isupper()
|
| 6 |
+
|
| 7 |
+
# def input_img(img):
|
| 8 |
+
# learn=load_learner('model.pkl')
|
| 9 |
+
# race,_,probs = learn.predict(img)
|
| 10 |
+
# #print(f"This is a: {race}.")
|
| 11 |
+
# processed_output=(f"This is a: {race}./nProbability it's a black person: {probs[0]:.4f}.\nProbability it's a white person: {probs[1]:.4f}")
|
| 12 |
+
# return processed_output
|
| 13 |
+
|
| 14 |
+
# # categories=('Black people','White people')
|
| 15 |
+
# # def func_classi(img):
|
| 16 |
+
# # pred,idx,probs=learn.predict(img)
|
| 17 |
+
# # return dict(zip(categories,map(float,probs)))
|
| 18 |
+
|
| 19 |
+
# image=gr.inputs.Image(shape=(192,192))
|
| 20 |
+
# label=gr.outputs.Label()
|
| 21 |
+
# examples=('Black people','White people')
|
| 22 |
+
# #demo = gr.Interface(fn=func_classi, inputs="image", outputs="label")
|
| 23 |
+
# demo = gr.Interface(fn=input_img, inputs="image", outputs="label")
|
| 24 |
+
# demo.launch(inline=False)
|
| 25 |
|
| 26 |
+
# #image=gr.inputs.Image(shape=(192,192))
|
| 27 |
+
# #label=gr.outputs.Label()
|
| 28 |
+
# #examples=('Black people','White people')
|
| 29 |
+
# #demo = gr.Interface(fn=func_classi, inputs=[gr.func_classi()], outputs=[gr.Textbook(label="Results")])
|
| 30 |
+
# #demo.launch(inline=False)
|
| 31 |
|
|
|
|
| 32 |
|
| 33 |
def input_img(img):
|
| 34 |
+
race,_,probs = learn.predict(PILImage.create('img'))
|
| 35 |
+
#race,_,probs = learn.predict(PILImage.create(img))
|
| 36 |
+
#processed_output=(f"This is a: {race}./nProbability it's a black person: {probs[0]:.4f}.\nProbability it's a white person: {probs[1]:.4f}")
|
| 37 |
processed_output=(f"This is a: {race}./nProbability it's a black person: {probs[0]:.4f}.\nProbability it's a white person: {probs[1]:.4f}")
|
| 38 |
return processed_output
|
| 39 |
+
learn.export('model.pkl')
|
| 40 |
+
|
| 41 |
+
im=PILImage.create(img)
|
| 42 |
+
im=PILImage.create('img')
|
| 43 |
+
im.thumbnail((192,192))
|
| 44 |
+
|
| 45 |
+
learn=load_learner('model.pkl')
|
| 46 |
|
| 47 |
+
learn.predict(im)
|
| 48 |
+
|
| 49 |
+
categories=('Black people','White people')
|
| 50 |
+
def func_classi(img):
|
| 51 |
+
pred,idx,probs=learn.predict(img)
|
| 52 |
+
return dict(zip(categories,map(float,probs)))
|
| 53 |
+
|
| 54 |
+
func_classi(im)
|
| 55 |
+
import gradio as gr
|
| 56 |
image=gr.inputs.Image(shape=(192,192))
|
| 57 |
label=gr.outputs.Label()
|
| 58 |
examples=('Black people','White people')
|
| 59 |
+
demo = gr.Interface(fn=func_classi, inputs="image", outputs="label")
|
| 60 |
+
demo.launch(inline=False)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|