Update app.py
Browse files
app.py
CHANGED
|
@@ -157,8 +157,16 @@ def full_process_with_translation(english_text, mode):
|
|
| 157 |
translation_result = translate_multiple_words(hebrew_text)
|
| 158 |
return hebrew_text, hebrew_audio, translation_result
|
| 159 |
|
| 160 |
-
# Create Gradio interface
|
| 161 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 162 |
gr.Markdown("## 馃摑 English-to-Hebrew Converter with Google Translate")
|
| 163 |
gr.Markdown("Enter English text to convert to Hebrew script, generate audio, and get translations using Google Translate.")
|
| 164 |
|
|
@@ -214,32 +222,37 @@ with gr.Blocks(title="English to Hebrew Converter") as demo:
|
|
| 214 |
label="Conversion Mode"
|
| 215 |
)
|
| 216 |
|
| 217 |
-
# Main interface
|
| 218 |
with gr.Row():
|
| 219 |
with gr.Column():
|
| 220 |
-
|
| 221 |
-
|
| 222 |
-
|
| 223 |
-
|
| 224 |
-
|
| 225 |
-
|
|
|
|
|
|
|
| 226 |
|
| 227 |
with gr.Column():
|
| 228 |
-
|
| 229 |
-
|
| 230 |
-
|
| 231 |
-
|
| 232 |
-
|
| 233 |
-
|
|
|
|
|
|
|
| 234 |
|
| 235 |
-
# Translation output
|
| 236 |
with gr.Row():
|
| 237 |
translation_output = gr.Textbox(
|
| 238 |
label="Word-by-Word Translation Results",
|
| 239 |
lines=3,
|
| 240 |
placeholder="Translations will appear here...",
|
| 241 |
-
|
| 242 |
)
|
|
|
|
| 243 |
|
| 244 |
# Button controls
|
| 245 |
with gr.Row():
|
|
@@ -259,21 +272,25 @@ with gr.Blocks(title="English to Hebrew Converter") as demo:
|
|
| 259 |
with gr.Accordion("馃攳 Manual Hebrew to English Translation", open=False):
|
| 260 |
with gr.Row():
|
| 261 |
with gr.Column():
|
| 262 |
-
|
| 263 |
-
|
| 264 |
-
|
| 265 |
-
|
| 266 |
-
|
| 267 |
-
|
| 268 |
-
|
|
|
|
|
|
|
| 269 |
manual_translate_btn = gr.Button("馃寪 Translate to English", variant="secondary")
|
| 270 |
|
| 271 |
with gr.Column():
|
| 272 |
-
|
| 273 |
-
|
| 274 |
-
|
| 275 |
-
|
| 276 |
-
|
|
|
|
|
|
|
| 277 |
|
| 278 |
# Event handlers
|
| 279 |
def process_convert(text, mode):
|
|
@@ -282,6 +299,13 @@ with gr.Blocks(title="English to Hebrew Converter") as demo:
|
|
| 282 |
else:
|
| 283 |
return google_translate_hebrew(text)
|
| 284 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 285 |
convert_btn.click(
|
| 286 |
fn=process_convert,
|
| 287 |
inputs=[english_input, mode],
|
|
|
|
| 157 |
translation_result = translate_multiple_words(hebrew_text)
|
| 158 |
return hebrew_text, hebrew_audio, translation_result
|
| 159 |
|
| 160 |
+
# Create Gradio interface with custom CSS for copy buttons
|
| 161 |
+
css = """
|
| 162 |
+
.copy-btn {
|
| 163 |
+
font-size: 12px !important;
|
| 164 |
+
padding: 4px 8px !important;
|
| 165 |
+
min-width: 60px !important;
|
| 166 |
+
}
|
| 167 |
+
"""
|
| 168 |
+
|
| 169 |
+
with gr.Blocks(title="English to Hebrew Converter", css=css) as demo:
|
| 170 |
gr.Markdown("## 馃摑 English-to-Hebrew Converter with Google Translate")
|
| 171 |
gr.Markdown("Enter English text to convert to Hebrew script, generate audio, and get translations using Google Translate.")
|
| 172 |
|
|
|
|
| 222 |
label="Conversion Mode"
|
| 223 |
)
|
| 224 |
|
| 225 |
+
# Main interface with copy buttons
|
| 226 |
with gr.Row():
|
| 227 |
with gr.Column():
|
| 228 |
+
with gr.Row():
|
| 229 |
+
english_input = gr.Textbox(
|
| 230 |
+
label="Enter English Text",
|
| 231 |
+
lines=3,
|
| 232 |
+
placeholder="Example: Hello, how are you?",
|
| 233 |
+
scale=5
|
| 234 |
+
)
|
| 235 |
+
copy_english_btn = gr.Button("馃搵 Copy", size="sm", scale=1, elem_classes="copy-btn")
|
| 236 |
|
| 237 |
with gr.Column():
|
| 238 |
+
with gr.Row():
|
| 239 |
+
hebrew_output = gr.Textbox(
|
| 240 |
+
label="Hebrew Script",
|
| 241 |
+
lines=3,
|
| 242 |
+
rtl=True,
|
| 243 |
+
scale=5
|
| 244 |
+
)
|
| 245 |
+
copy_hebrew_btn = gr.Button("馃搵 Copy", size="sm", scale=1, elem_classes="copy-btn")
|
| 246 |
|
| 247 |
+
# Translation output with copy button
|
| 248 |
with gr.Row():
|
| 249 |
translation_output = gr.Textbox(
|
| 250 |
label="Word-by-Word Translation Results",
|
| 251 |
lines=3,
|
| 252 |
placeholder="Translations will appear here...",
|
| 253 |
+
scale=5
|
| 254 |
)
|
| 255 |
+
copy_translation_btn = gr.Button("馃搵 Copy", size="sm", scale=1, elem_classes="copy-btn")
|
| 256 |
|
| 257 |
# Button controls
|
| 258 |
with gr.Row():
|
|
|
|
| 272 |
with gr.Accordion("馃攳 Manual Hebrew to English Translation", open=False):
|
| 273 |
with gr.Row():
|
| 274 |
with gr.Column():
|
| 275 |
+
with gr.Row():
|
| 276 |
+
manual_hebrew_input = gr.Textbox(
|
| 277 |
+
label="Enter Hebrew text to translate",
|
| 278 |
+
placeholder="讛讻谞住 讟拽住讟 讘注讘专讬转",
|
| 279 |
+
rtl=True,
|
| 280 |
+
lines=3,
|
| 281 |
+
scale=5
|
| 282 |
+
)
|
| 283 |
+
copy_manual_hebrew_btn = gr.Button("馃搵 Copy", size="sm", scale=1, elem_classes="copy-btn")
|
| 284 |
manual_translate_btn = gr.Button("馃寪 Translate to English", variant="secondary")
|
| 285 |
|
| 286 |
with gr.Column():
|
| 287 |
+
with gr.Row():
|
| 288 |
+
manual_translation_output = gr.Textbox(
|
| 289 |
+
label="English Translation",
|
| 290 |
+
lines=3,
|
| 291 |
+
scale=5
|
| 292 |
+
)
|
| 293 |
+
copy_manual_translation_btn = gr.Button("馃搵 Copy", size="sm", scale=1, elem_classes="copy-btn")
|
| 294 |
|
| 295 |
# Event handlers
|
| 296 |
def process_convert(text, mode):
|
|
|
|
| 299 |
else:
|
| 300 |
return google_translate_hebrew(text)
|
| 301 |
|
| 302 |
+
# Copy button functions
|
| 303 |
+
copy_english_btn.click(fn=lambda x: x, inputs=english_input, outputs=english_input, js="(x) => {navigator.clipboard.writeText(x); return x;}")
|
| 304 |
+
copy_hebrew_btn.click(fn=lambda x: x, inputs=hebrew_output, outputs=hebrew_output, js="(x) => {navigator.clipboard.writeText(x); return x;}")
|
| 305 |
+
copy_translation_btn.click(fn=lambda x: x, inputs=translation_output, outputs=translation_output, js="(x) => {navigator.clipboard.writeText(x); return x;}")
|
| 306 |
+
copy_manual_hebrew_btn.click(fn=lambda x: x, inputs=manual_hebrew_input, outputs=manual_hebrew_input, js="(x) => {navigator.clipboard.writeText(x); return x;}")
|
| 307 |
+
copy_manual_translation_btn.click(fn=lambda x: x, inputs=manual_translation_output, outputs=manual_translation_output, js="(x) => {navigator.clipboard.writeText(x); return x;}")
|
| 308 |
+
|
| 309 |
convert_btn.click(
|
| 310 |
fn=process_convert,
|
| 311 |
inputs=[english_input, mode],
|