Spaces:
Runtime error
Runtime error
MSP RAJA
commited on
Commit
•
d7cce73
1
Parent(s):
8b7d0dd
using_xlm_roberts
Browse files- README.md +31 -7
- app.py +45 -0
- requirements.txt +2 -0
README.md
CHANGED
@@ -1,13 +1,37 @@
|
|
1 |
---
|
2 |
-
title:
|
3 |
-
emoji:
|
4 |
-
colorFrom:
|
5 |
-
colorTo:
|
6 |
sdk: gradio
|
7 |
-
sdk_version: 3.16.1
|
8 |
app_file: app.py
|
9 |
pinned: false
|
10 |
-
license: mit
|
11 |
---
|
12 |
|
13 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
---
|
2 |
+
title: LanguageDetector
|
3 |
+
emoji: 💻
|
4 |
+
colorFrom: pink
|
5 |
+
colorTo: purple
|
6 |
sdk: gradio
|
|
|
7 |
app_file: app.py
|
8 |
pinned: false
|
|
|
9 |
---
|
10 |
|
11 |
+
# Configuration
|
12 |
+
|
13 |
+
`title`: _string_
|
14 |
+
Display title for the Space
|
15 |
+
|
16 |
+
`emoji`: _string_
|
17 |
+
Space emoji (emoji-only character allowed)
|
18 |
+
|
19 |
+
`colorFrom`: _string_
|
20 |
+
Color for Thumbnail gradient (red, yellow, green, blue, indigo, purple, pink, gray)
|
21 |
+
|
22 |
+
`colorTo`: _string_
|
23 |
+
Color for Thumbnail gradient (red, yellow, green, blue, indigo, purple, pink, gray)
|
24 |
+
|
25 |
+
`sdk`: _string_
|
26 |
+
Can be either `gradio` or `streamlit`
|
27 |
+
|
28 |
+
`sdk_version` : _string_
|
29 |
+
Only applicable for `streamlit` SDK.
|
30 |
+
See [doc](https://hf.co/docs/hub/spaces) for more info on supported versions.
|
31 |
+
|
32 |
+
`app_file`: _string_
|
33 |
+
Path to your main application file (which contains either `gradio` or `streamlit` Python code).
|
34 |
+
Path is relative to the root of the repository.
|
35 |
+
|
36 |
+
`pinned`: _boolean_
|
37 |
+
Whether the Space stays on top of your list.
|
app.py
ADDED
@@ -0,0 +1,45 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
"""Gradio app to showcase the language detector."""
|
2 |
+
|
3 |
+
import gradio as gr
|
4 |
+
from transformers import pipeline
|
5 |
+
|
6 |
+
|
7 |
+
# Get transformer model and set up a pipeline
|
8 |
+
model_ckpt = "papluca/xlm-roberta-base-language-detection"
|
9 |
+
pipe = pipeline("text-classification", model=model_ckpt)
|
10 |
+
|
11 |
+
|
12 |
+
def predict(text: str) -> dict:
|
13 |
+
"""Compute predictions for text."""
|
14 |
+
preds = pipe(text, return_all_scores=True, truncation=True, max_length=128)
|
15 |
+
if preds:
|
16 |
+
pred = preds[0]
|
17 |
+
return {p["label"]: float(p["score"]) for p in pred}
|
18 |
+
else:
|
19 |
+
return None
|
20 |
+
|
21 |
+
|
22 |
+
title = "Language detection with XLM-RoBERTa"
|
23 |
+
description = "Determine the language in which your text is written."
|
24 |
+
examples = [
|
25 |
+
["Better late than never."],
|
26 |
+
["Tutto è bene ciò che finisce bene."],
|
27 |
+
["Donde hay humo, hay fuego."],
|
28 |
+
]
|
29 |
+
explanation = "Supported languages are (20): arabic (ar), bulgarian (bg), german (de), modern greek (el), english (en), spanish (es), french (fr), hindi (hi), italian (it), japanese (ja), dutch (nl), polish (pl), portuguese (pt), russian (ru), swahili (sw), thai (th), turkish (tr), urdu (ur), vietnamese (vi), and chinese (zh)."
|
30 |
+
|
31 |
+
app = gr.Interface(
|
32 |
+
fn=predict,
|
33 |
+
inputs=gr.inputs.Textbox(
|
34 |
+
placeholder="What's the text you want to know the language for?",
|
35 |
+
label="Text",
|
36 |
+
lines=3,
|
37 |
+
),
|
38 |
+
outputs=gr.outputs.Label(num_top_classes=3, label="Your text is written in "),
|
39 |
+
title=title,
|
40 |
+
description=description,
|
41 |
+
examples=examples,
|
42 |
+
article=explanation,
|
43 |
+
)
|
44 |
+
|
45 |
+
app.launch()
|
requirements.txt
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
transformers==4.12.5
|
2 |
+
torch==1.5.0
|