Spaces:
Runtime error
Runtime error
add examples
Browse files
app.py
CHANGED
|
@@ -5,7 +5,6 @@ import gradio as gr
|
|
| 5 |
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM, pipeline
|
| 6 |
import torch
|
| 7 |
|
| 8 |
-
|
| 9 |
title = "Community Tab Language Detection & Translation"
|
| 10 |
description = """
|
| 11 |
When comments are created in the community tab, detect the language of the content.
|
|
@@ -23,8 +22,6 @@ headers = {"Authorization": f"Bearer {ACCESS_TOKEN}"}
|
|
| 23 |
model = AutoModelForSeq2SeqLM.from_pretrained("facebook/nllb-200-distilled-600M")
|
| 24 |
tokenizer = AutoTokenizer.from_pretrained("facebook/nllb-200-distilled-600M")
|
| 25 |
device = 0 if torch.cuda.is_available() else -1
|
| 26 |
-
LANGS = ["ace_Arab", "eng_Latn", "fra_Latn", "spa_Latn"]
|
| 27 |
-
|
| 28 |
|
| 29 |
language_code_map = {
|
| 30 |
"English": "eng_Latn",
|
|
@@ -62,12 +59,18 @@ def query(text, src_lang, tgt_lang):
|
|
| 62 |
return [lang_id, translation]
|
| 63 |
|
| 64 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 65 |
gr.Interface(
|
| 66 |
query,
|
| 67 |
[
|
| 68 |
gr.Textbox(lines=2),
|
| 69 |
-
gr.Radio(["English", "
|
| 70 |
-
gr.Radio(["
|
| 71 |
# gr.Radio(["English", "French", "Korean"]),
|
| 72 |
# gr.Radio(["Spanish", "German", "French"]),
|
| 73 |
],
|
|
@@ -76,5 +79,6 @@ gr.Interface(
|
|
| 76 |
gr.Textbox(lines=3, label="Translation")
|
| 77 |
],
|
| 78 |
title=title,
|
| 79 |
-
description=description
|
|
|
|
| 80 |
).launch()
|
|
|
|
| 5 |
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM, pipeline
|
| 6 |
import torch
|
| 7 |
|
|
|
|
| 8 |
title = "Community Tab Language Detection & Translation"
|
| 9 |
description = """
|
| 10 |
When comments are created in the community tab, detect the language of the content.
|
|
|
|
| 22 |
model = AutoModelForSeq2SeqLM.from_pretrained("facebook/nllb-200-distilled-600M")
|
| 23 |
tokenizer = AutoTokenizer.from_pretrained("facebook/nllb-200-distilled-600M")
|
| 24 |
device = 0 if torch.cuda.is_available() else -1
|
|
|
|
|
|
|
| 25 |
|
| 26 |
language_code_map = {
|
| 27 |
"English": "eng_Latn",
|
|
|
|
| 59 |
return [lang_id, translation]
|
| 60 |
|
| 61 |
|
| 62 |
+
examples = [
|
| 63 |
+
["Hello, world", "English", "French"],
|
| 64 |
+
["Hasta la vista", "Spanish", "German"],
|
| 65 |
+
["동경에 휴가를 간다", "Korean", "Japanese"],
|
| 66 |
+
]
|
| 67 |
+
|
| 68 |
gr.Interface(
|
| 69 |
query,
|
| 70 |
[
|
| 71 |
gr.Textbox(lines=2),
|
| 72 |
+
gr.Radio(["English", "Spanish", "Korean"], value="English", label="Source Language"),
|
| 73 |
+
gr.Radio(["French", "German", "Japanese"], value="French", label="Target Language")
|
| 74 |
# gr.Radio(["English", "French", "Korean"]),
|
| 75 |
# gr.Radio(["Spanish", "German", "French"]),
|
| 76 |
],
|
|
|
|
| 79 |
gr.Textbox(lines=3, label="Translation")
|
| 80 |
],
|
| 81 |
title=title,
|
| 82 |
+
description=description,
|
| 83 |
+
examples=examples
|
| 84 |
).launch()
|