Revathi2006/document_ai_pdf
0
1import threading2import requests3import gradio as gr4import os5 6# === Start your existing backend in a separate thread ===7def start_backend():8 import uvicorn9 uvicorn.run("backend:app", host="0.0.0.0", port=int(os.environ.get("PORT", 8000)))10 11threading.Thread(target=start_backend, daemon=True).start()12 13# === Minimal Gradio frontend to ping backend ===14def ping_backend():15 try:16 r = requests.get("http://127.0.0.1:8000/health", timeout=5)17 return r.json()18 except Exception as e:19 return str(e)20 21with gr.Blocks() as demo:22 gr.Markdown("## DOC AI — FastAPI Backend Test")23 gr.Button("Ping Backend").click(ping_backend, [], gr.JSON(label="Backend Response"))24 25demo.launch()26 