Stephen Zweibel
Use Gemini native PDF structured extraction
072b034
# This file is for Hugging Face Spaces deployment
# It simply imports and runs the main app
import os
import tempfile
from cv_extraction_app import app
import logging
# Configure logging
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
# Report environment configuration. Key normalization happens in cv_extraction_app.
if os.environ.get('GOOGLE_API_KEY') or os.environ.get('GEMINI_API_KEY'):
logging.info("Gemini API key is set")
else:
logging.warning("Gemini API key is not set")
if os.environ.get('APP_PASSWORD'):
logging.info("APP_PASSWORD is set")
else:
logging.warning("APP_PASSWORD is not set")
logging.info(
"Gemini runtime config: model=%s timeout=%ss file_ready_timeout=%ss thinking=%s temperature=%s",
os.environ.get("GEMINI_MODEL", "gemini-3-flash-preview"),
os.environ.get("GEMINI_TIMEOUT_SECONDS", "120"),
os.environ.get("GEMINI_FILE_READY_TIMEOUT_SECONDS", "60"),
os.environ.get("GEMINI_THINKING_LEVEL", "high"),
os.environ.get("GEMINI_TEMPERATURE", "default"),
)
def get_launch_kwargs():
"""Configure Gradio launch settings for both Spaces and Cloud Run."""
kwargs = {
"share": False,
# CSV exports are written to the process temp directory before Gradio serves them.
"allowed_paths": [tempfile.gettempdir()],
}
port = os.environ.get("PORT")
if port:
kwargs["server_name"] = "0.0.0.0"
kwargs["server_port"] = int(port)
return kwargs
# Launch the app with settings that work on Spaces and Cloud Run
if __name__ == "__main__":
launch_kwargs = get_launch_kwargs()
logging.info(
"Launching Gradio app with server_name=%s server_port=%s allowed_paths=%s",
launch_kwargs.get("server_name", "default"),
launch_kwargs.get("server_port", "default"),
launch_kwargs.get("allowed_paths", []),
)
app.launch(**launch_kwargs)