bibibi12345 commited on
Commit
fb8624f
·
1 Parent(s): 3e8f7f6
Files changed (3) hide show
  1. Dockerfile +4 -5
  2. app.py +6 -7
  3. requirements.txt +3 -2
Dockerfile CHANGED
@@ -20,8 +20,7 @@ EXPOSE 7860
20
  # Define environment variable
21
  ENV NAME World
22
 
23
- # Run app.py when the container launches
24
- # Use gunicorn for a more robust production server (optional, but recommended)
25
- # CMD ["gunicorn", "--bind", "0.0.0.0:7860", "app:app"]
26
- # Fallback to Flask's built-in server for simplicity
27
- CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
 
20
  # Define environment variable
21
  ENV NAME World
22
 
23
+ # Run the application with Uvicorn
24
+ # For Hugging Face Spaces compatibility, we use the module:app format
25
+ # and specify port 7860
26
+ CMD ["python", "-m", "uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
 
app.py CHANGED
@@ -50,10 +50,9 @@ async def handle_request(request: Request):
50
 
51
  return JSONResponse(content={"status": "success", "message": "Request received and logged."}, status_code=200)
52
 
53
- # The following block is typically not needed when running with Uvicorn via CLI,
54
- # but can be useful for direct execution (e.g., local debugging).
55
- # Hugging Face Spaces will use the CMD in the Dockerfile.
56
- # if __name__ == "__main__":
57
- # # Default Uvicorn port is 8000, suitable for many environments.
58
- # # Use 0.0.0.0 to be accessible externally.
59
- # uvicorn.run(app, host="0.0.0.0", port=8000)
 
50
 
51
  return JSONResponse(content={"status": "success", "message": "Request received and logged."}, status_code=200)
52
 
53
+ # This block allows direct execution of the app for local debugging
54
+ # and ensures compatibility with Hugging Face Spaces
55
+ if __name__ == "__main__":
56
+ # Hugging Face Spaces expects the app on port 7860
57
+ # Using 0.0.0.0 to be accessible externally
58
+ uvicorn.run("app:app", host="0.0.0.0", port=7860, log_level="info")
 
requirements.txt CHANGED
@@ -1,2 +1,3 @@
1
- fastapi
2
- uvicorn[standard]
 
 
1
+ fastapi==0.104.1
2
+ uvicorn[standard]==0.23.2
3
+ pydantic==2.4.2