Spaces:
Sleeping
Sleeping
File size: 2,509 Bytes
77da9e2 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
"""
Gradio UI Server Entry Point
Starts the Gradio web interface for UI element detection.
IMPORTANT: The API server must be running for this to work!
Usage:
# Terminal 1: Start API server
python app_api.py
# Terminal 2: Start UI server
python app_ui.py
The UI will be available at:
- Gradio Interface: http://localhost:7860
Configuration:
Set environment variables to customize:
- CU1_API_URL: API endpoint (default: http://localhost:8000)
- GRADIO_SERVER_NAME: Server host (default: 0.0.0.0)
- GRADIO_SERVER_PORT: Server port (default: 7860)
- GRADIO_SHARE: Enable sharing (default: false)
"""
import os
os.environ['PYTORCH_ENABLE_MPS_FALLBACK'] = '1'
from ui.gradio_interface import create_gradio_interface
def main():
"""Start the Gradio UI server"""
api_url = os.getenv("CU1_API_URL", "http://localhost:8000")
print("=" * 70)
print("🎨 CU-1 UI Element Detector - Gradio UI")
print("=" * 70)
print("\n⚠️ IMPORTANT: Make sure the API server is running!")
print(" If not started, run in another terminal:")
print(" python app_api.py")
print(f"\n🔗 API Connection: {api_url}")
print(" Change with: export CU1_API_URL=http://your-api:8000")
print("\n📱 Gradio Interface: http://localhost:7860")
print("\n🏗️ Architecture:")
print(" This UI is a CLIENT of the API (service-oriented)")
print(" All detection logic runs in the API server")
print(" UI communicates via HTTP/REST")
print("=" * 70 + "\n")
demo = create_gradio_interface()
# Read configuration from environment
server_name = os.getenv("GRADIO_SERVER_NAME", "0.0.0.0")
port_env = os.getenv("GRADIO_SERVER_PORT") or os.getenv("PORT")
server_port = int(port_env) if port_env and port_env.isdigit() else 7860
share_env = os.getenv("GRADIO_SHARE", "false").lower()
share = share_env in {"1", "true", "yes", "y"}
try:
demo.queue().launch(
server_name=server_name,
server_port=server_port,
share=share
)
except OSError as e:
if "Cannot find empty port" in str(e):
print(f"\n⚠️ Port {server_port} is busy, trying to find a free port...")
demo.queue().launch(
server_name=server_name,
server_port=None, # Auto-select free port
share=share
)
else:
raise
if __name__ == "__main__":
main()
|