samdo20 commited on
Commit
e67adcc
·
verified ·
1 Parent(s): a270abe

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -8
app.py CHANGED
@@ -5,25 +5,27 @@ from huggingface_hub import hf_hub_download
5
  # Télécharger le modèle depuis Hugging Face
6
  model_path = hf_hub_download(repo_id="facebook/fasttext-language-identification", filename="lid.218.bin")
7
 
8
- # Charger le modèle
9
  model = fasttext.load_model(model_path)
10
 
11
  def predict_language(text):
12
  # Supprimer les retours à la ligne et les espaces inutiles
13
  text = text.replace('\n', ' ').strip()
14
 
15
- # Effectuer la prédiction
16
  labels, probs = model.predict(text)
17
 
18
- # Retourner la langue et la probabilité
19
  return labels[0], probs[0]
20
 
21
  # Interface Gradio
22
- iface = gr.Interface(fn=predict_language,
23
- inputs=gr.Textbox(label="Entrez votre texte ici"),
24
- outputs=[gr.Label(), gr.Label()],
25
- live=True)
 
 
26
 
27
- # Lancer l'application
28
  if __name__ == "__main__":
29
  iface.launch(share=True)
 
5
  # Télécharger le modèle depuis Hugging Face
6
  model_path = hf_hub_download(repo_id="facebook/fasttext-language-identification", filename="lid.218.bin")
7
 
8
+ # Charger le modèle avec FastText
9
  model = fasttext.load_model(model_path)
10
 
11
  def predict_language(text):
12
  # Supprimer les retours à la ligne et les espaces inutiles
13
  text = text.replace('\n', ' ').strip()
14
 
15
+ # Effectuer la prédiction de la langue
16
  labels, probs = model.predict(text)
17
 
18
+ # Retourner la langue prédite et la probabilité correspondante
19
  return labels[0], probs[0]
20
 
21
  # Interface Gradio
22
+ iface = gr.Interface(
23
+ fn=predict_language,
24
+ inputs=gr.Textbox(label="Entrez votre texte ici"),
25
+ outputs=[gr.Text(label="Langue prédite"), gr.Text(label="Probabilité")],
26
+ live=True
27
+ )
28
 
29
+ # Lancer l'application Gradio
30
  if __name__ == "__main__":
31
  iface.launch(share=True)