Spaces:
Sleeping
Sleeping
Commit
·
99b3ef5
1
Parent(s):
2b9dfff
batch translation
Browse files
app.py
CHANGED
@@ -1,6 +1,6 @@
|
|
1 |
import logging
|
2 |
logger = logging.getLogger(__name__)
|
3 |
-
logging.basicConfig(level=logging.
|
4 |
|
5 |
import gradio as gr
|
6 |
import torah
|
@@ -216,7 +216,7 @@ with gr.Blocks() as app:
|
|
216 |
|
217 |
# --- Output Components ---
|
218 |
markdown_output = gr.Dataframe(label="ELS Results")
|
219 |
-
|
220 |
json_output = gr.Textbox(label="JSON Configuration Output")
|
221 |
json_download_btn = gr.Button("Prepare .json for Download")
|
222 |
json_file = gr.File(label="Download Config JSON", file_count="single")
|
@@ -253,10 +253,13 @@ with gr.Blocks() as app:
|
|
253 |
|
254 |
# --- Network Search Integration ---
|
255 |
updated_els_results = []
|
|
|
|
|
256 |
for result in els_results:
|
257 |
logger.debug(f"Processing result: {result}") # Add debugging log
|
258 |
try:
|
259 |
gematria_sum = calculate_gematria(result['result_text'])
|
|
|
260 |
except KeyError as e:
|
261 |
print(f"DEBUG: KeyError - Key '{e.args[0]}' not found in result. Skipping this result.")
|
262 |
continue
|
@@ -284,6 +287,14 @@ with gr.Blocks() as app:
|
|
284 |
result['Date Words'] = date_words_output
|
285 |
updated_els_results.append(result)
|
286 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
287 |
all_results.extend(updated_els_results)
|
288 |
current_date += delta
|
289 |
|
@@ -301,7 +312,7 @@ with gr.Blocks() as app:
|
|
301 |
search_phrase = f"{gematria_text}" # Removed date_words_output as it's now included in each result
|
302 |
config_json = generate_json_dump(1, 180, initial_step, rounds_combination, tlang, strip_spaces, strip_in_braces, strip_diacritics_chk, search_phrase, df, start_date, end_date)
|
303 |
|
304 |
-
return df, config_json
|
305 |
|
306 |
def handle_json_download(config_json, step, rounds_combination, strip_spaces, strip_in_braces, strip_diacritics_chk):
|
307 |
"""Handles the download of the JSON config file."""
|
@@ -318,7 +329,7 @@ with gr.Blocks() as app:
|
|
318 |
translate_btn.click(
|
319 |
perform_search,
|
320 |
inputs=[start_date, end_date, date_language_input, step, rounds_combination, tlang, strip_spaces, strip_in_braces, strip_diacritics_chk, merge_results_chk, include_torah_chk, include_bible_chk, include_quran_chk, gematria_text],
|
321 |
-
outputs=[markdown_output, json_output]
|
322 |
)
|
323 |
|
324 |
json_download_btn.click(
|
|
|
1 |
import logging
|
2 |
logger = logging.getLogger(__name__)
|
3 |
+
logging.basicConfig(level=logging.INFO)
|
4 |
|
5 |
import gradio as gr
|
6 |
import torah
|
|
|
216 |
|
217 |
# --- Output Components ---
|
218 |
markdown_output = gr.Dataframe(label="ELS Results")
|
219 |
+
most_frequent_phrase_output = gr.Textbox(label="Most Frequent Phrase in Network Search")
|
220 |
json_output = gr.Textbox(label="JSON Configuration Output")
|
221 |
json_download_btn = gr.Button("Prepare .json for Download")
|
222 |
json_file = gr.File(label="Download Config JSON", file_count="single")
|
|
|
253 |
|
254 |
# --- Network Search Integration ---
|
255 |
updated_els_results = []
|
256 |
+
texts_to_translate = [] # Collect texts for batch translation
|
257 |
+
|
258 |
for result in els_results:
|
259 |
logger.debug(f"Processing result: {result}") # Add debugging log
|
260 |
try:
|
261 |
gematria_sum = calculate_gematria(result['result_text'])
|
262 |
+
texts_to_translate.append(result['result_text']) # Add text for translation
|
263 |
except KeyError as e:
|
264 |
print(f"DEBUG: KeyError - Key '{e.args[0]}' not found in result. Skipping this result.")
|
265 |
continue
|
|
|
287 |
result['Date Words'] = date_words_output
|
288 |
updated_els_results.append(result)
|
289 |
|
290 |
+
# --- Batch Translation ---
|
291 |
+
translator = GoogleTranslator(source='auto', target=tlang)
|
292 |
+
translated_texts = translator.translate_batch(texts_to_translate)
|
293 |
+
|
294 |
+
# --- Add Translated Texts to Results ---
|
295 |
+
for i, result in enumerate(updated_els_results):
|
296 |
+
result['Translated Text'] = translated_texts[i]
|
297 |
+
|
298 |
all_results.extend(updated_els_results)
|
299 |
current_date += delta
|
300 |
|
|
|
312 |
search_phrase = f"{gematria_text}" # Removed date_words_output as it's now included in each result
|
313 |
config_json = generate_json_dump(1, 180, initial_step, rounds_combination, tlang, strip_spaces, strip_in_braces, strip_diacritics_chk, search_phrase, df, start_date, end_date)
|
314 |
|
315 |
+
return df, most_frequent_phrase, config_json
|
316 |
|
317 |
def handle_json_download(config_json, step, rounds_combination, strip_spaces, strip_in_braces, strip_diacritics_chk):
|
318 |
"""Handles the download of the JSON config file."""
|
|
|
329 |
translate_btn.click(
|
330 |
perform_search,
|
331 |
inputs=[start_date, end_date, date_language_input, step, rounds_combination, tlang, strip_spaces, strip_in_braces, strip_diacritics_chk, merge_results_chk, include_torah_chk, include_bible_chk, include_quran_chk, gematria_text],
|
332 |
+
outputs=[markdown_output, most_frequent_phrase_output, json_output]
|
333 |
)
|
334 |
|
335 |
json_download_btn.click(
|