santanche commited on
Commit
274c132
·
1 Parent(s): 84a6308

fix (server): paths adjusted

Browse files
Files changed (1) hide show
  1. app/server_sentiment_analysis.py +14 -3
app/server_sentiment_analysis.py CHANGED
@@ -1,6 +1,10 @@
1
  from fastapi import FastAPI, HTTPException
2
  from fastapi.responses import RedirectResponse
3
  from fastapi.middleware.cors import CORSMiddleware
 
 
 
 
4
 
5
  # Import the SentimentAnalysis class
6
  from sentiment_analysis import SentimentAnalysis
@@ -18,10 +22,14 @@ app.add_middleware(
18
  # Create a global instance of SentimentAnalysis
19
  classifier = SentimentAnalysis()
20
 
21
- # Redirect root to /docs
22
  @app.get("/")
23
- async def redirect_to_docs():
24
- return RedirectResponse(url="/docs")
 
 
 
 
 
25
 
26
  @app.get("/classify")
27
  async def classify(text: str):
@@ -30,3 +38,6 @@ async def classify(text: str):
30
  return result
31
  except Exception as e:
32
  raise HTTPException(status_code=500, detail=str(e)) from e
 
 
 
 
1
  from fastapi import FastAPI, HTTPException
2
  from fastapi.responses import RedirectResponse
3
  from fastapi.middleware.cors import CORSMiddleware
4
+ from fastapi.responses import FileResponse
5
+ from fastapi.staticfiles import StaticFiles
6
+ import uvicorn
7
+ import os
8
 
9
  # Import the SentimentAnalysis class
10
  from sentiment_analysis import SentimentAnalysis
 
22
  # Create a global instance of SentimentAnalysis
23
  classifier = SentimentAnalysis()
24
 
 
25
  @app.get("/")
26
+ def root():
27
+ return RedirectResponse(url="/editor/")
28
+
29
+ @app.get("/editor/")
30
+ def get_editor():
31
+ print(os.path.join("static", "editor", "index.html"))
32
+ return FileResponse(os.path.join("static", "editor", "index.html"))
33
 
34
  @app.get("/classify")
35
  async def classify(text: str):
 
38
  return result
39
  except Exception as e:
40
  raise HTTPException(status_code=500, detail=str(e)) from e
41
+
42
+ if __name__ == "__main__":
43
+ uvicorn.run(app, host="0.0.0.0", port=8000)