AurelioAguirre commited on
Commit
daae8cc
·
1 Parent(s): 4598698

Fixing dockerfile v6

Browse files
Files changed (2) hide show
  1. Dockerfile +1 -1
  2. src/main.py +22 -8
Dockerfile CHANGED
@@ -17,4 +17,4 @@ COPY --chown=user src/ /app/src
17
  EXPOSE 7860
18
 
19
  # Command to run the application
20
- CMD ["python", "-m", "src.main"]
 
17
  EXPOSE 7860
18
 
19
  # Command to run the application
20
+ CMD ["uvicorn", "src.main:app", "--host", "0.0.0.0", "--port", "7860"]
src/main.py CHANGED
@@ -5,6 +5,7 @@ import litserve as ls
5
  import yaml
6
  import logging
7
  from pathlib import Path
 
8
  from .routes import router, init_router
9
  from api import InferenceApi
10
 
@@ -22,8 +23,8 @@ def load_config():
22
  with open(config_path) as f:
23
  return yaml.safe_load(f)
24
 
25
- def main():
26
- """Main function to set up and run the inference server."""
27
  logger = setup_logging()
28
 
29
  try:
@@ -42,18 +43,31 @@ def main():
42
  track_requests=True
43
  )
44
 
 
 
 
 
 
 
 
 
 
45
  # Add our routes to the server's FastAPI app
46
  server.app.include_router(router, prefix="/api/v1")
47
 
48
- # Get port from config or use default
49
- port = config.get("server", {}).get("port", 8001)
50
-
51
- logger.info(f"Starting server on port {port}")
52
- server.run(port=port)
53
 
54
  except Exception as e:
55
  logger.error(f"Server initialization failed: {str(e)}")
56
  raise
57
 
 
 
 
58
  if __name__ == "__main__":
59
- main()
 
 
 
 
 
 
5
  import yaml
6
  import logging
7
  from pathlib import Path
8
+ from fastapi.middleware.cors import CORSMiddleware
9
  from .routes import router, init_router
10
  from api import InferenceApi
11
 
 
23
  with open(config_path) as f:
24
  return yaml.safe_load(f)
25
 
26
+ def create_app():
27
+ """Create and configure the application instance."""
28
  logger = setup_logging()
29
 
30
  try:
 
43
  track_requests=True
44
  )
45
 
46
+ # Add CORS middleware
47
+ server.app.add_middleware(
48
+ CORSMiddleware,
49
+ allow_origins=["*"], # Allows all origins
50
+ allow_credentials=True,
51
+ allow_methods=["*"], # Allows all methods
52
+ allow_headers=["*"], # Allows all headers
53
+ )
54
+
55
  # Add our routes to the server's FastAPI app
56
  server.app.include_router(router, prefix="/api/v1")
57
 
58
+ return server.app
 
 
 
 
59
 
60
  except Exception as e:
61
  logger.error(f"Server initialization failed: {str(e)}")
62
  raise
63
 
64
+ # Create the application instance
65
+ app = create_app()
66
+
67
  if __name__ == "__main__":
68
+ # If we run this directly with python, we can still use the old method
69
+ config = load_config()
70
+ port = config.get("server", {}).get("port", 8001)
71
+
72
+ # Get the server instance from our app and run it
73
+ app.parent.run(port=port) # assuming the LitServer instance is stored as parent