Spaces:
Runtime error
Runtime error
Update app.py
Browse files
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 |
-
|
| 21 |
-
|
| 22 |
|
| 23 |
# Эндпоинт для анализа
|
| 24 |
@app.post("/analyze")
|
| 25 |
-
def analyze_sentiment(request:
|
| 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"}
|