Spaces:
Running
Running
Update app.py
Browse filesClean layout, added a link to a tutorial on pasting in your Gemini API key
3 unmodified lines45677891011121 unmodified line141516171817192019202122212223242526272829303132333435363738394041424344454647484950515253545556335758596060 unmodified lines12112212310012412510212612712812913013110713213313413511111213613713813914014111714214314412014514614714852 unmodified lines20120220317918020420520620720846 unmodified lines25525625723325825926026114 unmodified lines2762772782542552792802812822832842852862572872882592602612622892902912922932942952962972672682692702982993003013022722732743033043053063073083092763103113123133143153162803173183193202843213223233243253263273282873293303313 unmodified linesimport timeimport json
# --- Custom CSS to polish layout and hide default loading indicators ---# --- Advanced Friendly Styling 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: 15px; padding: 20px; text-align: center; border: 1px solid #b7b7b7; border-radius: 8px; background-color: #1e1e1e; margin-bottom: 15px; border: 1px solid #e2e8f0; border-radius: 12px; background-color: #ffffff; box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05); margin-bottom: 20px;}
/* White Canvas Table Wrapper */.white-canvas { display: flex; justify-content: center; align-items: center; width: 100%;}
/* Streamlined, approachable UI overrides */.gradio-container { background-color: #f8fafc !important; font-family: 'Segoe UI', system-ui, -apple-system, sans-serif !important;}input, textarea, select { border-radius: 8px !important; border: 1px solid #cbd5e1 !important; box-shadow: inset 0 1px 2px 0 rgba(0, 0, 0, 0.05) !important;}button.primary { background: linear-gradient(135deg, #2563eb 0%, #1d4ed8 100%) !important; border: none !important; border-radius: 8px !important; transition: transform 0.1s ease !important;}button.primary:hover { transform: translateY(-1px) !important;}"""
# JAVASCRIPT MATRIX TO FORCIBLY STRIP OUT THE HUGGING FACE HEADER AND WHITE BUTTON# JAVASCRIPT TO STRIP AWAY THE HUGGING FACE TOP NAVIGATION HEADERforce_clean_layout_js = """function() { const removeHeaderBlock = () => {60 unmodified lines
def build_html_tables(manuscript, reference, words_data): table_style = ( "width: 7in !important; border-collapse: collapse; margin-bottom: 4pt; " "width: auto !important; border-collapse: collapse; margin-bottom: 4pt; " "direction: rtl; border: 1pt solid #b7b7b7; background-color: #ffffff; " "line-height: 1.0 !important; height: auto;" "line-height: 1.0 !important; height: auto; margin-left: auto; margin-right: auto;" ) # Fixed to exactly 0.069in padding down below hebrew_cell_style = ( "font-family: 'Times New Roman', serif !important; font-size: 24px !important; color: #000000 !important; " "text-align: right; vertical-align: middle; border: 1pt solid #b7b7b7; " "padding: 5pt; height: auto; white-space: nowrap;" "padding: 0.069in !important; height: auto; white-space: nowrap; width: 1%;" ) english_cell_style = ( "font-family: Arial, sans-serif !important; font-size: 14.6667px !important; color: #000000 !important; " "border: 1pt solid #b7b7b7; padding: 5pt; text-align: center; " "vertical-align: top; height: auto; line-height: 1.0 !important;" "border: 1pt solid #b7b7b7; padding: 0.069in !important; text-align: center; " "vertical-align: top; height: auto; line-height: 1.0 !important; white-space: nowrap; width: 1%;" ) heading_cell_style = ( "font-family: 'Times New Roman', serif !important; font-size: 18.6667px !important; color: #000000 !important; " "text-align: center; vertical-align: middle; border: 1pt solid #b7b7b7; " "padding: 5pt; height: auto; white-space: nowrap; line-height: 1.0 !important;" "padding: 0.069in !important; height: auto; white-space: nowrap; line-height: 1.0 !important; width: 1%;" ) html_output = ['<div id="table-payload" class="white-canvas" style="background-color: #ffffff; padding: 20px; border-radius: 8px; display: inline-block; width: 100%; box-sizing: border-box;">'] html_output = ['<div id="table-payload" class="white-canvas" style="background-color: #ffffff; padding: 20px; border-radius: 8px; display: inline-block; width: 100%; box-sizing: border-box; text-align: center;">'] table_chunks = calculate_dynamic_chunks(words_data, base_limit=7) for idx, current_chunk in enumerate(table_chunks):52 unmodified lines return f""" <div class="progress-container"> <img src="{gif_url}" width="40" height="40" style="margin: 0 auto 10px auto; display: block;" /> <p style="color: #ff6600; font-weight: bold; font-family: Arial; margin: 0 0 5px 0;">β³ Current Step: {step_text}...</p> <p style="color: #ffffff; font-family: monospace; font-size: 14px; margin: 0;">Elapsed Time: {elapsed}s</p> <p style="color: #2563eb; font-weight: bold; font-family: Arial; margin: 0 0 5px 0;">β³ Processing: {step_text}...</p> <p style="color: #64748b; font-family: sans-serif; font-size: 13px; margin: 0;">Elapsed Time: {elapsed}s</p> </div> """
46 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("Assembling inline CSS blocks and optimizing column bounds")), "", gr.update(visible=False) yield gr.update(visible=True, value=status_html("Structuring column dimensions and applying margins")), "", gr.update(visible=False) try: final_table_html = build_html_tables(manuscript_name, reference_header, raw_json_data)14 unmodified lines}"""
with gr.Blocks(css=custom_css) as demo: gr.Markdown("# Hebrew Interlinear Table Generator")with gr.Blocks(css=custom_css, title="Hebrew Interlinear Table Generator") as demo: gr.HTML( "<div style='background: linear-gradient(135deg, #1e3a8a 0%, #2563eb 100%); padding: 24px; border-radius: 12px; margin-bottom: 24px; color: white; text-align: center; box-shadow: 0 4px 6px -1px rgba(0,0,0,0.1);'>" "<h1 style='margin: 0 0 8px 0; font-size: 28px; font-weight: 700; color: white;'>π Hebrew Interlinear Table Generator</h1>" "<p style='margin: 0; font-size: 15px; opacity: 0.9;'>Convert raw Hebrew text into structured, publication-ready interlinear columns.</p>" "</div>" ) with gr.Accordion("π How to get your free Gemini API Key", open=False): with gr.Accordion("π How to find and paste your Gemini API key", open=True): gr.Markdown( "1. Go to [aistudio.google.com](https://aistudio.google.com/).\n" "2. Log in with any standard Google or Gmail account.\n" "3. Click the blue **'Get API key'** button in the top left.\n" "4. Click **'Create API key'**, choose a project, and copy your key token string." "1. Go to [Google AI Studio](https://aistudio.google.com/).\n" "2. Click **Get API Key** in the menu.\n" "3. Copy the **Default API Key** shown on the screen.\n" "4. Paste it into the **Gemini API Key** box below.\n\n" "πΊ **Need visual help?** Watch this [simple video tutorial](https://youtu.be/Uyn-P2nRvDA?si=_1NqPoJK-sHOVX-W)." ) with gr.Row(): with gr.Column(scale=4): gr.Markdown("### π οΈ Table Parameters") api_key_input = gr.Textbox(label="Gemini API Key", type="password", placeholder="Paste your personal Gemini API key here...") manuscript_input = gr.Textbox(label="Manuscript Name", value="Marseilles MS-24") book_input = gr.Textbox(label="Book Title", value="Luke") gr.Markdown("### π οΈ Step 1: Configure Reference Settings") api_key_input = gr.Textbox(label="π Gemini API Key", type="password", placeholder="Paste your default API key token here...") manuscript_input = gr.Textbox(label="π Manuscript Name", value="Marseilles MS-24") book_input = gr.Textbox(label="π Book Title", value="Luke") with gr.Row(): chapter_input = gr.Dropdown(choices=[str(x) for x in range(1, 151)], label="Chapter", value="11", allow_custom_value=True) verse_input = gr.Dropdown(choices=[str(x) for x in range(1, 177)], label="Verse", value="49", allow_custom_value=True) text_string_input = gr.Textbox(label="Hebrew Text String", placeholder="Paste your Hebrew text string here...", lines=3) chapter_input = gr.Dropdown(choices=[str(x) for x in range(1, 151)], label="Ch.", value="11", allow_custom_value=True) verse_input = gr.Dropdown(choices=[str(x) for x in range(1, 177)], label="Ver.", value="49", allow_custom_value=True) gr.Markdown("### π Step 2: Paste Hebrew Text") text_string_input = gr.Textbox(label="Hebrew Verses Input String", placeholder="Paste your raw Hebrew string text right here...", lines=3) with gr.Row(): submit_btn = gr.Button("Generate Table", variant="primary") submit_btn = gr.Button("π Generate Table", variant="primary") clear_btn = gr.Button("π§Ή Clear Text", variant="secondary") status_panel = gr.HTML(visible=False) gr.Markdown("### π Step 3: Output View & Copy Options") copy_btn = gr.Button("π Copy for Google Docs", variant="secondary", visible=False) output_html = gr.HTML(label="Generated Table") output_html = gr.HTML(label="Generated Output Table Grid Layout Canvas")
demo.load(fn=None, inputs=None, outputs=None, js=force_clean_layout_js)
submit_btn.click(fn=generate_table_code, inputs=[api_key_input, manuscript_input, book_input, chapter_input, verse_input, text_string_input], outputs=[status_panel, output_html, copy_btn], show_progress="hidden") submit_btn.click( fn=generate_table_code, inputs=[api_key_input, manuscript_input, book_input, chapter_input, verse_input, text_string_input], outputs=[status_panel, output_html, copy_btn], show_progress="hidden" ) clear_btn.click(fn=None, inputs=[], outputs=[text_string_input], js="() => ''") copy_btn.click(fn=None, js=copy_js)
if __name__ == "__main__": demo.queue().launch(server_name="0.0.0.0", server_port=7860)app.py+77-35