Spaces:
Sleeping
Sleeping
Update main.py
Browse files
main.py
CHANGED
|
@@ -1,4 +1,4 @@
|
|
| 1 |
-
from fastapi import FastAPI, Depends
|
| 2 |
from fastapi.middleware.cors import CORSMiddleware
|
| 3 |
from pydantic import BaseModel
|
| 4 |
from huggingface_hub import InferenceClient
|
|
@@ -61,10 +61,7 @@ async def generate_text(item: Item, token: Annotated[str, Depends(oauth2_scheme)
|
|
| 61 |
# Reject if not authenticated
|
| 62 |
apiKey = os.environ.get("API_KEY")
|
| 63 |
if apiKey != token:
|
| 64 |
-
|
| 65 |
-
"message": "Not authenticated",
|
| 66 |
-
"token": token
|
| 67 |
-
}
|
| 68 |
|
| 69 |
return {
|
| 70 |
"response": generate(item)
|
|
|
|
| 1 |
+
from fastapi import FastAPI, Depends, HTTPException
|
| 2 |
from fastapi.middleware.cors import CORSMiddleware
|
| 3 |
from pydantic import BaseModel
|
| 4 |
from huggingface_hub import InferenceClient
|
|
|
|
| 61 |
# Reject if not authenticated
|
| 62 |
apiKey = os.environ.get("API_KEY")
|
| 63 |
if apiKey != token:
|
| 64 |
+
raise HTTPException(status_code=403, detail="Invalid API key")
|
|
|
|
|
|
|
|
|
|
| 65 |
|
| 66 |
return {
|
| 67 |
"response": generate(item)
|