AurelioAguirre commited on
Commit
840a4e4
·
1 Parent(s): 801882a

trying again

Browse files
Files changed (1) hide show
  1. main/main.py +33 -5
main/main.py CHANGED
@@ -13,7 +13,16 @@ from huggingface_hub.hf_api import HfApi
13
  logging.basicConfig(level=logging.INFO)
14
  logger = logging.getLogger(__name__)
15
 
16
- app = FastAPI(title="LLM Engine Service")
 
 
 
 
 
 
 
 
 
17
 
18
  # Global variable to store the LLM instance
19
  llm_instance = None
@@ -37,6 +46,20 @@ class GenerateRequest(BaseModel):
37
  return_as_token_ids: bool = False
38
  stream: bool = False
39
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
40
  @app.post("/initialize")
41
  async def initialize_model(request: InitializeRequest):
42
  """
@@ -167,12 +190,17 @@ async def health_check():
167
  def main():
168
  # Load environment variables or configuration here
169
  host = os.getenv("LLM_ENGINE_HOST", "0.0.0.0")
170
- port = int(os.getenv("LLM_ENGINE_PORT", "8001"))
 
 
 
 
 
 
 
 
171
 
172
  # Start the server
173
- hf_a = HfApi()
174
- space_info = hf_a.space_info("TeamGenKI/LLM-Engine")
175
- logger.warning(f"Exposing URL: {space_info}")
176
  uvicorn.run(
177
  app,
178
  host=host,
 
13
  logging.basicConfig(level=logging.INFO)
14
  logger = logging.getLogger(__name__)
15
 
16
+ # Initialize FastAPI with root path for Spaces
17
+ app = FastAPI(
18
+ title="LLM Engine Service",
19
+ # This is crucial for Hugging Face Spaces
20
+ root_path="/",
21
+ # Add OpenAPI configs
22
+ openapi_url="/api/openapi.json",
23
+ docs_url="/api/docs",
24
+ redoc_url="/api/redoc"
25
+ )
26
 
27
  # Global variable to store the LLM instance
28
  llm_instance = None
 
46
  return_as_token_ids: bool = False
47
  stream: bool = False
48
 
49
+ @app.get("/")
50
+ async def root():
51
+ """Root endpoint to verify service is running"""
52
+ space_url = "https://teamgenki-llm-engine.hf.space"
53
+ return {
54
+ "status": "running",
55
+ "service": "LLM Engine",
56
+ "endpoints": {
57
+ "initialize": f"{space_url}/initialize",
58
+ "generate": f"{space_url}/generate",
59
+ "health": f"{space_url}/health"
60
+ }
61
+ }
62
+
63
  @app.post("/initialize")
64
  async def initialize_model(request: InitializeRequest):
65
  """
 
190
  def main():
191
  # Load environment variables or configuration here
192
  host = os.getenv("LLM_ENGINE_HOST", "0.0.0.0")
193
+ port = int(os.getenv("LLM_ENGINE_PORT", "7860")) # Changed to 7860 for Spaces
194
+
195
+ # Log the service URLs
196
+ space_url = "https://teamgenki-llm-engine.hf.space"
197
+ logger.info(f"Service will be available at: {space_url}")
198
+ logger.info(f"API endpoints:")
199
+ logger.info(f" Initialize: {space_url}/initialize")
200
+ logger.info(f" Generate: {space_url}/generate")
201
+ logger.info(f" Health: {space_url}/health")
202
 
203
  # Start the server
 
 
 
204
  uvicorn.run(
205
  app,
206
  host=host,