Spaces:
Running
Running
Update app.py
Browse filesI hate this thing
11 unmodified lines121314151516171819201920212223242526272628293029313233333435363724 unmodified lines626364646566676823 unmodified lines9293949495969797989910081 unmodified lines18218318418518518618718842 unmodified lines23123223323423423523623710 unmodified lines24824925025125125225325425517 unmodified lines2732742752752762772782791 unmodified line2812822832832842852862874 unmodified lines29229329429429529629629729829930030130230330430533 unmodified lines3393403413363423433443453 unmodified lines34935035134635235335435511 unmodified linesfrom docx.oxml.ns import nsdecls, qn
# ---------------------------------------------------------------------------# 1. CORE API ENGINE - DYNAMIC CONTEXTUAL TRANSLATION & TRANSLITERATION# 1. CORE API LINGUISTIC PIPELINE (WORD-BY-WORD SELECTION OVER MODEL 1.5 FLASH)# ---------------------------------------------------------------------------def process_live_ai_request(word, api_key): """ Leverages Gemini 2.5 Flash via direct REST calls to dynamically analyze the Hebrew token, applying the exact BEI Transliteration Schema and Morphology rules. Queries the stable Gemini 1.5 Flash model web gateway for a single word token. Feeds your complete BEI Transliteration Schema Matrix and Morphology rules directly into each call for pristine, context-aware translations. """ clean_key = api_key.strip() if api_key else "" if not clean_key: return "Missing Key", "Missing Key", "Enter valid key above" # Updated API gateway url string pointing exactly to stable gemini-1.5-flash url = f"https://generativelanguage.googleapis.com/v1beta/models/gemini-2.5-flash:generateContent?key={clean_key}" url = f"https://generativelanguage.googleapis.com/v1beta/models/gemini-1.5-flash:generateContent?key={clean_key}" headers = {"Content-Type": "application/json"} # Complete systemic prompt passing your precise organizational rules prompt = f""" You are an expert academic philologist working for Benai Emunah International (BEI) on a critical interlinear text project for the Hebrew Book of Luke. Analyze this isolated Hebrew word token: "{word}" Analyze this single isolated Hebrew word token: "{word}" Generate exactly THREE lines of text in your response. Do not include any markdown, introductory remarks, bullet points, or formatting. Just output the three raw lines. 24 unmodified lines --- CRITICAL BEI MORPHOLOGY RULES: - STRICT NO-PERIOD CONSTRAINT: Abbreviation tags must absolutely never contain a period (use 'v', never write 'v.'). - Token Assembly Sequence: [Part of Speech Abbreviation] [Binyan (Verbs Only)] [Tense/Mood/Aspect (Verbs Only)] [Concordance Block]. - Token Assembly Sequence: [Part of Speech] [Binyan (Verbs Only)] [Tense/Mood/Aspect (Verbs Only)] [Concordance Block]. - Part of Speech: v, n, adv, adj, conj, part, prep, pron, name, ddo, #, intj, constr - Binyan: Pa'al, Nif'al, Pi'el, Pu'al, Hif'il, Huf'al, Hitpa'el - Tense/Mood/Aspect: perf, imp, ptcpl23 unmodified lines transliteration = lines[0] if len(lines) > 0 else "error" translation = lines[1] if len(lines) > 1 else "error" morphology = lines[2] if len(lines) > 2 else "error" return transliteration, translation, morphology.replace(".", "") else: return f"API Error ({response.status_code})", "Check Key Setup", "error" return f"API Error ({response.status_code})", "Rate Limit Active", "error" except Exception as e: return "Connection Timeout", "Network Error", "error"
81 unmodified lines run.font.size = Pt(4)
# ---------------------------------------------------------------------------# 3. SCREEN CANVAS VIEW COMPILER (HTML DISPLAY ENGINE)# 3. SCREEN CANVAS VIEW COMPILER# ---------------------------------------------------------------------------def build_html_canvas(word_packages, ms_name, heading_label): html_elements = []42 unmodified lines return "".join(html_elements)
# ---------------------------------------------------------------------------# 4. RUNTIME SYSTEM EXECUTION ENGINE# 5. PACED WORD-BY-WORD EXECUTION ROUTER (FIXES EXCEPTION 429)# ---------------------------------------------------------------------------def process_pipeline(api_key, ms_name, book, ch, ver, raw_input): if not raw_input.strip():10 unmodified lines word_packages = [] for tok in tokens: # Request transliteration, translation, and morphology concurrently via systemic instructions # Pacing step spacing out sequential web hits by exactly 400 milliseconds to avoid 429 locks time.sleep(0.4) tl, ts, mo = process_live_ai_request(tok, api_key) word_packages.append((tok, tl, ts, mo)) 17 unmodified lines doc.save(file_path) elapsed = time.time() - start_time status = f"Success! Processed {len(tokens)} words in {elapsed:.2f} seconds." status = 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 line return "", "Success: Canvas workspace cleared cleanly.", "", gr.update(visible=False)
# ---------------------------------------------------------------------------# 5. GRADIO UI DESIGN LAYOUT# 6. GRADIO UI LAYOUT CONFIGURATIONS (WITH EXPLICIT VISIBILITY FIX)# ---------------------------------------------------------------------------bei_css = """body, .gradio-container { background-color: #F4F3EF !important; }4 unmodified lines.clear-btn { background-color: #718096 !important; color: white !important; font-weight: bold !important; border-radius: 4px !important; margin: 5px 0; }.copy-btn { background-color: #D4AF37 !important; color: #1B4D3E !important; font-weight: bold !important; border-radius: 4px !important; margin: 5px 0; border: 1px solid #1B4D3E !important; }
/* FIX: Forced high-visibility dark charcoal text for the instructions box title and body lines *//* FIX: Triple override rules forcing dark charcoal on text layouts inside guide box */.api-guide-box { background-color: #E2E8F0 !important; border-left: 5px solid #1B4D3E !important; padding: 12px; border-radius: 4px; margin-bottom: 10px; }.api-guide-box p, .api-guide-box b, .api-guide-box a { color: #2D3748 !important; font-family: 'Arial', sans-serif !important; font-size: 11pt !important; margin: 0; }.api-guide-box p, .api-guide-box span, .api-guide-box b, .api-guide-box strong, .api-guide-box a { color: #2D3748 !important; font-family: 'Arial', sans-serif !important; font-size: 11pt !important; margin: 0 !important;}.api-guide-box a { color: #1B4D3E !important; font-weight: bold !important; text-decoration: underline !important; }
input[type="text"], input[type="password"], textarea {33 unmodified lines with gr.Column(scale=2): gr.HTML(''' <div class="api-guide-box"> <p>馃攽 <b>Gemini API Key Guide:</b> To generate your credentials key, log into <p>馃攽 <strong>Gemini API Key Guide:</strong> To generate your credentials key, log into <a href="https://aistudio.google.com/" target="_blank">Google AI Studio</a>, click the "Get API Key" button, copy the token code block, and paste it below.</p> </div>3 unmodified lines ms_name = gr.Textbox(label="馃搵 Manuscript Selection Name", value="Marseilles MS-24") book = gr.Textbox(label="Book", value="Luke") with gr.Row(): ch = gr.Dropdown(label="Chapter", choices=[str(i) for i in range(1, 25)], value="1") ch = gr.Dropdown(label="Chapter", choices=[str(i) for i in range(1, 24)], value="1") ver = gr.Dropdown(label="Verse", choices=[str(i) for i in range(1, 81)], value="5") with gr.Column(scale=2): raw_input = gr.Textbox(label="Paste Your Hebrew Here", value="讛指讬指讛 讘旨执讬诪值讬志讛讜止专职讚旨讜止住 讛址诪旨侄诇侄讱职 讻旨止讛值谉 讗侄讞指讚 讜旨砖讈职诪讜止 讝职讻址专职讬指讛讜旨 诪执讘旨值讬转 讗指讘执讬指讛 讜职讗执砖讈职转旨讜止 诪执讘旨值讬转 讗址讛植专讜止谉 讜旨砖讈职诪指讛旨 讗值诇执讬讝址讘旨值转", lines=7)app.py+24-18