Spaces:
Running
Running
Update app.py
Browse filesI'm ready for a nap
8 unmodified lines910111213141516171819202122231 unmodified line2526272829303126 unmodified lines5859606162636452 unmodified lines11711811912012112212396 unmodified lines22022122222322422522610 unmodified lines23723823924024124224318 unmodified lines2622632642652662672681 unmodified line27027127227327427527641 unmodified lines3183193203213223233248 unmodified linesfrom docx.oxml import parse_xml, OxmlElementfrom docx.oxml.ns import nsdecls, qn# Classic reliable legacy library that natively connects your interface to Gemini 1.5 Flashimport google.generativeai as generative_ai# ---------------------------------------------------------------------------# 1. CORE LINGUISTIC PIPELINE (GEMINI TRANSLITERATION & TRANSLATION ENGINE)# ---------------------------------------------------------------------------def process_live_ai_request(word, api_key):"""Queries the stable Gemini 1.5 Flash model using the user's custom API key.Enforces the full BEI Transliteration Schema Matrix and Morphology constraints."""clean_key = api_key.strip() if api_key else ""1 unmodified linereturn "Missing Key", "Missing Key", "Enter valid key above"try:# Configure the legacy library with the user-provided keygenerative_ai.configure(api_key=clean_key)model = generative_ai.GenerativeModel('gemini-1.5-flash')26 unmodified linesBET: v / BET_DAGESH: b | GIMEL: g / GIMEL_DAGESH: g | DALET: d / DALET_DAGESH: d | KAF/FINAL_KAF: kh / KAF_DAGESH: k | PE/FINAL_PE: f / PE_DAGESH: p | TAV: t / TAV_DAGESH: tHARDCODED CLUSTERS & EXPLICIT WORDS:שּׁ -> sh | צּ -> ts | יְרוּשָׁלִַם -> yᵉ·roo·sha·la̱·yeem | מממ -> ha·ma·shee̱·akh | קקק or יֵשׁוּעַ -> Yey·shoo̱·a | אֲדֹנָי -> a·do·nai̱ | שִׁיחַ -> ·shee̱·akh | DIVINE_NAME (YHVH) -> Yᵉ·ho·va̱h | DIVINE_NAME_ELOHIM -> Ye·ho·vee̱h---CRITICAL BEI MORPHOLOGY RULES:52 unmodified linescell_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>')# Cell margin padding locked precisely to your true 0.069 inches benchmark spacingpadding_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)96 unmodified linesreturn "".join(html_elements)# ---------------------------------------------------------------------------# 4. RUNTIME WORKFLOW CONTROLLER (PACED INDIVIDUAL TOKEN ENGINE)# ---------------------------------------------------------------------------def process_pipeline(api_key, ms_name, book, ch, ver, raw_input):if not raw_input.strip():10 unmodified linesword_packages = []for tok in tokens:# Pacing constraint (0.4s) naturally prevents network rate blockstime.sleep(0.4)tl, ts, mo = process_live_ai_request(tok, api_key)word_packages.append((tok, tl, ts, mo))18 unmodified linesdoc.save(file_path)elapsed = time.time() - start_timestatus = f"Success! Processed {len(tokens)} words in {elapsed:.2f} seconds across Gemini 1.5 Flash."return status, html_canvas, gr.update(value=file_path, visible=True)1 unmodified linereturn "", "Success: Canvas workspace cleared cleanly.", "", gr.update(visible=False)# ---------------------------------------------------------------------------# 5. GRADIO INTERFACE LAYOUT (WITH CORRECT CONTRAST PALETTES)# ---------------------------------------------------------------------------bei_css = """body, .gradio-container { background-color: #F4F3EF !important; }41 unmodified lineswith gr.Row():with gr.Column(scale=2):# FIXED VISIBILITY: Removed the bold text tags to ensure the title inherits clear dark charcoal text nativelygr.HTML('''<div class="api-guide-box"><p style="color: #2D3748 !important; font-family: Arial, sans-serif !important; font-size: 11pt !important; margin: 0 !important; padding: 0 !important; line-height: 1.4 !important;">8 unmodified lines910111213141516171819202122231 unmodified line2526272829303126 unmodified lines5859606162636452 unmodified lines11711811912012112212396 unmodified lines22022122222322422522610 unmodified lines23723823924024124218 unmodified lines2612622632642652662671 unmodified line26927027127227327427541 unmodified lines3173183193203213223238 unmodified linesfrom docx.oxml import parse_xml, OxmlElementfrom docx.oxml.ns import nsdecls, qn# Classic secure SDK version that maps your target model beautifullyimport google.generativeai as generative_ai# ---------------------------------------------------------------------------# 1. CORE AI LINGUISTIC PIPELINE (USER API KEY PASS)# ---------------------------------------------------------------------------def process_live_ai_request(word, api_key):"""Queries the stable Gemini 1.5 Flash model utilizing the user-provided API key.Enforces the full BEI Transliteration Schema Matrix and Morphology constraints."""clean_key = api_key.strip() if api_key else ""1 unmodified linereturn "Missing Key", "Missing Key", "Enter valid key above"try:# Configure the legacy library dynamically with the key from the UI text boxgenerative_ai.configure(api_key=clean_key)model = generative_ai.GenerativeModel('gemini-1.5-flash')26 unmodified linesBET: v / BET_DAGESH: b | GIMEL: g / GIMEL_DAGESH: g | DALET: d / DALET_DAGESH: d | KAF/FINAL_KAF: kh / KAF_DAGESH: k | PE/FINAL_PE: f / PE_DAGESH: p | TAV: t / TAV_DAGESH: tHARDCODED CLUSTERS & EXPLICIT WORDS:שּׁ -> sh | צּ -> ts | יְרווּשָׁלִַם -> yᵉ·roo·sha·la̱·yeem | מממ -> ha·ma·shee̱·akh | קקק or יֵשׁוּעַ -> Yey·shoo̱·a | אֲדֹנָי -> a·do·nai̱ | שִׁיחַ -> ·shee̱·akh | DIVINE_NAME (YHVH) -> Yᵉ·ho·va̱h | DIVINE_NAME_ELOHIM -> Ye·ho·vee̱h---CRITICAL BEI MORPHOLOGY RULES:52 unmodified linescell_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>')# Precise cell margin constraints set down to your 0.069 inches padding benchmark layoutpadding_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)96 unmodified linesreturn "".join(html_elements)# ---------------------------------------------------------------------------# 4. RUNTIME WORKFLOW CONTROLLER (PACED SEQUENCE ENGINE)# ---------------------------------------------------------------------------def process_pipeline(api_key, ms_name, book, ch, ver, raw_input):if not raw_input.strip():10 unmodified linesword_packages = []for tok in tokens:time.sleep(0.4)tl, ts, mo = process_live_ai_request(tok, api_key)word_packages.append((tok, tl, ts, mo))18 unmodified linesdoc.save(file_path)elapsed = time.time() - start_timestatus = f"Success! Processed {len(tokens)} words in {elapsed:.2f} seconds."return status, html_canvas, gr.update(value=file_path, visible=True)1 unmodified linereturn "", "Success: Canvas workspace cleared cleanly.", "", gr.update(visible=False)# ---------------------------------------------------------------------------# 5. GRADIO DESIGN THEME LAYOUT PARAMETERS# ---------------------------------------------------------------------------bei_css = """body, .gradio-container { background-color: #F4F3EF !important; }41 unmodified lineswith gr.Row():with gr.Column(scale=2):# RESTORED INTERFACE: Removed boldface text markers completely so the label displays cleanly in its native dark theme colorgr.HTML('''<div class="api-guide-box"><p style="color: #2D3748 !important; font-family: Arial, sans-serif !important; font-size: 11pt !important; margin: 0 !important; padding: 0 !important; line-height: 1.4 !important;">
app.py+10-11