Agent_PDF / app.py
Ag27 Deployer
Deploy Ag27 Table Extractor: 2026-04-29 19:38:38
df4a1a2
"""
Hugging Face Spaces entry point for Ag27 Table Extractor.
This wraps the FastAPI app to be compatible with HF Spaces.
"""
import os
import sys
import subprocess
# Ensure we use the correct port for HF Spaces
port = int(os.environ.get("PORT", 7860))
host = "0.0.0.0"
# Try to import and run the FastAPI app
if __name__ == "__main__":
# Build the frontend if not already built
web_dist = os.path.join(os.path.dirname(__file__), "web", "dist")
if not os.path.exists(web_dist):
print("Building frontend...")
# Check if package.json exists
web_dir = os.path.join(os.path.dirname(__file__), "web")
if not os.path.exists(os.path.join(web_dir, "package.json")):
print("❌ web/package.json not found!")
sys.exit(1)
result = subprocess.run(
["npm", "--prefix", "web", "install"],
cwd=os.path.dirname(__file__),
)
if result.returncode != 0:
print("Frontend npm install failed")
sys.exit(1)
result = subprocess.run(
["npm", "--prefix", "web", "run", "build"],
cwd=os.path.dirname(__file__),
)
if result.returncode != 0:
print("Frontend build failed")
sys.exit(1)
print(f"βœ… Frontend ready at {web_dist}")
# Import and run the FastAPI app
import uvicorn
from server import app
print(f"πŸš€ Starting Ag27 Table Extractor on {host}:{port}")
uvicorn.run(app, host=host, port=port)