Spaces:
Running
Running
Update app.py
Browse filesfix after unexplained syntax overnight even though it was working fine
Once I get this just right I'll be working on the interface
110 unmodified lines11111211311411511611711811912012111 unmodified lines1331341351361371381391401411421431441451464 unmodified lines15115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020133 unmodified lines23523623723823924024139 unmodified lines28128228328428528628714 unmodified lines302303304305306307308110 unmodified linesreturn 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 = 6 if len(chunks) == 0 else 7word = words_data[word_index]11 unmodified linesreturn chunksdef build_html_tables(manuscript, reference, words_data):total_table_width_in = 7.0total_slots = 7# Embedded align="center" ensures Google Docs centers the table geometry upon pastingtable_style = (f"width: {total_table_width_in}in !important; min-width: {total_table_width_in}in !important; "f"max-width: {total_table_width_in}in !important; table-layout: fixed !important; border-collapse: collapse; ""margin-bottom: 4pt; direction: rtl; border: 1pt solid #b7b7b7; background-color: #ffffff; ""line-height: 1.0 !important; height: auto; margin-left: auto !important; margin-right: auto !important;")4 unmodified linesis_first = (idx == 0)is_last_table = (idx == len(table_chunks) - 1)# Build character scoring arrays to execute proper dynamic logic adjustmentsslot_weights = []if is_first:ref_len = max(len(reference), len(manuscript))slot_weights.append(ref_len)for word in current_chunk:# Score scaling factor maps visual space accuratelyw_hebrew = len(word.get("hebrew", "")) * 1.6w_translit = len(word.get("transliteration", ""))w_trans = len(word.get("translation", ""))w_morph = len(word.get("morphology", ""))max_text_footprint = max(w_hebrew, w_translit, w_trans, w_morph)slot_weights.append(max_text_footprint if max_text_footprint > 0 else 6)if is_last_table:while (len(current_chunk) + (1 if is_first else 0)) < total_slots:current_chunk.append({"hebrew": " ", "transliteration": " ", "translation": " ", "morphology": " "})slot_weights.append(6)# --- RUN 3-STEP BALANCING MATRIX LOGIC ---total_weight_score = sum(slot_weights)calculated_widths = []for w in slot_weights:allocated_width = (w / total_weight_score) * total_table_width_in# Guard constraint protects narrow columns from causing text wrap glitchesif allocated_width < 0.75:allocated_width = 0.75calculated_widths.append(round(allocated_width, 3))remainder_adjustment = round(total_table_width_in - sum(calculated_widths), 3)if remainder_adjustment != 0 and len(calculated_widths) > 0:calculated_widths[-1] = round(calculated_widths[-1] + remainder_adjustment, 3)# The align="center" attribute is included here for native Google Docs pasting supporthtml_output.append(f'<table style="{table_style}" align="center">')html_output.append(' <colgroup>')for c_width in calculated_widths:html_output.append(f' <col style="width: {c_width}in !important; min-width: {c_width}in !important; max-width: {c_width}in !important;">')html_output.append(' </colgroup>')# LOCKED REQUIREMENT: Symmetrical 0.069in cell padding across all four boundaries + suppressed text wrapbase_cell = "border: 1pt solid #b7b7b7; padding: 0.069in !important; height: auto; overflow: hidden; white-space: nowrap !important; box-sizing: border-box !important;"hebrew_cell_style = f"font-family: 'Times New Roman', serif !important; font-size: 24px !important; color: #000000 !important; text-align: right; vertical-align: middle; {base_cell}"english_cell_style = f"font-family: Arial, sans-serif !important; font-size: 14.6667px !important; color: #000000 !important; text-align: center; vertical-align: top; line-height: 1.0 !important; {base_cell}"33 unmodified linesdef generate_table_code(api_key, manuscript_name, book, chapter, verse, text_string):if not api_key:gr.Warning("API Key missing.")yield gr.update(visible=True, value="<p style='color:red; text-align:center;'>❌ Error: Please enter your Gemini API key.</p>"), "", gr.update(visible=False)return39 unmodified linesCRITICAL LINGUISTIC SCHEMA RULES:1. When parsing the definite direct object marker 'אֶת' or 'אֶת־', always set its translation parameter exactly to a single hyphen "-" and its morphology parameter exactly to "ddom".2. For any other standard grammatical particle occurrences, always abbreviate the word 'particle' down to "part".3. Never use the terminology \"Qal\". For the Pa'al binyan stem, always specify it exactly as "Pa'al" (e.g., 'v Pa'al imperf 3ms').CRITICAL TRANSLITERATION MAPPINGS:- VOCAL_SHEVA: "ᵉ", HATAF_SEGOL: "e", HATAF_PATAH: "a", HATAF_QAMATS: "o", HIRIQ: "i", TSERE: "ey", SEGOL: "e", PATAH: "a", QAMATS: "a", HOLAM: "o", QUBUTS: "oo", MAQAF: "-", PASEQ: "׀", SOF_PASUQ: "."14 unmodified linesyield gr.update(visible=True, value=f"<p style='color:red; text-align:center;'>❌ API Error: {str(e)}</p>"), "", gr.update(visible=False)returnyield gr.update(visible=True, value=status_html("Executing 3-Step Column Balance Layout Matrix")), "", gr.update(visible=False)try:final_table_html = build_html_tables(manuscript_name, reference_header, raw_json_data)110 unmodified lines11111211311411511611711811912012112212311 unmodified lines1351361371381391401411421431441454 unmodified lines15015115215315415515615715815916016116216316416516616716816917017117217333 unmodified lines20720820921021121239 unmodified lines25225325425525625725814 unmodified lines273274275276277278279110 unmodified linesreturn str(text_string).replace("-", "‑")def calculate_dynamic_chunks(words_data, base_limit=7):"""Splits words into clean layout chunks of up to 7 slots."""chunks = []current_chunk = []word_index = 0while word_index < len(words_data):# First table row needs 1 slot for reference block + 6 slots for words = 7 total columnscurrent_limit = 6 if len(chunks) == 0 else 7word = words_data[word_index]11 unmodified linesreturn chunksdef build_html_tables(manuscript, reference, words_data):# Rule: Table is explicitly locked to 7.0 inches wide overalltable_style = ("width: 7.0in !important; min-width: 7.0in !important; max-width: 7.0in !important; ""table-layout: fixed !important; border-collapse: collapse; margin-bottom: 4pt; ""direction: rtl; border: 1pt solid #b7b7b7; background-color: #ffffff; ""line-height: 1.0 !important; height: auto; margin-left: auto !important; margin-right: auto !important;")4 unmodified linesis_first = (idx == 0)is_last_table = (idx == len(table_chunks) - 1)allocated_slots = len(current_chunk) + (1 if is_first else 0)# Symmetrical filler keeps trailing short tables exactly 7 columns wideif is_last_table:while allocated_slots < 7:current_chunk.append({"hebrew": " ", "transliteration": " ", "translation": " ", "morphology": " "})allocated_slots += 1# Native align="center" makes Google Docs automatically center the table on pastehtml_output.append(f'<table style="{table_style}" align="center">')# Rule: Every column is locked to exactly 1.0 inch wide to guarantee a 7.0 inch total widthhtml_output.append(' <colgroup>')for _ in range(7):html_output.append(' <col style="width: 1.0in !important; min-width: 1.0in !important; max-width: 1.0in !important;">')html_output.append(' </colgroup>')# Rule: Exact 0.069in cell padding on all 4 sides + word wrap strictly disabled (nowrap)base_cell = "border: 1pt solid #b7b7b7; padding: 0.069in !important; height: auto; overflow: hidden; white-space: nowrap !important; box-sizing: border-box !important;"hebrew_cell_style = f"font-family: 'Times New Roman', serif !important; font-size: 24px !important; color: #000000 !important; text-align: right; vertical-align: middle; {base_cell}"english_cell_style = f"font-family: Arial, sans-serif !important; font-size: 14.6667px !important; color: #000000 !important; text-align: center; vertical-align: top; line-height: 1.0 !important; {base_cell}"33 unmodified linesdef generate_table_code(api_key, manuscript_name, book, chapter, verse, text_string):if not api_key:yield gr.update(visible=True, value="<p style='color:red; text-align:center;'>❌ Error: Please enter your Gemini API key.</p>"), "", gr.update(visible=False)return39 unmodified linesCRITICAL LINGUISTIC SCHEMA RULES:1. When parsing the definite direct object marker 'אֶת' or 'אֶת־', always set its translation parameter exactly to a single hyphen "-" and its morphology parameter exactly to "ddom".2. For any other standard grammatical particle occurrences, always abbreviate the word 'particle' down to "part".3. Never use the terminology "Qal". For the Pa'al binyan stem, always specify it exactly as "Pa'al" (e.g., 'v Pa'al imperf 3ms').CRITICAL TRANSLITERATION MAPPINGS:- VOCAL_SHEVA: "ᵉ", HATAF_SEGOL: "e", HATAF_PATAH: "a", HATAF_QAMATS: "o", HIRIQ: "i", TSERE: "ey", SEGOL: "e", PATAH: "a", QAMATS: "a", HOLAM: "o", QUBUTS: "oo", MAQAF: "-", PASEQ: "׀", SOF_PASUQ: "."14 unmodified linesyield gr.update(visible=True, value=f"<p style='color:red; text-align:center;'>❌ API Error: {str(e)}</p>"), "", gr.update(visible=False)returnyield gr.update(visible=True, value=status_html("Assembling Fixed 7-Inch Symmetrical Grid Blueprint")), "", gr.update(visible=False)try:final_table_html = build_html_tables(manuscript_name, reference_header, raw_json_data)
app.py+17-46