Spaces:
Running
Running
Update app.py
Browse files11 unmodified lines12131415151617185 unmodified lines2425262728272829303162 unmodified lines94959697979899100130 unmodified lines23123223323423423523623710 unmodified lines24824925025125125225325418 unmodified lines2732742752762762772782791 unmodified line2812822832842842852862874 unmodified lines29229329429529529629711 unmodified linesfrom docx.oxml.ns import nsdecls, qn
# ---------------------------------------------------------------------------# 1. CORE API LINGUISTIC PIPELINE (WORD-BY-WORD SELECTION OVER MODEL 1.5 FLASH)# 1. CORE API LINGUISTIC PIPELINE (WORD-BY-WORD WITH CORRECT 1.5 FLASH ROUTING)# ---------------------------------------------------------------------------def process_live_ai_request(word, api_key): """5 unmodified lines 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-1.5-flash:generateContent?key={clean_key}" # FIX: Corrected model string path to 'gemini-1.5-flash-latest' to eliminate HTTP 404 routing errors url = f"https://generativelanguage.googleapis.com/v1beta/models/gemini-1.5-flash-latest:generateContent?key={clean_key}" headers = {"Content-Type": "application/json"} prompt = f"""62 unmodified lines morphology = lines[2] if len(lines) > 2 else "error" return transliteration, translation, morphology.replace(".", "") else: return f"API Error ({response.status_code})", "Rate Limit Active", "error" return f"API Error ({response.status_code})", "Connection Interrupted", "error" except Exception as e: return "Connection Timeout", "Network Error", "error"
130 unmodified lines return "".join(html_elements)
# ---------------------------------------------------------------------------# 5. PACED WORD-BY-WORD EXECUTION ROUTER (FIXES EXCEPTION 429)# 5. PACED WORD-BY-WORD EXECUTION ROUTER# ---------------------------------------------------------------------------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: # Pacing step spacing out sequential web hits by exactly 400 milliseconds to avoid 429 locks # 400 millisecond delay to ensure continuous queries never trigger rate locks time.sleep(0.4) tl, ts, mo = process_live_ai_request(tok, api_key) word_packages.append((tok, tl, ts, mo))18 unmodified lines doc.save(file_path) elapsed = time.time() - start_time status = f"Success! Processed {len(tokens)} words in {elapsed:.2f} seconds across Gemini 1.5 Flash." status = f"Success! Processed {len(tokens)} words in {elapsed:.2f} seconds." return status, html_canvas, gr.update(value=file_path, visible=True)
1 unmodified line return "", "Success: Canvas workspace cleared cleanly.", "", gr.update(visible=False)
# ---------------------------------------------------------------------------# 6. GRADIO UI LAYOUT CONFIGURATIONS (WITH EXPLICIT VISIBILITY FIX)# 6. GRADIO UI LAYOUT CONFIGURATIONS# ---------------------------------------------------------------------------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: 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 span, .api-guide-box b, .api-guide-box strong, .api-guide-box a { color: #2D3748 !important; app.py+8-9