Spaces:
Runtime error
Runtime error
firts try test
Browse files
app.py
ADDED
@@ -0,0 +1,59 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# run this to import all needed libraries
|
2 |
+
!pip install -U duckduckgo_search
|
3 |
+
!pip install firebase-admin
|
4 |
+
!pip install gradio
|
5 |
+
|
6 |
+
from fastai import *
|
7 |
+
from fastdownload import download_url
|
8 |
+
from fastai.vision.all import *
|
9 |
+
from duckduckgo_search import ddg_images
|
10 |
+
from fastcore.all import *
|
11 |
+
import gradio as gr
|
12 |
+
|
13 |
+
|
14 |
+
# ref = db.reference("/")
|
15 |
+
path = Path()
|
16 |
+
model = load_learner(path/"Emotionv2.pkl")
|
17 |
+
#working process , unpickling
|
18 |
+
# något sätt att ladda upp filer
|
19 |
+
# modellen visar de bilder den analyserar och vad den klassificierar
|
20 |
+
|
21 |
+
labelA = "Angry human face"
|
22 |
+
labelB = "Disgusted human face"
|
23 |
+
labelC = "Happy human face"
|
24 |
+
labelD = "Sad human face"
|
25 |
+
|
26 |
+
labels = ["Angry human face", "Disgusted human face", "Happy human face", "Sad human face"]
|
27 |
+
|
28 |
+
# this is where we use the model on a given file and get the classification and probability for it that the model gives
|
29 |
+
# img = PILImage.create("Sad2.jpg") # insert uploaded file name
|
30 |
+
|
31 |
+
def predict(img):
|
32 |
+
img = PILImage.create(img)
|
33 |
+
pred,_,probs = model.predict(img)
|
34 |
+
# a = model.predict(img)
|
35 |
+
return {labels[i]: float(probs[i]) for i in range(len(labels))}
|
36 |
+
|
37 |
+
|
38 |
+
# print(a)
|
39 |
+
# img.show()
|
40 |
+
# print(f"this is: {pred}")
|
41 |
+
# print(f"{labelA} {probs[0].item():.2f}")
|
42 |
+
# print(f"{labelB} {probs[1].item():.2f}")
|
43 |
+
# print(f"{labelC} {probs[2].item():.2f}")
|
44 |
+
# print(f"{labelD} {probs[3].item():.2f}")
|
45 |
+
|
46 |
+
# print(f"Probability of {pred}: {max(probs):.2f}")
|
47 |
+
|
48 |
+
interpretation='default'
|
49 |
+
|
50 |
+
# gr.Image(source="webcam", streaming=True),
|
51 |
+
|
52 |
+
gr.Interface(fn=predict,
|
53 |
+
inputs=gr.inputs.Image(shape=(512, 512)),
|
54 |
+
interpretation=interpretation,
|
55 |
+
outputs=gr.outputs.Label(num_top_classes=4)).launch(share=True)
|
56 |
+
|
57 |
+
|
58 |
+
|
59 |
+
|