Pep1900 commited on
Commit
ff79521
·
verified ·
1 Parent(s): 910360b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -4
app.py CHANGED
@@ -1,6 +1,7 @@
1
  import os
2
  from fastapi import FastAPI, Header, HTTPException
3
  from transformers import pipeline
 
4
 
5
  import os
6
 
@@ -17,13 +18,17 @@ sentiment_model = pipeline(
17
  app = FastAPI(title="Sentiment Analysis API")
18
 
19
  # Модель запроса
20
- #class TextRequest(BaseModel):
21
- # text: str
22
 
23
  # Эндпоинт для анализа
24
  @app.post("/analyze")
25
- def analyze_sentiment(request: str, x_api_key: str = Header(...)):
26
  #if x_api_key != SECRET_KEY:
27
  # raise HTTPException(status_code=401, detail="Invalid API Key")
28
  result = sentiment_model(request.text)
29
- return {"result": result}
 
 
 
 
 
1
  import os
2
  from fastapi import FastAPI, Header, HTTPException
3
  from transformers import pipeline
4
+ from pydantic import BaseModel
5
 
6
  import os
7
 
 
18
  app = FastAPI(title="Sentiment Analysis API")
19
 
20
  # Модель запроса
21
+ class TextRequest(BaseModel):
22
+ text: str
23
 
24
  # Эндпоинт для анализа
25
  @app.post("/analyze")
26
+ def analyze_sentiment(request: TextRequest, x_api_key: str = Header(...)):
27
  #if x_api_key != SECRET_KEY:
28
  # raise HTTPException(status_code=401, detail="Invalid API Key")
29
  result = sentiment_model(request.text)
30
+ return {"result": result}
31
+
32
+ @app.get("/hello")
33
+ def hello_world():
34
+ return {"message": "Hello World"}