Spaces:
Running
Running
Update app.py
Browse filesThis should remove that pesky white button to navigate to my profile
29 unmodified lines3031323334353637383940414243444546474849505152535455565758596022 unmodified lines83848586878889909192939495969798991001011021031041051061071081091101 unmodified line1121131141151161171181191201211221231241251262 unmodified lines1291301311321331341351361371381391401411421431445 unmodified lines15015115215315415515621 unmodified lines17817918018118218318418518670 unmodified lines25725825926026126226319 unmodified lines28328428528628728829 unmodified lines}"""MODEL_NAME = "gemini-3.1-flash-lite"def clean_hyphens_for_docs(text_string):"""Swaps standard hyphens with HTML non-breaking hyphens.This freezes compounds so Google Docs cannot split them across lines."""if not text_string:return ""return str(text_string).replace("-", "‑")def calculate_dynamic_chunks(words_data, base_limit=7):"""Dynamic Fixed-Grid Hybrid Engine.Inspects the text footprint of each word cell. If a row's combinedhorizontal text footprint grows too heavy, it dynamically scalesdown column capacity to prevent clipboard overflow."""chunks = []current_chunk = []word_index = 0while word_index < len(words_data):current_limit = (base_limit - 1) if len(chunks) == 0 else base_limitword = words_data[word_index]current_chunk.append(word)22 unmodified linesreturn chunksdef build_html_tables(manuscript, reference, words_data):"""Native Python engine to assemble right-to-left interlinear grids.Applies non-breaking hyphen locks to stabilize clipboard styling."""table_style = ("width: 7in !important; border-collapse: collapse; margin-bottom: 4pt; ""direction: rtl; border: 1pt solid #b7b7b7; background-color: #ffffff; ""line-height: 1.0 !important; height: auto;")hebrew_cell_style = ("font-family: 'Times New Roman', serif !important; font-size: 24px !important; color: #000000 !important; ""text-align: right; vertical-align: middle; border: 1pt solid #b7b7b7; ""padding: 5pt; height: auto; white-space: nowrap;")english_cell_style = ("font-family: Arial, sans-serif !important; font-size: 14.6667px !important; color: #000000 !important; ""border: 1pt solid #b7b7b7; padding: 5pt; text-align: center; ""vertical-align: top; height: auto; line-height: 1.0 !important;")heading_cell_style = ("font-family: 'Times New Roman', serif !important; font-size: 18.6667px !important; color: #000000 !important; ""text-align: center; vertical-align: middle; border: 1pt solid #b7b7b7; "1 unmodified line)html_output = ['<div id="table-payload" class="white-canvas" style="background-color: #ffffff; padding: 20px; border-radius: 8px; display: inline-block; width: 100%; box-sizing: border-box;">']table_chunks = calculate_dynamic_chunks(words_data, base_limit=7)for idx, current_chunk in enumerate(table_chunks):html_output.append(f'<table style="{table_style}">')is_first = (idx == 0)target_total_cols = 7actual_slots_used = len(current_chunk) + (1 if is_first else 0)is_last_table = (idx == len(table_chunks) - 1)2 unmodified linescurrent_chunk.append({"hebrew": " ", "transliteration": "", "translation": "", "morphology": ""})actual_slots_used += 1# --- ROW 1: Hebrew Text / Reference ---html_output.append(' <tr style="height: auto; line-height: 1.0 !important;">')if is_first:html_output.append(f' <td style="{heading_cell_style}">{reference}</td>')for word in current_chunk:html_output.append(f' <td style="{hebrew_cell_style}">{word.get("hebrew", " ")}</td>')html_output.append(' </tr>')# --- ROW 2: English Structural Stack ---html_output.append(' <tr style="height: auto; line-height: 1.0 !important;">')if is_first:formatted_manuscript = manuscript.replace(" ", "<br>") if " " in manuscript else manuscript5 unmodified linest_lit = clean_hyphens_for_docs(word.get("transliteration", ""))t_lat = clean_hyphens_for_docs(word.get("translation", ""))morph = clean_hyphens_for_docs(word.get("morphology", ""))content = f'{t_lit}<br>{t_lat}<br>{morph}'html_output.append(f' <td class="english-cell" style="{english_cell_style}">{content}</td>')else:21 unmodified lines<div class="progress-container"><img src="{gif_url}" width="40" height="40" style="margin: 0 auto 10px auto; display: block;" /><p style="color: #ff6600; font-weight: bold; font-family: Arial; margin: 0 0 5px 0;">โณ Current Step: {step_text}...</p><p style="color: #ffffff; font-family: monospace; font-size: 14px; margin: 0;">Elapsed Time: {elapsed}s</p></div>"""70 unmodified lineswith gr.Blocks(css=custom_css) as demo:gr.Markdown("# Hebrew Interlinear Table Generator")# SHORT, CLEAN USER KEY INSTRUCTIONS ON-SCREENwith gr.Accordion("๐ How to get your free Gemini API Key", open=False):gr.Markdown("1. Go to [aistudio.google.com](https://aistudio.google.com/).\n"19 unmodified linescopy_btn = gr.Button("๐ Copy for Google Docs", variant="secondary", visible=False)output_html = gr.HTML(label="Generated Table")submit_btn.click(fn=generate_table_code, inputs=[api_key_input, manuscript_input, book_input, chapter_input, verse_input, text_string_input], outputs=[status_panel, output_html, copy_btn], show_progress="hidden")clear_btn.click(fn=None, inputs=[], outputs=[text_string_input], js="() => ''")copy_btn.click(fn=None, js=copy_js)29 unmodified lines303132333435363738394041424344454647484950515253545556575859606162636465666768697071727322 unmodified lines969798991001011021031041051061071081091101111121131141151161 unmodified line1181191201211221231241251261271281292 unmodified lines1321331341351361371381391401411421431445 unmodified lines15015115215315415521 unmodified lines17717817918018118218370 unmodified lines25425525625725825919 unmodified lines27928028128228328428528629 unmodified lines}"""# JAVASCRIPT MATRIX TO FORCIBLY STRIP OUT THE HUGGING FACE HEADER AND WHITE BUTTONforce_clean_layout_js = """function() {const removeHeaderBlock = () => {const hfHeader = document.querySelector('header');const spaceHeader = document.querySelector('div[class*="space-header"]');if (hfHeader) hfHeader.remove();if (spaceHeader) spaceHeader.remove();document.querySelectorAll('div').forEach(div => {if (window.getComputedStyle(div).position === 'fixed' && div.innerHTML.includes('fizzickschick')) {div.remove();}});};removeHeaderBlock();setTimeout(removeHeaderBlock, 500);setTimeout(removeHeaderBlock, 1500);setTimeout(removeHeaderBlock, 3000);}"""MODEL_NAME = "gemini-3.1-flash-lite"def clean_hyphens_for_docs(text_string):if not text_string:return ""return str(text_string).replace("-", "‑")def calculate_dynamic_chunks(words_data, base_limit=7):chunks = []current_chunk = []word_index = 0while word_index < len(words_data):current_limit = (base_limit - 1) if len(chunks) == 0 else base_limitword = words_data[word_index]current_chunk.append(word)22 unmodified linesreturn chunksdef build_html_tables(manuscript, reference, words_data):table_style = ("width: 7in !important; border-collapse: collapse; margin-bottom: 4pt; ""direction: rtl; border: 1pt solid #b7b7b7; background-color: #ffffff; ""line-height: 1.0 !important; height: auto;")hebrew_cell_style = ("font-family: 'Times New Roman', serif !important; font-size: 24px !important; color: #000000 !important; ""text-align: right; vertical-align: middle; border: 1pt solid #b7b7b7; ""padding: 5pt; height: auto; white-space: nowrap;")english_cell_style = ("font-family: Arial, sans-serif !important; font-size: 14.6667px !important; color: #000000 !important; ""border: 1pt solid #b7b7b7; padding: 5pt; text-align: center; ""vertical-align: top; height: auto; line-height: 1.0 !important;")heading_cell_style = ("font-family: 'Times New Roman', serif !important; font-size: 18.6667px !important; color: #000000 !important; ""text-align: center; vertical-align: middle; border: 1pt solid #b7b7b7; "1 unmodified line)html_output = ['<div id="table-payload" class="white-canvas" style="background-color: #ffffff; padding: 20px; border-radius: 8px; display: inline-block; width: 100%; box-sizing: border-box;">']table_chunks = calculate_dynamic_chunks(words_data, base_limit=7)for idx, current_chunk in enumerate(table_chunks):html_output.append(f'<table style="{table_style}">')is_first = (idx == 0)target_total_cols = 7actual_slots_used = len(current_chunk) + (1 if is_first else 0)is_last_table = (idx == len(table_chunks) - 1)2 unmodified linescurrent_chunk.append({"hebrew": " ", "transliteration": "", "translation": "", "morphology": ""})actual_slots_used += 1html_output.append(' <tr style="height: auto; line-height: 1.0 !important;">')if is_first:html_output.append(f' <td style="{heading_cell_style}">{reference}</td>')for word in current_chunk:html_output.append(f' <td style="{hebrew_cell_style}">{word.get("hebrew", " ")}</td>')html_output.append(' </tr>')html_output.append(' <tr style="height: auto; line-height: 1.0 !important;">')if is_first:formatted_manuscript = manuscript.replace(" ", "<br>") if " " in manuscript else manuscript5 unmodified linest_lit = clean_hyphens_for_docs(word.get("transliteration", ""))t_lat = clean_hyphens_for_docs(word.get("translation", ""))morph = clean_hyphens_for_docs(word.get("morphology", ""))content = f'{t_lit}<br>{t_lat}<br>{morph}'html_output.append(f' <td class="english-cell" style="{english_cell_style}">{content}</td>')else:21 unmodified lines<div class="progress-container"><img src="{gif_url}" width="40" height="40" style="margin: 0 auto 10px auto; display: block;" /><p style="color: #ff6600; font-weight: bold; font-family: Arial; margin: 0 0 5px 0;">โณ Current Step: {step_text}...</p><p style="color: #ffffff; font-family: monospace; font-size: 14px; margin: 0;">Elapsed Time: {elapsed}s</p></div>"""70 unmodified lineswith gr.Blocks(css=custom_css) as demo:gr.Markdown("# Hebrew Interlinear Table Generator")with gr.Accordion("๐ How to get your free Gemini API Key", open=False):gr.Markdown("1. Go to [aistudio.google.com](https://aistudio.google.com/).\n"19 unmodified linescopy_btn = gr.Button("๐ Copy for Google Docs", variant="secondary", visible=False)output_html = gr.HTML(label="Generated Table")demo.load(fn=None, inputs=None, outputs=None, js=force_clean_layout_js)submit_btn.click(fn=generate_table_code, inputs=[api_key_input, manuscript_input, book_input, chapter_input, verse_input, text_string_input], outputs=[status_panel, output_html, copy_btn], show_progress="hidden")clear_btn.click(fn=None, inputs=[], outputs=[text_string_input], js="() => ''")copy_btn.click(fn=None, js=copy_js)
app.py+27-29