Spaces:
Running
Running
Update app.py
Browse filesstill not right
5 unmodified lines67891011121 unmodified line141516171819204 unmodified lines252627282930311 unmodified line3334353637383940414243444546474849505152535455562 unmodified lines596061626364655 unmodified lines717273747576771 unmodified line7980818283848559 unmodified lines1451461471481491501511527 unmodified lines16016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121214 unmodified lines22722822923023123223377 unmodified lines3113123133143153163175 unmodified lines# --- Advanced Premium Dark/Black Theme Engine ---custom_css = """/* Completely hide technical loading bars & indicators */.subpanel.loading, .generating, div[class*="loading"], .progress-wrap {display: none !important;visibility: hidden !important;1 unmodified lineoverflow: hidden !important;}/* Polished Minimalist Progress Window */.progress-container {padding: 20px;text-align: center;4 unmodified linesmargin-bottom: 20px;}/* White Canvas Table Wrapper for clear document viewing */.white-canvas {display: flex;justify-content: center;1 unmodified linewidth: 100%;}/* Forcing Total UI Background to Black */.gradio-container, html, body {background-color: #000000 !important;font-family: 'Segoe UI', system-ui, -apple-system, sans-serif !important;}/* Text elements color correction for readability against black background */.gradio-container h1, .gradio-container h2, .gradio-container h3, .gradio-container p, .gradio-container span {color: #f8fafc !important;}/* Style Accordion Boxes for Dark Mode */.label-wrap, .accordion-trigger {background-color: #111827 !important;border: 1px solid #1f2937 !important;}/* Form Input Field Polishing */input, textarea, select {border-radius: 8px !important;border: 1px solid #374151 !important;2 unmodified linesbox-shadow: inset 0 1px 2px 0 rgba(0, 0, 0, 0.5) !important;}/* Primary Action Button Customization */button.primary {background: linear-gradient(135deg, #2563eb 0%, #1d4ed8 100%) !important;border: none !important;5 unmodified linestransform: translateY(-1px) !important;}/* Secondary Actions Customization */button.secondary {background-color: #1f2937 !important;border: 1px solid #374151 !important;1 unmodified line}"""# JAVASCRIPT TO STRIP AWAY THE HUGGING FACE TOP NAVIGATION HEADERforce_clean_layout_js = """function() {const removeHeaderBlock = () => {59 unmodified linesreturn chunksdef build_html_tables(manuscript, reference, words_data):# Total targeted layout boundary matching your templatetotal_table_width_in = 7.0table_style = (f"width: {total_table_width_in}in !important; min-width: {total_table_width_in}in !important; "7 unmodified linesfor idx, current_chunk in enumerate(table_chunks):is_first = (idx == 0)total_slots = 7slot_weights = []if is_first:ref_len = max(len(reference), len(manuscript))slot_weights.append(ref_len)for word in current_chunk:# Multiply Hebrew character length by 1.8 because 24px font is visually much wider than 14px Arialw_hebrew = len(word.get("hebrew", "")) * 1.8w_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 5)is_last_table = (idx == len(table_chunks) - 1)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(5)# --- EXECUTE PROPORTIONAL COLUMN BALANCING ---total_weight_score = sum(slot_weights)calculated_widths = []for w in slot_weights:allocated_width = (w / total_weight_score) * total_table_width_in# Guard against columns getting crushed too narrowif allocated_width < 0.70:allocated_width = 0.70calculated_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)html_output.append(f'<table style="{table_style}">')html_output.append(' <colgroup>')for c_width in calculated_widths:html_output.append(f' <col style="width: {c_width}in !important;">')html_output.append(' </colgroup>')# FIXED STEP: white-space flipped to normal to allow text to wrap within balanced bounds, preserving 0.069in paddingbase_cell = "border: 1pt solid #b7b7b7; padding: 0.069in !important; height: auto; overflow: hidden; word-wrap: break-word; white-space: normal !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}"heading_cell_style = f"font-family: 'Times New Roman', serif !important; font-size: 18.6667px !important; color: #000000 !important; text-align: center; vertical-align: middle; line-height: 1.0 !important; {base_cell}"14 unmodified linesis_first = Falsefor word in current_chunk:if word.get("hebrew") != " ":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", ""))77 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)5 unmodified lines678910111 unmodified line1314151617184 unmodified lines2324252627281 unmodified line30313233343536373839404142434445464748492 unmodified lines5253545556575 unmodified lines6364656667681 unmodified line70717273747559 unmodified lines1351361371381391401411427 unmodified lines15015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021114 unmodified lines22622722822923023123277 unmodified lines3103113123133143153165 unmodified lines# --- Advanced Premium Dark/Black Theme Engine ---custom_css = """.subpanel.loading, .generating, div[class*="loading"], .progress-wrap {display: none !important;visibility: hidden !important;1 unmodified lineoverflow: hidden !important;}.progress-container {padding: 20px;text-align: center;4 unmodified linesmargin-bottom: 20px;}.white-canvas {display: flex;justify-content: center;1 unmodified linewidth: 100%;}.gradio-container, html, body {background-color: #000000 !important;font-family: 'Segoe UI', system-ui, -apple-system, sans-serif !important;}.gradio-container h1, .gradio-container h2, .gradio-container h3, .gradio-container p, .gradio-container span {color: #f8fafc !important;}.label-wrap, .accordion-trigger {background-color: #111827 !important;border: 1px solid #1f2937 !important;}input, textarea, select {border-radius: 8px !important;border: 1px solid #374151 !important;2 unmodified linesbox-shadow: inset 0 1px 2px 0 rgba(0, 0, 0, 0.5) !important;}button.primary {background: linear-gradient(135deg, #2563eb 0%, #1d4ed8 100%) !important;border: none !important;5 unmodified linestransform: translateY(-1px) !important;}button.secondary {background-color: #1f2937 !important;border: 1px solid #374151 !important;1 unmodified line}"""force_clean_layout_js = """function() {const removeHeaderBlock = () => {59 unmodified linesreturn chunksdef build_html_tables(manuscript, reference, words_data):total_table_width_in = 7.0total_slots = 7 # Exactly 7 columns per template gridtable_style = (f"width: {total_table_width_in}in !important; min-width: {total_table_width_in}in !important; "7 unmodified linesfor idx, current_chunk in enumerate(table_chunks):is_first = (idx == 0)is_last_table = (idx == len(table_chunks) - 1)# Count actual data positions vs blank fill requirementsactual_data_count = len(current_chunk)if is_first:actual_data_count += 1# If it's the short trailing table, pad it out with clean space objectsif is_last_table:while (len(current_chunk) + (1 if is_first else 0)) < total_slots:current_chunk.append({"hebrew": " ", "transliteration": " ", "translation": " ", "morphology": " "})# --- STEP BALANCING MATRIX ---calculated_widths = []# Scenario A: Short trailing table - distribute 7 inches perfectly evenly across columnsif is_last_table and not is_first:fixed_slice = round(total_table_width_in / total_slots, 4)calculated_widths = [fixed_slice] * total_slots# Scenario B: Full table - run character density scoring calculationselse:slot_weights = []if is_first:ref_len = max(len(reference), len(manuscript))slot_weights.append(ref_len)for word in current_chunk:w_hebrew = len(word.get("hebrew", "")) * 1.8w_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 5)total_weight_score = sum(slot_weights)for w in slot_weights:allocated_width = (w / total_weight_score) * total_table_width_inif allocated_width < 0.75:allocated_width = 0.75calculated_widths.append(round(allocated_width, 3))# Proportional Float Correctionremainder_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)html_output.append(f'<table style="{table_style}">')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>')# Strictly locked 0.069in box model propertiesbase_cell = "border: 1pt solid #b7b7b7; padding: 0.069in !important; height: auto; overflow: hidden; word-wrap: break-word; white-space: normal !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}"heading_cell_style = f"font-family: 'Times New Roman', serif !important; font-size: 18.6667px !important; color: #000000 !important; text-align: center; vertical-align: middle; line-height: 1.0 !important; {base_cell}"14 unmodified linesis_first = Falsefor word in current_chunk:if word.get("hebrew") != " " and word.get("hebrew") != " ":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", ""))77 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 Symmetric Grid Alignment Blueprint")), "", gr.update(visible=False)try:final_table_html = build_html_tables(manuscript_name, reference_header, raw_json_data)
app.py+44-45