File size: 1,685 Bytes
4ac740a
fc5225d
4ac740a
 
fc5225d
4ac740a
fc5225d
 
57b0d6a
4ac740a
f3cb11d
 
 
57b0d6a
ff84e55
 
 
 
 
4ac740a
 
 
ff84e55
 
 
 
4ac740a
fc5225d
 
ff84e55
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
from fastai.text.all import *
from huggingface_hub import from_pretrained_fastai
import gradio as gr

# Cargamos el learner
repo_id = "joferngome/Emotions"
learner = from_pretrained_fastai(repo_id)
labels = learner.dls.vocab

# Definimos las etiquetas de nuestro modelo
#labels = list(range(28))
labels=["admiration","amusement","anger","annoyance","approval","caring","confusion","curiosity","desire","disappointment","disapproval","disgust","embarrasement",
       "excitement","fear","gratitude","grief","joy","love","nervousness","optimism","pride","realization","relief","remorse","sadness","surprise","neutral"]

example1 = "As the gentle breeze caressed the emerald fields, a symphony of rustling leaves and chirping birds filled the air, creating a harmonious melody that echoed through the tranquil countryside."

example2 = "In the midst of a bustling city, amidst the towering skyscrapers and buzzing crowds, two souls found solace in each other's embrace, their love creating a sanctuary of serenity amidst the chaos."

example3 = "With each stroke of the artist's brush, the canvas transformed into a vibrant tapestry of colors, capturing the essence of life and evoking emotions that words alone could never convey."

# Definimos una función que se encarga de llevar a cabo las predicciones
def predict(text):
    probs= learner.predict(text)[2]
    # print(pred)
    # probs = pred['probs']
    print(probs)
    return {labels[i]: float(probs[i]) for i in range(len(labels))}
    
# Creamos la interfaz y la lanzamos. 
gr.Interface(fn=predict, inputs=gr.inputs.Textbox(), outputs=gr.outputs.Label(),examples=[example1,example2,example3]).launch(share=False,debug=True)