Voffchik commited on
Commit
116a867
·
verified ·
1 Parent(s): c7c5efc

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -10
app.py CHANGED
@@ -7,8 +7,8 @@ from contextlib import asynccontextmanager
7
 
8
  @asynccontextmanager
9
  async def lifespan(app: FastAPI):
10
- global classifier
11
- classifier = pipeline("sentiment-analysis")
12
  yield
13
 
14
  app = FastAPI(lifespan=lifespan)
@@ -16,14 +16,12 @@ app = FastAPI(lifespan=lifespan)
16
  class TextRequest(BaseModel):
17
  text: str
18
 
19
- @app.post("/request")
20
- async def analyze(request: TextRequest):
21
  try:
22
- result = classifier(request.text)[0]
23
- return {
24
- "text": request.text,
25
- "sentiment": result['label'],
26
- "confidence": round(result['score'], 4)
27
- }
28
  except Exception as e:
29
  return {"error": str(e)}
 
7
 
8
  @asynccontextmanager
9
  async def lifespan(app: FastAPI):
10
+ global needModel
11
+ needModel = pipeline("...")
12
  yield
13
 
14
  app = FastAPI(lifespan=lifespan)
 
16
  class TextRequest(BaseModel):
17
  text: str
18
 
19
+ @app.post("/message")
20
+ async def model(request: TextRequest):
21
  try:
22
+ # result = needModel(request.text)[0]
23
+ result = {
24
+ "text": "hi from api!"}
25
+ return result
 
 
26
  except Exception as e:
27
  return {"error": str(e)}