Update app.py
Browse files
app.py
CHANGED
@@ -1,6 +1,7 @@
|
|
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)
|
@@ -8,7 +9,7 @@ model = fasttext.load_model(model_path)
|
|
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 |
|
|
|
1 |
import fasttext
|
2 |
from huggingface_hub import hf_hub_download
|
3 |
import gradio as gr
|
4 |
+
import numpy as np
|
5 |
|
6 |
model_path = hf_hub_download(repo_id="facebook/fasttext-language-identification", filename="model.bin")
|
7 |
model = fasttext.load_model(model_path)
|
|
|
9 |
def predict(text, top):
|
10 |
labels, probabilities = model.predict(text, k=top)
|
11 |
cleaned_labels = [label.replace('__label__', '') for label in labels]
|
12 |
+
result = dict(zip(cleaned_labels, np.array(probabilities)))
|
13 |
#result = sorted(result, key=lambda x: x[1], reverse=True)
|
14 |
return result
|
15 |
|