Nihar Shah commited on
Commit
c3f60df
Β·
1 Parent(s): ac2fb20

Fix: Update entry point for HF Spaces - use hf_spaces_run.py directly

Browse files
Files changed (3) hide show
  1. Dockerfile +2 -1
  2. app.py +10 -2
  3. hf_spaces_run.py +34 -0
Dockerfile CHANGED
@@ -17,6 +17,7 @@ RUN pip install --no-cache-dir -r requirements.txt
17
  COPY app/ ./app/
18
  COPY openenv.yaml .
19
  COPY app.py .
 
20
 
21
  # Expose port 7860 for Hugging Face Spaces
22
  EXPOSE 7860
@@ -26,4 +27,4 @@ HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
26
  CMD python -c "import urllib.request; urllib.request.urlopen('http://localhost:7860/health')" || exit 1
27
 
28
  # Run FastAPI app on port 7860 for HF Spaces compatibility
29
- CMD ["python", "-m", "uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "7860"]
 
17
  COPY app/ ./app/
18
  COPY openenv.yaml .
19
  COPY app.py .
20
+ COPY hf_spaces_run.py .
21
 
22
  # Expose port 7860 for Hugging Face Spaces
23
  EXPOSE 7860
 
27
  CMD python -c "import urllib.request; urllib.request.urlopen('http://localhost:7860/health')" || exit 1
28
 
29
  # Run FastAPI app on port 7860 for HF Spaces compatibility
30
+ CMD ["python", "hf_spaces_run.py"]
app.py CHANGED
@@ -1,7 +1,7 @@
1
  #!/usr/bin/env python3
2
  """
3
  FastAPI application entry point for Hugging Face Spaces.
4
- This is the main app that Hugging Face Spaces will run.
5
  """
6
 
7
  import sys
@@ -11,9 +11,17 @@ from pathlib import Path
11
  # Ensure app module can be imported
12
  sys.path.insert(0, str(Path(__file__).parent))
13
 
 
14
  from app.main import app
15
 
16
- # This is the entry point that HF Spaces looks for
 
 
 
 
 
 
 
17
  if __name__ == "__main__":
18
  import uvicorn
19
  # HF Spaces uses port 7860 by default
 
1
  #!/usr/bin/env python3
2
  """
3
  FastAPI application entry point for Hugging Face Spaces.
4
+ This is the main app that HuggingFace Spaces will import and run.
5
  """
6
 
7
  import sys
 
11
  # Ensure app module can be imported
12
  sys.path.insert(0, str(Path(__file__).parent))
13
 
14
+ # Import the FastAPI app from app.main
15
  from app.main import app
16
 
17
+ # Export the app for HF Spaces to discover
18
+ __all__ = ['app']
19
+
20
+ # This is the entry point that HF Spaces looks for when it imports this file
21
+ if __name__ == "__main__":
22
+ import uvicorn
23
+ # HF Spaces uses port 7860 by default
24
+ uvicorn.run(app, host="0.0.0.0", port=7860)
25
  if __name__ == "__main__":
26
  import uvicorn
27
  # HF Spaces uses port 7860 by default
hf_spaces_run.py ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ """
3
+ HuggingFace Spaces runner script.
4
+ This script is used when deploying to HF Spaces.
5
+ It starts the FastAPI app with uvicorn on port 7860.
6
+ """
7
+
8
+ import sys
9
+ import os
10
+ from pathlib import Path
11
+
12
+ # Ensure the app module can be imported
13
+ sys.path.insert(0, str(Path(__file__).parent))
14
+
15
+ def main():
16
+ """Main entry point for HF Spaces."""
17
+ import uvicorn
18
+ from app.main import app
19
+
20
+ print("πŸš€ Starting OpenEnv CRM Query Environment on port 7860...")
21
+ print("πŸ“ Binding to 0.0.0.0:7860")
22
+ print("πŸ“š API Documentation: http://localhost:7860/docs")
23
+ print("πŸ” ReDoc Documentation: http://localhost:7860/redoc")
24
+
25
+ uvicorn.run(
26
+ app,
27
+ host="0.0.0.0",
28
+ port=7860,
29
+ log_level="info",
30
+ access_log=True,
31
+ )
32
+
33
+ if __name__ == "__main__":
34
+ main()