Spaces:
Build error
Build error
Add predict function
Browse files1234567891011121314151617"""Gradio app to showcase the language detector."""import gradio as grtitle = "Language detection with XLM-RoBERTa"description = "Determine the language in which your text is written.\nSupported languages are (20): arabic (ar), bulgarian (bg), german (de), modern greek (el), english (en), spanish (es), french (fr), hindi (hi), italian (it), japanese (ja), dutch (nl), polish (pl), portuguese (pt), russian (ru), swahili (sw), thai (th), turkish (tr), urdu (ur), vietnamese (vi), and chinese (zh)."examples = [["Better late than never."],["Tutto è bene ciò che finisce bene."],["Donde hay humo, hay fuego."],]app = gr.Interface.load("huggingface/papluca/xlm-roberta-base-language-detection",description=description,examples=examples,)12345678910111213141516171819202122232425262728293031323334353637383940"""Gradio app to showcase the language detector."""import gradio as grfrom transformers import pipeline# Get transformer model and set up a pipelinemodel_ckpt = "papluca/xlm-roberta-base-language-detection"pipe = pipeline("text-classification", model=model_ckpt)def predict(text: str) -> dict:"""Compute predictions for text."""preds = pipe(text, return_all_scores=True)if preds:pred = preds[0]return {p["label"]: float(p["score"]) for p in pred}else:return Nonetitle = "Language detection with XLM-RoBERTa"description = "Determine the language in which your text is written. Supported languages are (20): arabic (ar), bulgarian (bg), german (de), modern greek (el), english (en), spanish (es), french (fr), hindi (hi), italian (it), japanese (ja), dutch (nl), polish (pl), portuguese (pt), russian (ru), swahili (sw), thai (th), turkish (tr), urdu (ur), vietnamese (vi), and chinese (zh)."examples = [["Better late than never."],["Tutto è bene ciò che finisce bene."],["Donde hay humo, hay fuego."],]app = gr.Interface(fn=predict,inputs=gr.inputs.Textbox(placeholder="What's the text you want to know the language for?",label="Text",lines=3,),outputs=gr.outputs.Label(num_top_classes=3, label="Your text is written in "),description=description,examples=examples,)
app.py+26-3