Muhammed Machrouh
commited on
Commit
Β·
c4537cc
1
Parent(s):
adb0df0
inital file system
Browse files- README.md +7 -7
- app.py +24 -0
- requirements.txt +4 -0
README.md
CHANGED
@@ -1,13 +1,13 @@
|
|
1 |
---
|
2 |
-
title: Fasttext
|
3 |
-
emoji:
|
4 |
-
colorFrom:
|
5 |
-
colorTo:
|
6 |
sdk: gradio
|
7 |
-
sdk_version: 5.
|
8 |
app_file: app.py
|
9 |
pinned: false
|
10 |
-
license:
|
11 |
---
|
12 |
|
13 |
-
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
1 |
---
|
2 |
+
title: Fasttext Language Identification
|
3 |
+
emoji: π
|
4 |
+
colorFrom: indigo
|
5 |
+
colorTo: blue
|
6 |
sdk: gradio
|
7 |
+
sdk_version: 5.9.0
|
8 |
app_file: app.py
|
9 |
pinned: false
|
10 |
+
license: apache-2.0
|
11 |
---
|
12 |
|
13 |
+
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
app.py
ADDED
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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="medmac01/fasttext-darija-identification", filename="model.bin")
|
7 |
+
model = fasttext.load_model(model_path)
|
8 |
+
|
9 |
+
def predict(text, top=2):
|
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 |
+
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)
|
requirements.txt
ADDED
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
gradio
|
2 |
+
fasttext
|
3 |
+
huggingface_hub
|
4 |
+
numpy==1.26.4
|