Update app.py
Browse files
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="
|
7 |
|
8 |
-
# Charger le modèle
|
9 |
model = fasttext.load_model(model_path)
|
10 |
|
11 |
-
# Fonction de prédiction de la langue
|
12 |
def predict_language(text):
|
13 |
-
|
14 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
15 |
|
16 |
# Interface Gradio
|
17 |
-
iface = gr.Interface(fn=predict_language,
|
|
|
|
|
|
|
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)
|