Spaces:
Running
Running
Update app/webui/app.py
Browse files- app/webui/app.py +11 -2
app/webui/app.py
CHANGED
@@ -1,5 +1,6 @@
|
|
1 |
import sys
|
2 |
import os
|
|
|
3 |
|
4 |
# Add the project root to the Python path
|
5 |
project_root = os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..'))
|
@@ -11,6 +12,8 @@ from glob import glob
|
|
11 |
from app.webui.process import model_load, diff_texts, translator, translator_sec
|
12 |
from llama_index.core import SimpleDirectoryReader
|
13 |
|
|
|
|
|
14 |
def huanik(
|
15 |
endpoint: str,
|
16 |
model: str,
|
@@ -27,6 +30,7 @@ def huanik(
|
|
27 |
context_window: int,
|
28 |
num_output: int,
|
29 |
rpm: int,
|
|
|
30 |
):
|
31 |
|
32 |
if not source_text or source_lang == target_lang:
|
@@ -39,7 +43,7 @@ def huanik(
|
|
39 |
|
40 |
source_text = re.sub(r'(?m)^\s*$\n?', '', source_text)
|
41 |
|
42 |
-
if choice:
|
43 |
init_translation, reflect_translation, final_translation = translator_sec(
|
44 |
endpoint2=endpoint2,
|
45 |
model2=model2,
|
@@ -51,6 +55,7 @@ def huanik(
|
|
51 |
source_text=source_text,
|
52 |
country=country,
|
53 |
max_tokens=max_tokens,
|
|
|
54 |
)
|
55 |
|
56 |
else:
|
@@ -251,6 +256,10 @@ with gr.Blocks(theme="soft", css=CSS, fill_height=True) as demo:
|
|
251 |
value=60,
|
252 |
step=1,
|
253 |
)
|
|
|
|
|
|
|
|
|
254 |
with gr.Column(scale=4):
|
255 |
source_text = gr.Textbox(
|
256 |
label="Source Text",
|
@@ -282,7 +291,7 @@ with gr.Blocks(theme="soft", css=CSS, fill_height=True) as demo:
|
|
282 |
choice.select(fn=enable_sec, inputs=[choice], outputs=[AddEndpoint])
|
283 |
endpoint2.change(fn=update_model, inputs=[endpoint2], outputs=[model2])
|
284 |
|
285 |
-
start_ta = submit.click(fn=huanik, inputs=[endpoint, model, api_key, choice, endpoint2, model2, api_key2, source_lang, target_lang, source_text, country, max_tokens, context_window, num_output, rpm], outputs=[output_init, output_reflect, output_final, output_diff])
|
286 |
upload.upload(fn=read_doc, inputs = upload, outputs = source_text)
|
287 |
output_final.change(fn=export_txt, inputs=output_final, outputs=[export])
|
288 |
|
|
|
1 |
import sys
|
2 |
import os
|
3 |
+
from translatepy.translators.google import GoogleTranslate
|
4 |
|
5 |
# Add the project root to the Python path
|
6 |
project_root = os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..'))
|
|
|
12 |
from app.webui.process import model_load, diff_texts, translator, translator_sec
|
13 |
from llama_index.core import SimpleDirectoryReader
|
14 |
|
15 |
+
gtranslate = GoogleTranslate()
|
16 |
+
|
17 |
def huanik(
|
18 |
endpoint: str,
|
19 |
model: str,
|
|
|
30 |
context_window: int,
|
31 |
num_output: int,
|
32 |
rpm: int,
|
33 |
+
gt: bool,
|
34 |
):
|
35 |
|
36 |
if not source_text or source_lang == target_lang:
|
|
|
43 |
|
44 |
source_text = re.sub(r'(?m)^\s*$\n?', '', source_text)
|
45 |
|
46 |
+
if choice or gt:
|
47 |
init_translation, reflect_translation, final_translation = translator_sec(
|
48 |
endpoint2=endpoint2,
|
49 |
model2=model2,
|
|
|
55 |
source_text=source_text,
|
56 |
country=country,
|
57 |
max_tokens=max_tokens,
|
58 |
+
gt = gt,
|
59 |
)
|
60 |
|
61 |
else:
|
|
|
256 |
value=60,
|
257 |
step=1,
|
258 |
)
|
259 |
+
gt = gr.Checkbox(
|
260 |
+
label="Google Translate",
|
261 |
+
info="Use Google Translate as Init Translation"
|
262 |
+
)
|
263 |
with gr.Column(scale=4):
|
264 |
source_text = gr.Textbox(
|
265 |
label="Source Text",
|
|
|
291 |
choice.select(fn=enable_sec, inputs=[choice], outputs=[AddEndpoint])
|
292 |
endpoint2.change(fn=update_model, inputs=[endpoint2], outputs=[model2])
|
293 |
|
294 |
+
start_ta = submit.click(fn=huanik, inputs=[endpoint, model, api_key, choice, endpoint2, model2, api_key2, source_lang, target_lang, source_text, country, max_tokens, context_window, num_output, rpm, gt], outputs=[output_init, output_reflect, output_final, output_diff])
|
295 |
upload.upload(fn=read_doc, inputs = upload, outputs = source_text)
|
296 |
output_final.change(fn=export_txt, inputs=output_final, outputs=[export])
|
297 |
|