Spaces:
Runtime error
Runtime error
clean up
Browse files
app.py
CHANGED
|
@@ -39,22 +39,21 @@ def identify_language(text):
|
|
| 39 |
|
| 40 |
|
| 41 |
def translate(text, src_lang, tgt_lang):
|
| 42 |
-
src_lang_code = language_code_map[src_lang]
|
| 43 |
-
tgt_lang_code = language_code_map[tgt_lang]
|
| 44 |
-
|
| 45 |
translation_pipeline = pipeline(
|
| 46 |
-
"translation", model=model, tokenizer=tokenizer, src_lang=
|
| 47 |
result = translation_pipeline(text)
|
| 48 |
return result[0]['translation_text']
|
| 49 |
|
| 50 |
|
| 51 |
def query(text, user_lang):
|
| 52 |
-
|
|
|
|
|
|
|
| 53 |
|
| 54 |
translation = translate(
|
| 55 |
-
text,
|
| 56 |
|
| 57 |
-
return [
|
| 58 |
|
| 59 |
|
| 60 |
examples = [
|
|
@@ -69,7 +68,7 @@ gr.Interface(
|
|
| 69 |
[
|
| 70 |
gr.Textbox(lines=3, label="User Input"),
|
| 71 |
gr.Radio(["English", "Spanish", "Korean", "French", "German", "Japanese"],
|
| 72 |
-
value="English", label="User
|
| 73 |
],
|
| 74 |
outputs=[
|
| 75 |
gr.Textbox(lines=1, label="Detected Language"),
|
|
|
|
| 39 |
|
| 40 |
|
| 41 |
def translate(text, src_lang, tgt_lang):
|
|
|
|
|
|
|
|
|
|
| 42 |
translation_pipeline = pipeline(
|
| 43 |
+
"translation", model=model, tokenizer=tokenizer, src_lang=src_lang, tgt_lang=tgt_lang, device=device)
|
| 44 |
result = translation_pipeline(text)
|
| 45 |
return result[0]['translation_text']
|
| 46 |
|
| 47 |
|
| 48 |
def query(text, user_lang):
|
| 49 |
+
detected_lang_code = identify_language(text)
|
| 50 |
+
|
| 51 |
+
user_lang_code = language_code_map[user_lang]
|
| 52 |
|
| 53 |
translation = translate(
|
| 54 |
+
text, detected_lang_code, user_lang_code) if detected_lang_code != user_lang_code else "N/A \n(User's content language is the same as the language of the input)"
|
| 55 |
|
| 56 |
+
return [detected_lang_code, translation]
|
| 57 |
|
| 58 |
|
| 59 |
examples = [
|
|
|
|
| 68 |
[
|
| 69 |
gr.Textbox(lines=3, label="User Input"),
|
| 70 |
gr.Radio(["English", "Spanish", "Korean", "French", "German", "Japanese"],
|
| 71 |
+
value="English", label="User Content Language Settings"),
|
| 72 |
],
|
| 73 |
outputs=[
|
| 74 |
gr.Textbox(lines=1, label="Detected Language"),
|