Spaces:
Sleeping
Sleeping
| from huggingface_hub import from_pretrained_fastai | |
| import gradio as gr | |
| from fastai.vision.all import * | |
| # repo_id = "YOUR_USERNAME/YOUR_LEARNER_NAME" | |
| repo_id = "rasaenluis3/e3Modelo" | |
| learner = from_pretrained_fastai(repo_id) | |
| labels = ['0','1','2','3','4','5'] | |
| # Auxiliar | |
| def catToValue(cat): | |
| if cat == '0': | |
| return 'sadness' | |
| elif cat == '1': | |
| return 'joy' # wonderhoy :) | |
| elif cat == '2': | |
| return 'love' | |
| elif cat == '3': | |
| return 'anger' | |
| elif cat == '4': | |
| return 'fear' | |
| elif cat == '5': | |
| return 'surprise' | |
| else: | |
| return str(cat) | |
| # Definimos una función que se encarga de llevar a cabo las predicciones | |
| def predict(texto): | |
| print(texto) | |
| pred,pred_idx,probs = learner.predict(texto) | |
| si = {catToValue(labels[i]): float(probs[i]) for i in range(len(labels))} | |
| print(si) | |
| return si | |
| # Creamos la interfaz y la lanzamos. | |
| gr.Interface(fn=predict, inputs=gr.inputs.Textbox(lines=3,label="Escríbeme in english please"), outputs=gr.outputs.Label(num_top_classes=3)).launch(share=False) | |