Spaces:
Build error
Build error
| 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 = "KaraSpdrnr/language-predictor" | |
| learner = from_pretrained_fastai(repo_id) | |
| labels = learner.dls.vocab | |
| # Definimos una función que se encarga de llevar a cabo las predicciones | |
| def predict(txt): | |
| pred, pred_idx, probs = learner.predict(txt) | |
| print(pred) | |
| print(pred_idx) | |
| print(probs) | |
| label = str(pred) # Convertir la etiqueta predicha a cadena | |
| print(label[1]) | |
| return {label: float(probs[pred_idx])} | |
| examples = [ | |
| ["Este es un ejemplo de texto en español."], | |
| ["This is an example that should return en."], | |
| ["هذا النص جميل جداً وهو عربي"], | |
| ["Този текст е много красив и български"], | |
| ["これは日本語でも中国語との違いが分かる素晴らしいフレーズです。"] | |
| ] | |
| # Creamos la interfaz y la lanzamos. | |
| gr.Interface(fn=predict, inputs=gr.inputs.Textbox(lines=5, label="Ingrese el texto"), outputs=gr.outputs.Label(num_top_classes=3),examples=examples).launch(share=False) | |