Spaces:
Sleeping
Sleeping
fix: warn if newlines do not match
Browse files
app.py
CHANGED
@@ -82,6 +82,12 @@ def fill_scaffold(filepath: str, translated: str) -> list[str]:
|
|
82 |
''.join(translated[i*3:i*3+3])
|
83 |
for i in range(len(translated) // 3)
|
84 |
]).split('\n\n')
|
|
|
|
|
|
|
|
|
|
|
|
|
85 |
translated_doc = scaffold.safe_substitute({
|
86 |
f"hf_i18n_placeholder{i}": text
|
87 |
for i, text in enumerate(translated)
|
@@ -165,7 +171,7 @@ with demo:
|
|
165 |
prompt_button = gr.Button("Show Full Prompt", variant="primary")
|
166 |
# TODO: add with_prompt_checkbox so people can freely use other services such as DeepL or Papago.
|
167 |
gr.Markdown("1. Copy with the button right-hand side and paste into [chat.openai.com](https://chat.openai.com).")
|
168 |
-
prompt_output = gr.Textbox(label="Full Prompt", lines=3
|
169 |
# TODO: add check for segments, indicating whether user should add or remove new lines from their input. (gr.Row)
|
170 |
gr.Markdown("2. After getting the complete translation, remove randomly inserted newlines on your favorite text editor and paste the result below.")
|
171 |
ui_translated_input = gr.inputs.Textbox(label="Cleaned ChatGPT initial translation")
|
@@ -175,8 +181,8 @@ with demo:
|
|
175 |
api_key_input = gr.inputs.Textbox(label="Your OpenAI API Key")
|
176 |
api_call_button = gr.Button("Translate (Call API)", variant="primary")
|
177 |
with gr.Row():
|
178 |
-
content_output = gr.Textbox(label="Original content"
|
179 |
-
final_output = gr.Textbox(label="Draft for review"
|
180 |
|
181 |
prompt_button.click(get_full_prompt, inputs=[language_input, filepath_input], outputs=prompt_output)
|
182 |
fill_button.click(fill_scaffold, inputs=[filepath_input, ui_translated_input], outputs=[content_output, final_output])
|
|
|
82 |
''.join(translated[i*3:i*3+3])
|
83 |
for i in range(len(translated) // 3)
|
84 |
]).split('\n\n')
|
85 |
+
if (newlines := scaffold.template.count('$hf_i18n_placeholder') - len(translated)):
|
86 |
+
return [
|
87 |
+
content,
|
88 |
+
f"Please {'recover' if newlines > 0 else 'remove'} "
|
89 |
+
f"{abs(newlines)} incorrectly inserted double newlines."
|
90 |
+
]
|
91 |
translated_doc = scaffold.safe_substitute({
|
92 |
f"hf_i18n_placeholder{i}": text
|
93 |
for i, text in enumerate(translated)
|
|
|
171 |
prompt_button = gr.Button("Show Full Prompt", variant="primary")
|
172 |
# TODO: add with_prompt_checkbox so people can freely use other services such as DeepL or Papago.
|
173 |
gr.Markdown("1. Copy with the button right-hand side and paste into [chat.openai.com](https://chat.openai.com).")
|
174 |
+
prompt_output = gr.Textbox(label="Full Prompt", lines=3).style(show_copy_button=True)
|
175 |
# TODO: add check for segments, indicating whether user should add or remove new lines from their input. (gr.Row)
|
176 |
gr.Markdown("2. After getting the complete translation, remove randomly inserted newlines on your favorite text editor and paste the result below.")
|
177 |
ui_translated_input = gr.inputs.Textbox(label="Cleaned ChatGPT initial translation")
|
|
|
181 |
api_key_input = gr.inputs.Textbox(label="Your OpenAI API Key")
|
182 |
api_call_button = gr.Button("Translate (Call API)", variant="primary")
|
183 |
with gr.Row():
|
184 |
+
content_output = gr.Textbox(label="Original content").style(show_copy_button=True)
|
185 |
+
final_output = gr.Textbox(label="Draft for review").style(show_copy_button=True)
|
186 |
|
187 |
prompt_button.click(get_full_prompt, inputs=[language_input, filepath_input], outputs=prompt_output)
|
188 |
fill_button.click(fill_scaffold, inputs=[filepath_input, ui_translated_input], outputs=[content_output, final_output])
|