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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -8
app.py CHANGED
@@ -1,20 +1,29 @@
1
- from huggingface_hub import hf_hub_download
2
  import fasttext
3
  import gradio as gr
 
4
 
5
  # Télécharger le modèle depuis Hugging Face
6
- model_path = hf_hub_download(repo_id="facebook/fasttext-language-identification", filename="model.bin")
7
 
8
- # Charger le modèle avec fastText
9
  model = fasttext.load_model(model_path)
10
 
11
- # Fonction de prédiction de la langue
12
  def predict_language(text):
13
- prediction = model.predict(text)
14
- return prediction[0][0] # Retourne la langue prédite
 
 
 
 
 
 
15
 
16
  # Interface Gradio
17
- iface = gr.Interface(fn=predict_language, inputs="text", outputs="text", live=True)
 
 
 
18
 
 
19
  if __name__ == "__main__":
20
- iface.launch()
 
 
1
  import fasttext
2
  import gradio as gr
3
+ from huggingface_hub import hf_hub_download
4
 
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)