kambris commited on
Commit
b433e10
verified
1 Parent(s): 3f7b9ab

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +53 -29
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
- with gr.Blocks(title="English to Hebrew Converter") as demo:
 
 
 
 
 
 
 
 
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
- english_input = gr.Textbox(
221
- label="Enter English Text",
222
- lines=3,
223
- placeholder="Example: Hello, how are you?",
224
- show_copy_button=True
225
- )
 
 
226
 
227
  with gr.Column():
228
- hebrew_output = gr.Textbox(
229
- label="Hebrew Script",
230
- lines=3,
231
- rtl=True,
232
- show_copy_button=True
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
- show_copy_button=True
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
- manual_hebrew_input = gr.Textbox(
263
- label="Enter Hebrew text to translate",
264
- placeholder="讛讻谞住 讟拽住讟 讘注讘专讬转",
265
- rtl=True,
266
- lines=3,
267
- show_copy_button=True
268
- )
 
 
269
  manual_translate_btn = gr.Button("馃寪 Translate to English", variant="secondary")
270
 
271
  with gr.Column():
272
- manual_translation_output = gr.Textbox(
273
- label="English Translation",
274
- lines=3,
275
- show_copy_button=True
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],