# 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)