Spaces:
Running
Running
Update app.py
Browse filesstill not right
5 unmodified lines6789910111 unmodified line131415171617184 unmodified lines232425282627281 unmodified line3031323633343536374238394041474243444546534748492 unmodified lines525354625556575 unmodified lines636465746667681 unmodified line7071728273747559 unmodified lines1351361371481381391401411427 unmodified lines15015115216316416515315415515615716816917017117217317417517615815917817918018116016116218418518618718816316416516616716816917017117217317417517617717817918018118218318418518618718819019119219319419519618919019119219319419519619719819920020120220220320520420520620820920720820921021114 unmodified lines22622722823022923023123277 unmodified lines3103113123143133143153165 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 line overflow: hidden !important;}
/* Polished Minimalist Progress Window */.progress-container { padding: 20px; text-align: center;4 unmodified lines margin-bottom: 20px;}
/* White Canvas Table Wrapper for clear document viewing */.white-canvas { display: flex; justify-content: center;1 unmodified line width: 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 lines box-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 lines transform: 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 lines return chunks
def build_html_tables(manuscript, reference, words_data): # Total targeted layout boundary matching your template total_table_width_in = 7.0 total_slots = 7 # Exactly 7 columns per template grid table_style = ( f"width: {total_table_width_in}in !important; min-width: {total_table_width_in}in !important; "7 unmodified lines for idx, current_chunk in enumerate(table_chunks): is_first = (idx == 0) total_slots = 7 slot_weights = [] is_last_table = (idx == len(table_chunks) - 1) # Count actual data positions vs blank fill requirements actual_data_count = len(current_chunk) 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 Arial w_hebrew = len(word.get("hebrew", "")) * 1.8 w_translit = len(word.get("transliteration", "")) w_trans = len(word.get("translation", "")) w_morph = len(word.get("morphology", "")) actual_data_count += 1 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 it's the short trailing table, pad it out with clean space objects 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) current_chunk.append({"hebrew": " ", "transliteration": " ", "translation": " ", "morphology": " "})
# --- STEP BALANCING MATRIX --- calculated_widths = [] # Scenario A: Short trailing table - distribute 7 inches perfectly evenly across columns if 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 calculations else: 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.8 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 5) for w in slot_weights: allocated_width = (w / total_weight_score) * total_table_width_in # Guard against columns getting crushed too narrow if allocated_width < 0.70: allocated_width = 0.70 calculated_widths.append(round(allocated_width, 3)) total_weight_score = sum(slot_weights) for w in slot_weights: allocated_width = (w / total_weight_score) * total_table_width_in if allocated_width < 0.75: allocated_width = 0.75 calculated_widths.append(round(allocated_width, 3)) # Proportional Float Correction 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(f' <col style="width: {c_width}in !important; min-width: {c_width}in !important; max-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 padding base_cell = "border: 1pt solid #b7b7b7; padding: 0.069in !important; height: auto; overflow: hidden; word-wrap: break-word; white-space: normal !important;" # Strictly locked 0.069in box model properties base_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 lines is_first = False for word in current_chunk: if word.get("hebrew") != " ": 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 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("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