|
import fasttext |
|
import gradio as gr |
|
from huggingface_hub import hf_hub_download |
|
|
|
|
|
model_path = hf_hub_download(repo_id="facebook/fasttext-language-identification", filename="lid.218.bin") |
|
|
|
|
|
model = fasttext.load_model(model_path) |
|
|
|
def predict_language(text): |
|
|
|
text = text.replace('\n', ' ').strip() |
|
|
|
|
|
labels, probs = model.predict(text) |
|
|
|
|
|
return labels[0], probs[0] |
|
|
|
|
|
iface = gr.Interface( |
|
fn=predict_language, |
|
inputs=gr.Textbox(label="Entrez votre texte ici"), |
|
outputs=[gr.Text(label="Langue prédite"), gr.Text(label="Probabilité")], |
|
live=True |
|
) |
|
|
|
|
|
if __name__ == "__main__": |
|
iface.launch(share=True) |
|
|