CoolFace
Apppublic

edmagall/entregable3

sourceHugging Faceupdated 3y agoView on Hugging Face
0likes
app.py20 linesDownload Raw Back to root
1from huggingface_hub import from_pretrained_fastai2import gradio as gr3from fastai.vision.all import *4 5 6 7# repo_id = "YOUR_USERNAME/YOUR_LEARNER_NAME"8repo_id = "edmagall/edmagall/hate_speech_offensive"9 10learner = from_pretrained_fastai(repo_id)11labels = learner.dls.vocab12 13# Definimos una función que se encarga de llevar a cabo las predicciones14def predict(tweet):15    #img = PILImage.create(img)16    pred,pred_idx,probs = learner.predict(tweet)17    return {labels[i]: float(probs[i]) for i in range(len(labels))}18    19# Creamos la interfaz y la lanzamos. 20gr.Interface(fn=predict, inputs=gr.inputs.Image(shape=(128, 128)), outputs=gr.outputs.Label(num_top_classes=3),examples=['fry.jpg','leela.jpg']).launch(share=False)