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)