eli02 commited on
Commit
986afef
·
1 Parent(s): e8df1d7

Refactor index endpoint to use Path for file path resolution and adjust static file mount point name

Browse files
Files changed (1) hide show
  1. main.py +5 -2
main.py CHANGED
@@ -6,11 +6,13 @@ from pydantic import BaseModel
6
  from jose import JWTError, jwt
7
  from datetime import datetime, timedelta
8
  from openai import OpenAI
 
9
  from typing import List
10
  import pandas as pd
11
  import os
12
  import logging
13
 
 
14
  # Configure logging
15
  logging.basicConfig(level=logging.INFO)
16
 
@@ -123,7 +125,8 @@ class TokenResponse(BaseModel):
123
  # Root endpoint
124
  @app.get("/")
125
  def index() -> FileResponse:
126
- return FileResponse(path="static/index.html", media_type="text/html")
 
127
 
128
  # Login endpoint to issue tokens
129
  @app.post("/login", response_model=TokenResponse)
@@ -177,7 +180,7 @@ def search(
177
 
178
  return results
179
 
180
- app.mount("/home", StaticFiles(directory="static", html=True), name="static")
181
 
182
  # Run the app
183
  if __name__ == "__main__":
 
6
  from jose import JWTError, jwt
7
  from datetime import datetime, timedelta
8
  from openai import OpenAI
9
+ from pathlib import Path
10
  from typing import List
11
  import pandas as pd
12
  import os
13
  import logging
14
 
15
+
16
  # Configure logging
17
  logging.basicConfig(level=logging.INFO)
18
 
 
125
  # Root endpoint
126
  @app.get("/")
127
  def index() -> FileResponse:
128
+ file_path = Path(__file__).parent / "static" / "index.html"
129
+ return FileResponse(path=str(file_path), media_type="text/html")
130
 
131
  # Login endpoint to issue tokens
132
  @app.post("/login", response_model=TokenResponse)
 
180
 
181
  return results
182
 
183
+ app.mount("/home", StaticFiles(directory="static", html=True), name="home")
184
 
185
  # Run the app
186
  if __name__ == "__main__":