Spaces:
Running
Running
Update app.py
Browse filesThis should remove that pesky white button to navigate to my profile
29 unmodified lines3031323334353637383940414243444546474849505152535455565758593637383960616263644546474849506566676869705771727322 unmodified lines9697988687888999100101102103951041051061071081011091101111121131071141151161 unmodified line1181191201151211221231241201251261231271281292 unmodified lines1321331341321351361371361381391401411411421431445 unmodified lines15015115215315315415521 unmodified lines17717817918118218318018118218370 unmodified lines25425525626025725825919 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): """ 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 combined horizontal text footprint grows too heavy, it dynamically scales down column capacity to prevent clipboard overflow. """ chunks = [] current_chunk = [] word_index = 0 while word_index < len(words_data): current_limit = (base_limit - 1) if len(chunks) == 0 else base_limit word = words_data[word_index] current_chunk.append(word) 22 unmodified lines return chunks
def 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 = 7 actual_slots_used = len(current_chunk) + (1 if is_first else 0) is_last_table = (idx == len(table_chunks) - 1) 2 unmodified lines current_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 lines t_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> <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-SCREEN 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 lines copy_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