File size: 2,112 Bytes
60959dc
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f703f2c
60959dc
 
 
 
 
f703f2c
203dd63
747c14c
4dc7d59
60959dc
 
 
7ec9149
 
60959dc
 
 
 
 
747c14c
d78bec8
60959dc
 
 
 
 
 
 
 
 
7d6f63f
 
 
60959dc
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# from fastai.vision.all import *
# import gradio as gr


# #is_black(x) : return x[0].isupper()

# def input_img(img):
#     learn=load_learner('model.pkl')
#     race,_,probs = learn.predict(img)
#     #print(f"This is a: {race}.")
#     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}")
#     return processed_output
    
# # categories=('Black people','White people')
# # def func_classi(img):
# #     pred,idx,probs=learn.predict(img)
# #     return dict(zip(categories,map(float,probs)))

# image=gr.inputs.Image(shape=(192,192))
# label=gr.outputs.Label()
# examples=('Black people','White people')
# #demo = gr.Interface(fn=func_classi, inputs="image", outputs="label")
# demo = gr.Interface(fn=input_img, inputs="image", outputs="label")
# demo.launch(inline=False)

# #image=gr.inputs.Image(shape=(192,192))
# #label=gr.outputs.Label()
# #examples=('Black people','White people')
# #demo = gr.Interface(fn=func_classi, inputs=[gr.func_classi()], outputs=[gr.Textbook(label="Results")])
# #demo.launch(inline=False)

from fastai.vision.all import *
learn=load_learner('model.pkl')
def input_img(img):
    race,_,probs = learn.predict(PILImage.create('img'))
    #race,_,probs = learn.predict(PILImage.create(img))
    #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}")
    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}")
    return processed_output

im=PILImage.create(img)
im=PILImage.create('img')
im.thumbnail((192,192))



learn.predict(im)

categories=('Black people','White people')
def func_classi(img):
  pred,idx,probs=learn.predict(img)
  return dict(zip(categories,map(float,probs)))

func_classi(im)
import gradio as gr
image=gr.inputs.Image(shape=(192,192))
label=gr.outputs.Label()
examples=('Black people','White people')
demo = gr.Interface(fn=func_classi, inputs="image", outputs="label")
demo.launch(inline=False)