entregable3 / app.py
enamezto's picture
Create app.py
047d5d6 verified
from huggingface_hub import from_pretrained_fastai
from fastai.text.all import *
import gradio as gr
repo_id = "enamezto/MMLA"
learnerClass = from_pretrained_fastai(repo_id)
labels = [' acknowledge', ' advise', ' agree', ' agreement', ' anger', ' angry', ' answer', ' apologise', ' apology', ' arrange', ' ask for help', ' asking for opinions', ' backchannel', ' care', ' change', ' comfort', ' command', ' complain', ' confirm', ' criticize', ' disagreement', ' disgust', ' doubt', ' emphasize', ' excited', ' explain', ' fear', ' flaunt', ' frustrated', ' greet', ' greeting', ' happy', ' humorous', ' inform', ' introduce', ' invite', ' joke', ' joy', ' leave', ' negative', ' neutral', ' oppose', ' other', ' others', ' plan', ' positive', ' praise', ' prevent', ' question', ' reflection', ' refuse', ' sad', ' sadness', ' sarcastic', ' serious', ' sincere', ' statement-non-opinion', ' statement-opinion', ' surprise', ' sustain', ' taunt', ' thank', ' therapist_input', ' warn']
def predict(text):
pred, pred_idx, probs = learnerClass.predict(text)
return {labels[i]: float(probs[i]) for i in range(len(labels))}
gr.Interface(
fn=predict,
inputs=gr.Textbox(lines=3, placeholder="Escribe una frase cualquiera..."),
outputs=gr.Label(num_top_classes=3),
title="Clasificador de frases",
description="Introduce la frase"
).launch()