add translation
Browse files- app.py +9 -2
- requirements.txt +1 -0
app.py
CHANGED
@@ -2,6 +2,7 @@ import torch
|
|
2 |
import gradio as gr
|
3 |
from transformers import pipeline
|
4 |
import os
|
|
|
5 |
|
6 |
device = torch.cuda.current_device() if torch.cuda.is_available() else "cpu"
|
7 |
HF_AUTH_TOKEN = os.environ.get("HF_AUTH_TOKEN")
|
@@ -28,8 +29,10 @@ def get_answer(user_input, decoding_methods, num_beams, top_k, top_p, temperatur
|
|
28 |
penalty_alpha=penalty_alpha)
|
29 |
answer = generated_text[0]["generated_text"]
|
30 |
answer_without_prompt = answer[len(prompt)+1:]
|
31 |
-
|
32 |
-
|
|
|
|
|
33 |
|
34 |
|
35 |
with gr.Blocks() as demo:
|
@@ -59,6 +62,10 @@ with gr.Blocks() as demo:
|
|
59 |
label="Answer",
|
60 |
combine_adjacent=True,
|
61 |
).style(color_map={"": "blue", "-": "green"})
|
|
|
|
|
|
|
|
|
62 |
with gr.Row():
|
63 |
gr.Markdown("![visitor badge](https://visitor-badge.glitch.me/badge?page_id=cahya_indochat)")
|
64 |
|
|
|
2 |
import gradio as gr
|
3 |
from transformers import pipeline
|
4 |
import os
|
5 |
+
from mtranslate import translate
|
6 |
|
7 |
device = torch.cuda.current_device() if torch.cuda.is_available() else "cpu"
|
8 |
HF_AUTH_TOKEN = os.environ.get("HF_AUTH_TOKEN")
|
|
|
29 |
penalty_alpha=penalty_alpha)
|
30 |
answer = generated_text[0]["generated_text"]
|
31 |
answer_without_prompt = answer[len(prompt)+1:]
|
32 |
+
user_input_en = translate(user_input, "en", "id")
|
33 |
+
answer_without_prompt_en = translate(answer_without_prompt, "en", "id")
|
34 |
+
return [(f"{user_input} ", None), (answer_without_prompt, "")], \
|
35 |
+
[(f"{user_input_en} ", None), (answer_without_prompt_en, "")]
|
36 |
|
37 |
|
38 |
with gr.Blocks() as demo:
|
|
|
62 |
label="Answer",
|
63 |
combine_adjacent=True,
|
64 |
).style(color_map={"": "blue", "-": "green"})
|
65 |
+
generated_answer_en = gr.HighlightedText(
|
66 |
+
label="Translation",
|
67 |
+
combine_adjacent=True,
|
68 |
+
).style(color_map={"": "blue", "-": "green"})
|
69 |
with gr.Row():
|
70 |
gr.Markdown("![visitor badge](https://visitor-badge.glitch.me/badge?page_id=cahya_indochat)")
|
71 |
|
requirements.txt
CHANGED
@@ -1,2 +1,3 @@
|
|
1 |
torch
|
2 |
transformers
|
|
|
|
1 |
torch
|
2 |
transformers
|
3 |
+
mtranslate
|