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 lines11111211311411511611711811912012112212311 unmodified lines1351361371361371381391381391411421431401411421431441454 unmodified lines15015115215415515315415715815916016116216316416516616716816917015515617215715817417517617717817918018118218318418518618718815916019016116216316416519419516616716816919817017117217333 unmodified lines20720820923821021121239 unmodified lines25225325428425525625725814 unmodified lines273274275305276277278279110 unmodified lines return 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 = 0 while word_index < len(words_data): # First table row needs 1 slot for reference block + 6 slots for words = 7 total columns current_limit = 6 if len(chunks) == 0 else 7 word = words_data[word_index]11 unmodified lines return chunks
def build_html_tables(manuscript, reference, words_data): total_table_width_in = 7.0 total_slots = 7 # Embedded align="center" ensures Google Docs centers the table geometry upon pasting # Rule: Table is explicitly locked to 7.0 inches wide overall table_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; " "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 lines is_first = (idx == 0) is_last_table = (idx == len(table_chunks) - 1) # Build character scoring arrays to execute proper dynamic logic adjustments slot_weights = [] allocated_slots = len(current_chunk) + (1 if is_first else 0) 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 accurately w_hebrew = len(word.get("hebrew", "")) * 1.6 w_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) # Symmetrical filler keeps trailing short tables exactly 7 columns wide if is_last_table: while (len(current_chunk) + (1 if is_first else 0)) < total_slots: while allocated_slots < 7: 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 glitches if allocated_width < 0.75: allocated_width = 0.75 calculated_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) allocated_slots += 1
# The align="center" attribute is included here for native Google Docs pasting support # Native align="center" makes Google Docs automatically center the table on paste html_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 width 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;">') 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>') # LOCKED REQUIREMENT: Symmetrical 0.069in cell padding across all four boundaries + suppressed text wrap # 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 lines
def 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) return
39 unmodified lines CRITICAL 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'). 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 lines yield gr.update(visible=True, value=f"<p style='color:red; text-align:center;'>❌ API Error: {str(e)}</p>"), "", gr.update(visible=False) return
yield gr.update(visible=True, value=status_html("Executing 3-Step Column Balance Layout Matrix")), "", gr.update(visible=False) yield 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