Update app.py
Browse files
app.py
CHANGED
@@ -1,3 +1,24 @@
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
|
3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import fasttext
|
2 |
+
from huggingface_hub import hf_hub_download
|
3 |
import gradio as gr
|
4 |
|
5 |
+
model_path = hf_hub_download(repo_id="facebook/fasttext-language-identification", filename="model.bin")
|
6 |
+
model = fasttext.load_model(model_path)
|
7 |
+
|
8 |
+
def predict(text, top):
|
9 |
+
labels, probabilities = model.predict(text, k=top)
|
10 |
+
cleaned_labels = [label.replace('__label__', '') for label in labels]
|
11 |
+
result = dict(zip(cleaned_labels, probabilities))
|
12 |
+
#result = sorted(result, key=lambda x: x[1], reverse=True)
|
13 |
+
return result
|
14 |
+
|
15 |
+
demo = gr.Interface(
|
16 |
+
fn=predict,
|
17 |
+
inputs=[
|
18 |
+
gr.Textbox(lines=1, placeholder="Text", label="Content"),
|
19 |
+
gr.Number(value=5, info='number of predictions that should be returned', minimum=1, maximum=100, label="Top"),
|
20 |
+
],
|
21 |
+
title="Language Identification Demo",
|
22 |
+
flagging_mode="never",
|
23 |
+
outputs=gr.Label(label="Result"))
|
24 |
+
demo.launch(share=True, show_api=True)
|