Update app.py
Browse files
app.py
CHANGED
|
@@ -1,4 +1,4 @@
|
|
| 1 |
-
from fastapi import FastAPI, HTTPException, Depends
|
| 2 |
from fastapi.security import HTTPBearer
|
| 3 |
from pydantic import BaseModel
|
| 4 |
from transformers import GPT2LMHeadModel, GPT2TokenizerFast, GPT2Config
|
|
@@ -69,9 +69,15 @@ def classify_text(sentence: str):
|
|
| 69 |
@app.post("/analyze")
|
| 70 |
async def analyze_text(data: TextInput, token: str = Depends(bearer_scheme)):
|
| 71 |
user_input = data.text.strip()
|
|
|
|
| 72 |
if not user_input:
|
| 73 |
raise HTTPException(status_code=400, detail="Text cannot be empty")
|
| 74 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 75 |
# The token is automatically extracted from the Authorization header
|
| 76 |
# You can validate the token here if needed
|
| 77 |
print(f"Received Bearer Token: {token}")
|
|
|
|
| 1 |
+
from fastapi import FastAPI, HTTPException, Depends
|
| 2 |
from fastapi.security import HTTPBearer
|
| 3 |
from pydantic import BaseModel
|
| 4 |
from transformers import GPT2LMHeadModel, GPT2TokenizerFast, GPT2Config
|
|
|
|
| 69 |
@app.post("/analyze")
|
| 70 |
async def analyze_text(data: TextInput, token: str = Depends(bearer_scheme)):
|
| 71 |
user_input = data.text.strip()
|
| 72 |
+
|
| 73 |
if not user_input:
|
| 74 |
raise HTTPException(status_code=400, detail="Text cannot be empty")
|
| 75 |
+
|
| 76 |
+
# Check if there are at least two words
|
| 77 |
+
word_count = len(user_input.split())
|
| 78 |
+
if word_count < 2:
|
| 79 |
+
raise HTTPException(status_code=400, detail="Text must contain at least two words")
|
| 80 |
+
|
| 81 |
# The token is automatically extracted from the Authorization header
|
| 82 |
# You can validate the token here if needed
|
| 83 |
print(f"Received Bearer Token: {token}")
|