Spaces:
Running
Running
Update app.py
Browse filesanother syntax error grrr
34 unmodified lines353637383940415 unmodified lines4748495051525354555657585927 unmodified lines878889909134 unmodified lines}def clean_morphology(text):# Enforce strict no-period constraint rule across all grammar tokensreturn text.replace(".", "")def translit_word(word):5 unmodified linesreturn resdef call_mock_engine(word):# Simulated breakdown isolating core semantic roots matching manuscript textif "ืึธืึธื" in word: return "haยทyaฬฑ", "(there) was", "v Pa'al past 3ms"if "ืึผึดืืึตืึพ" in word: return "beeยทmey", "in the days of", "nmp constr"if "ืืึนืจึฐืึผืึนืก" in word: return "horยทdoฬฑs", "Herod", "name"if "ืึทืึผึถืึถืึฐ" in word: return "haยทmeยทleฬฑkh", "the king", "nms"if "ืึผึนืึตื" in word: return "koยทheyฬฑn", "priest", "nms"if "ืึถืึธื" in word: return "eยทkhaฬฑd", "a certain, one", "# m"return translit_word(word), "translation", "n ms"# ---------------------------------------------------------------------------27 unmodified linescell_top = table.cell(0, col_idx)cell_bottom = table.cell(1, col_idx)# Enforce exact 0.069 inches padding boundaries configurationfor cell in (cell_top, cell_bottom):34 unmodified lines353637383940415 unmodified lines4748495051525354555657585960616263646527 unmodified lines9394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928034 unmodified lines}def clean_morphology(text):"""Enforces the strict no-period constraint rule across all grammar tokens."""return text.replace(".", "")def translit_word(word):5 unmodified linesreturn resdef call_mock_engine(word):"""Simulated breakdown isolating core semantic roots matching manuscript text."""if "ืึธืึธื" in word:return "haยทyaฬฑ", "(there) was", "v Pa'al past 3ms"if "ืึผึดืืึตืึพ" in word:return "beeยทmey", "in the days of", "nmp constr"if "ืืึนืจึฐืึผืึนืก" in word:return "horยทdoฬฑs", "Herod", "name"if "ืึทืึผึถืึถืึฐ" in word:return "haยทmeยทleฬฑkh", "the king", "nms"if "ืึผึนืึตื" in word:return "koยทheyฬฑn", "priest", "nms"if "ืึถืึธื" in word:return "eยทkhaฬฑd", "a certain, one", "# m"return translit_word(word), "translation", "n ms"# ---------------------------------------------------------------------------27 unmodified linescell_top = table.cell(0, col_idx)cell_bottom = table.cell(1, col_idx)# Enforce exact 0.069 inches padding boundaries configuration (Cleanly expanded layout blocks)cell_top.width = Inches(col_widths[col_idx])tcPr_top = cell_top._tc.get_or_add_tcPr()borders_top = parse_xml(f'<w:tcBorders {nsdecls("w")}><w:top w:val="single" w:sz="4" w:color="B7B7B7"/><w:left w:val="single" w:sz="4" w:color="B7B7B7"/><w:bottom w:val="single" w:sz="4" w:color="B7B7B7"/><w:right w:val="single" w:sz="4" w:color="B7B7B7"/></w:tcBorders>')padding_top = parse_xml(f'<w:tcMar {nsdecls("w")}><w:top w:w="99" w:type="dxa"/><w:left w:w="99" w:type="dxa"/><w:bottom w:w="99" w:type="dxa"/><w:right w:w="99" w:type="dxa"/></w:tcMar>')tcPr_top.append(borders_top)tcPr_top.append(padding_top)cell_bottom.width = Inches(col_widths[col_idx])tcPr_bottom = cell_bottom._tc.get_or_add_tcPr()borders_bottom = parse_xml(f'<w:tcBorders {nsdecls("w")}><w:top w:val="single" w:sz="4" w:color="B7B7B7"/><w:left w:val="single" w:sz="4" w:color="B7B7B7"/><w:bottom w:val="single" w:sz="4" w:color="B7B7B7"/><w:right w:val="single" w:sz="4" w:color="B7B7B7"/></w:tcBorders>')padding_bottom = parse_xml(f'<w:tcMar {nsdecls("w")}><w:top w:w="99" w:type="dxa"/><w:left w:w="99" w:type="dxa"/><w:bottom w:w="99" w:type="dxa"/><w:right w:w="99" w:type="dxa"/></w:tcMar>')tcPr_bottom.append(borders_bottom)tcPr_bottom.append(padding_bottom)if is_first and col_idx == 0:cell_top.text = heading_labelcell_bottom.text = ms_namep1 = cell_top.paragraphs[0]p2 = cell_bottom.paragraphs[0]p1.alignment = WD_ALIGN_PARAGRAPH.CENTERp2.alignment = WD_ALIGN_PARAGRAPH.CENTERp1.runs[0].font.name = 'Times New Roman'p1.runs[0].font.size = Pt(14)p2.runs[0].font.name = 'Arial'p2.runs[0].font.size = Pt(11)cell_top.vertical_alignment = WD_ALIGN_VERTICAL.TOPcell_bottom.vertical_alignment = WD_ALIGN_VERTICAL.TOPcontinuepkg_idx = col_idx - 1 if is_first else col_idxif pkg_idx < len(word_packages) and word_packages[pkg_idx]:heb, tl, ts, mo = word_packages[pkg_idx]cell_top.text = hebp_top = cell_top.paragraphs[0]p_top.alignment = WD_ALIGN_PARAGRAPH.RIGHTcell_top.vertical_alignment = WD_ALIGN_VERTICAL.CENTERp_top.runs[0].font.name = 'Times New Roman'p_top.runs[0].font.size = Pt(18)cell_bottom.text = f"{tl}\n{ts}\n{clean_morphology(mo)}"p_bot = cell_bottom.paragraphs[0]p_bot.alignment = WD_ALIGN_PARAGRAPH.CENTERcell_bottom.vertical_alignment = WD_ALIGN_VERTICAL.TOPfor r in p_bot.runs:r.font.name = 'Arial'r.font.size = Pt(11)# 4pt Times New Roman blank grid block spacing spacersp = doc.add_paragraph()sp.paragraph_format.space_before = Pt(0)sp.paragraph_format.space_after = Pt(4)run = sp.add_run()run.font.name = 'Times New Roman'run.font.size = Pt(4)# ---------------------------------------------------------------------------# 3. SCREEN CANVAS VIEW COMPILER (HTML DISPLAY ENGINE)# ---------------------------------------------------------------------------def build_html_canvas(word_packages, ms_name, heading_label):"""Generates an explicit Right-To-Left styled HTML canvas container matching layout grid rules."""html = '<div style="overflow-x:auto; background-color:white; padding:15px; border-radius:4px;">'# Block 1 (Handles first 6 layout words + verse headings anchor)t1_data = word_packages[:6]while len(t1_data) < 6:t1_data.append(None)html += '<table dir="rtl" style="width:7in; border-collapse:collapse; margin:0 auto 4pt auto; table-layout:fixed; border:1px solid #b7b7b7;">'# Row 1: Hebrew Text Linehtml += '<tr style="height:40px;">'html += f'<td style="width:1in; border:1px solid #b7b7b7; font-family:\'Times New Roman\'; font-size:14pt; text-align:center; vertical-align:top; color:#000; font-weight:bold;">{heading_label}</td>'for pkg in t1_data:text = pkg[0] if pkg else ""html += f'<td style="width:1in; border:1px solid #b7b7b7; font-family:\'Times New Roman\'; font-size:18pt; text-align:right; padding:0.069in; vertical-align:middle; color:#000;">{text}</td>'html += '</tr>'# Row 2: Data Package Triple Stackshtml += '<tr>'html += f'<td style="border:1px solid #b7b7b7; font-family:\'Arial\'; font-size:11pt; text-align:center; vertical-align:top; color:#000;">{ms_name}</td>'for pkg in t1_data:content = f'<div style="line-height:1.2;">{pkg[1]}<br>{pkg[2]}<br>{clean_morphology(pkg[3])}</div>' if pkg else ""html += f'<td style="border:1px solid #b7b7b7; font-family:\'Arial\'; font-size:11pt; text-align:center; padding:0.069in; vertical-align:top; color:#000;">{content}</td>'html += '</tr></table>'# Trailing Blocks (Iterates over remaining strings across columns 1-7 sequentially)rem = word_packages[6:]while len(rem) > 0:chunk = rem[:7]while len(chunk) < 7:chunk.append(None)html += '<table dir="rtl" style="width:7in; border-collapse:collapse; margin:0 auto 4pt auto; table-layout:fixed; border:1px solid #b7b7b7;"><tr>'for pkg in chunk:text = pkg[0] if pkg else ""html += f'<td style="width:1in; border:1px solid #b7b7b7; font-family:\'Times New Roman\'; font-size:18pt; text-align:right; padding:0.069in; vertical-align:middle; color:#000;">{text}</td>'html += '</tr><tr>'for pkg in chunk:content = f'<div style="line-height:1.2;">{pkg[1]}<br>{pkg[2]}<br>{clean_morphology(pkg[3])}</div>' if pkg else ""html += f'<td style="border:1px solid #b7b7b7; font-family:\'Arial\'; font-size:11pt; text-align:center; padding:0.069in; vertical-align:top; color:#000;">{content}</td>'html += '</tr></table>'rem = rem[7:]html += '</div>'return html# ---------------------------------------------------------------------------# 4. RUNTIME SYSTEM EXECUTION BLOCK# ---------------------------------------------------------------------------def process_pipeline(api_key, ms_name, book, ch, ver, raw_input):if not raw_input.strip():return "System Warning: Please supply structural manuscript input lines.", "", gr.update(visible=False)start_time = time.time()time.sleep(1.2)heading_label = f"{book[:3]}. {ch}:{ver}"tokens = raw_input.strip().split()word_packages = [((tok,) + call_mock_engine(tok)) for tok in tokens]# Render Output Layout HTML Canvashtml_canvas = build_html_canvas(word_packages, ms_name, heading_label)# Build Document File Template Targetdoc = Document()t1_data = word_packages[:6]while len(t1_data) < 6:t1_data.append(None)build_docx_table(doc, t1_data, ms_name, heading_label, is_first=True)rem = word_packages[6:]while len(rem) > 0:chunk = rem[:7]while len(chunk) < 7:chunk.append(None)build_docx_table(doc, chunk, ms_name, heading_label, is_first=False)rem = rem[7:]file_path = "BEI_Interlinear_Output.docx"doc.save(file_path)elapsed = time.time() - start_timestatus = f"Execution successful! Processed context parameters across {len(tokens)} words in {elapsed:.2f} seconds."return status, html_canvas, gr.update(value=file_path, visible=True)# ---------------------------------------------------------------------------# 5. GRADIO SPACE STYLING (BENAI EMUNAH FOREST ACCENTS)# ---------------------------------------------------------------------------bei_css = """body, .gradio-container { background-color: #F4F3EF !important; }.bei-banner { background-color: #1B4D3E; padding: 22px; text-align: center; border-radius: 8px; border-bottom: 4px solid #D4AF37; }.bei-banner h1 { color: #F4F3EF !important; font-size: 28px; margin: 0; font-weight: bold; }.bei-banner p { color: #D4AF37 !important; margin: 4px 0 0 0; font-size: 13px; }.action-btn { background-color: #1B4D3E !important; color: white !important; font-weight: bold !important; border-radius: 4px !important; }.hourglass-box { text-align: center; font-size: 24px; padding: 10px; color: #1B4D3E; }"""with gr.Blocks(css=bei_css, title="Shorashim Pro Workspace") as demo:with gr.Row(elem_classes="bei-banner"):gr.Markdown("<h1>๐ Shorashim Pro Workspace</h1><p>Benai Emunah International โข Critical Manuscript Translation Interface</p>")with gr.Row():with gr.Column(scale=2):api_key = gr.Textbox(label="๐ Gemini API Access Key", type="password", placeholder="AI key token platform credentials...")with gr.Row():ms_name = gr.Textbox(label="๐ Manuscript Selection Name", value="Marseilles MS-24")book = gr.Textbox(label="๐ Scripture Target Book", value="Luke")with gr.Row():ch = gr.Dropdown(label="Chapter Target", choices=[str(i) for i in range(1, 25)], value="1")ver = gr.Dropdown(label="Verse Target", choices=[str(i) for i in range(1, 81)], value="5")with gr.Column(scale=2):raw_input = gr.Textbox(label="๐ Manuscript Hebrew Words Input String", value="ืึธืึธื ืึผึดืืึตืึพืืึนืจึฐืึผืึนืก ืึทืึผึถืึถืึฐ ืึผึนืึตื ืึถืึธื", lines=5)with gr.Row():gen_btn = gr.Button("๐ Generate Interlinear Canvas", elem_classes="action-btn")with gr.Row():with gr.Column(scale=1, visible=False) as loading_area:gr.Markdown("<div class='hourglass-box'>โณ <b>Backend Operational Threads Active... Please Wait.</b></div>")with gr.Row():with gr.Column():status_field = gr.Textbox(label="System Status Pipeline Logs", interactive=False)doc_file = gr.File(label="
app.py+199-10