File size: 1,686 Bytes
f2854ec
1dbda4e
 
 
 
 
f2854ec
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
61
# run this to import all needed libraries
# !pip install -U duckduckgo_search
# !pip install firebase-admin
# !pip install gradio

# Vi behöver ladda ned alla libraries externt för att det ska funka

from fastai import *
from fastdownload import download_url
from fastai.vision.all import *
from fastcore.all import *
import gradio as gr


# ref = db.reference("/")
path = Path()
model = load_learner(path/"Emotionv2.pkl")
#working process , unpickling
# något sätt att ladda upp filer
# modellen visar de bilder den analyserar och vad den klassificierar

labelA = "Angry human face"
labelB = "Disgusted human face"
labelC = "Happy human face"
labelD = "Sad human face"

labels = ["Angry human face", "Disgusted human face", "Happy human face", "Sad human face"]

# this is where we use the model on a given file and get the classification and probability for it that the model gives
# img = PILImage.create("Sad2.jpg") # insert uploaded file name

def predict(img):
  img = PILImage.create(img)
  pred,_,probs = model.predict(img)
  # a = model.predict(img)
  return {labels[i]: float(probs[i]) for i in range(len(labels))}


# print(a)
# img.show()
# print(f"this is: {pred}")
# print(f"{labelA} {probs[0].item():.2f}")
# print(f"{labelB} {probs[1].item():.2f}")
# print(f"{labelC} {probs[2].item():.2f}")
# print(f"{labelD} {probs[3].item():.2f}")

# print(f"Probability of {pred}: {max(probs):.2f}")

interpretation='default'

# gr.Image(source="webcam", streaming=True),

gr.Interface(fn=predict,
             inputs=gr.inputs.Image(shape=(512, 512)),
             interpretation=interpretation,
             outputs=gr.outputs.Label(num_top_classes=4)).launch(share=True)