Spaces:
Runtime error
Runtime error
| 1import gradio as gr | |
| import asyncio | |
| import os | |
| from playwright.async_api import async_playwright | |
| # Playwright ke liye browser binary set karna (Hugging Face Docker compatibility ke liye) | |
| os.system("playwright install chromium") | |
| async def get_admit_card(form_no): | |
| if not form_no or len(form_no) < 5: | |
| return None, "β Bhai, valid Form Number dalo!" | |
| pdf_path = f"AdmitCard_{form_no}.pdf" | |
| async with async_playwright() as p: | |
| try: | |
| # Low-resource sandbox bypass for Hugging Face | |
| browser = await p.chromium.launch( | |
| headless=True, | |
| args=['--no-sandbox', '--disable-setuid-sandbox', '--disable-dev-shm-usage'] | |
| ) | |
| context = await browser.new_context( | |
| user_agent='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36' | |
| ) | |
| page = await context.new_page() | |
| url = "https://erp.jnvuiums.in/Exam/Pre_Exam/Exam_ForALL_AdmitCard.aspx" | |
| await page.goto(url, wait_until="domcontentloaded", timeout=60000) | |
| # Form input fill karna | |
| await page.fill("#txtchallanNo", str(form_no)) | |
| await page.press("#txtchallanNo", "Enter") | |
| await asyncio.sleep(1.5) # Wait for state sync | |
| # Download click handler | |
| async with page.expect_download(timeout=45000) as download_info: | |
| await page.click("#btnGetResult") | |
| download = await download_info.value | |
| await download.save_as(pdf_path) | |
| await browser.close() | |
| if os.path.exists(pdf_path): | |
| return pdf_path, "β Badhai ho! Admit Card mil gaya. Niche se download karein." | |
| else: | |
| return None, "β File save nahi ho payi. Ek baar phir try karein." | |
| except Exception as e: | |
| if 'browser' in locals(): | |
| await browser.close() | |
| return None, f"β οΈ Error: Admit card nahi mila. Form number check karein ya site down ho sakti hai." | |
| # Custom HTML Interface Wrapper | |
| html_layout = """ | |
| <div style="text-align: center; max-width: 600px; margin: 0 auto; padding: 20px; font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;"> | |
| <h1 style="color: #ff4b4b; margin-bottom: 5px;">π© RajasthaniBoyz Admit Card Downloader π©</h1> | |
| <p style="color: #555; margin-bottom: 25px;">Apna JNVU Form Number dalo aur ek click mein PDF paao!</p> | |
| </div> | |
| """ | |
| with gr.Blocks(css=".gradio-container {background-color: #f9f9f9;}") as demo: | |
| gr.HTML(html_layout) | |
| with gr.Row(): | |
| with gr.Column(scale=1): | |
| form_input = gr.Textbox(label="Enter Form Number / Challan No.", placeholder="Eg: 12873762", max_lines=1) | |
| btn = gr.Button("π Get Admit Card", variant="primary") | |
| with gr.Column(scale=1): | |
| status_output = gr.Markdown(value="β¨ Status yahan dikhega...") | |
| file_output = gr.File(label="π₯ Download PDF Here") | |
| btn.click(fn=get_admit_card, inputs=form_input, outputs=[file_output, status_output]) | |
| demo.launch() | |