Spaces:
Sleeping
Sleeping
Upload 2 files
Browse files- Dockerfile +6 -4
- app.py +30 -5
Dockerfile
CHANGED
|
@@ -39,10 +39,12 @@ ENV PORT=7860
|
|
| 39 |
|
| 40 |
EXPOSE 7860
|
| 41 |
|
|
|
|
|
|
|
|
|
|
| 42 |
# Health check hits the FastAPI /health endpoint
|
| 43 |
-
HEALTHCHECK --interval=30s --timeout=10s --start-period=
|
| 44 |
CMD curl -fsS http://127.0.0.1:7860/health || exit 1
|
| 45 |
|
| 46 |
-
#
|
| 47 |
-
CMD ["python", "
|
| 48 |
-
"--host", "0.0.0.0", "--port", "7860"]
|
|
|
|
| 39 |
|
| 40 |
EXPOSE 7860
|
| 41 |
|
| 42 |
+
ENV GRADIO_SERVER_NAME=0.0.0.0
|
| 43 |
+
ENV GRADIO_SERVER_PORT=7860
|
| 44 |
+
|
| 45 |
# Health check hits the FastAPI /health endpoint
|
| 46 |
+
HEALTHCHECK --interval=30s --timeout=10s --start-period=60s --retries=3 \
|
| 47 |
CMD curl -fsS http://127.0.0.1:7860/health || exit 1
|
| 48 |
|
| 49 |
+
# Combined mode: Gradio UI at /ui + OpenEnv API at / (reset, step, state, health)
|
| 50 |
+
CMD ["python", "app.py", "--hf"]
|
|
|
app.py
CHANGED
|
@@ -729,9 +729,34 @@ with gr.Blocks(title="AutoDataLab — E-commerce Data Analyst") as demo:
|
|
| 729 |
if __name__ == "__main__":
|
| 730 |
import argparse
|
| 731 |
ap = argparse.ArgumentParser()
|
| 732 |
-
ap.add_argument("--share",
|
| 733 |
-
ap.add_argument("--port",
|
| 734 |
-
ap.add_argument("--host",
|
|
|
|
| 735 |
args = ap.parse_args()
|
| 736 |
-
|
| 737 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 729 |
if __name__ == "__main__":
|
| 730 |
import argparse
|
| 731 |
ap = argparse.ArgumentParser()
|
| 732 |
+
ap.add_argument("--share", action="store_true")
|
| 733 |
+
ap.add_argument("--port", type=int, default=7861)
|
| 734 |
+
ap.add_argument("--host", default="0.0.0.0")
|
| 735 |
+
ap.add_argument("--hf", action="store_true", help="HF Spaces mode: mount OpenEnv API + Gradio on same port")
|
| 736 |
args = ap.parse_args()
|
| 737 |
+
|
| 738 |
+
hf_mode = args.hf or os.environ.get("SPACE_ID") is not None # auto-detect HF Spaces
|
| 739 |
+
|
| 740 |
+
if hf_mode:
|
| 741 |
+
# Mount Gradio UI on top of the OpenEnv FastAPI app so both work on port 7860
|
| 742 |
+
import uvicorn
|
| 743 |
+
from data_cleaning_env.models import DataCleaningAction, DataCleaningObservation
|
| 744 |
+
from data_cleaning_env.server.data_cleaning_env_environment import DataCleaningEnvironment
|
| 745 |
+
try:
|
| 746 |
+
from openenv.core.env_server.http_server import create_app as create_openenv_app
|
| 747 |
+
openenv_fastapi = create_openenv_app(
|
| 748 |
+
DataCleaningEnvironment, DataCleaningAction, DataCleaningObservation,
|
| 749 |
+
env_name="data_cleaning_env",
|
| 750 |
+
)
|
| 751 |
+
# Mount Gradio at /ui; OpenEnv API stays at root (/, /reset, /step, /state, /health)
|
| 752 |
+
combined_app = gr.mount_gradio_app(openenv_fastapi, demo, path="/ui", css=CSS)
|
| 753 |
+
print("Running combined OpenEnv API + Gradio UI on port 7860")
|
| 754 |
+
print(" API: http://0.0.0.0:7860/health")
|
| 755 |
+
print(" UI: http://0.0.0.0:7860/ui")
|
| 756 |
+
uvicorn.run(combined_app, host="0.0.0.0", port=7860)
|
| 757 |
+
except Exception as e:
|
| 758 |
+
print(f"[warn] Could not mount OpenEnv app ({e}), falling back to Gradio-only")
|
| 759 |
+
demo.launch(server_name="0.0.0.0", server_port=7860, share=False, css=CSS)
|
| 760 |
+
else:
|
| 761 |
+
demo.launch(server_name=args.host, server_port=args.port,
|
| 762 |
+
share=args.share, inbrowser=not args.share, css=CSS)
|