Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,5 +1,5 @@
|
|
| 1 |
from fastapi import FastAPI, HTTPException, Depends, status
|
| 2 |
-
from fastapi.security import HTTPBearer
|
| 3 |
from pydantic import BaseModel
|
| 4 |
from transformers import pipeline
|
| 5 |
import gradio as gr
|
|
@@ -34,13 +34,13 @@ class EnhanceRequest(BaseModel):
|
|
| 34 |
class EnhanceResponse(BaseModel):
|
| 35 |
enhanced_prompt: str
|
| 36 |
|
| 37 |
-
def verify_api_key(
|
| 38 |
-
if
|
| 39 |
raise HTTPException(
|
| 40 |
status_code=status.HTTP_401_UNAUTHORIZED,
|
| 41 |
detail="Invalid API key"
|
| 42 |
)
|
| 43 |
-
return
|
| 44 |
|
| 45 |
@app.post("/enhance", response_model=EnhanceResponse)
|
| 46 |
async def enhance_prompt(request: EnhanceRequest, api_key: str = Depends(verify_api_key)):
|
|
|
|
| 1 |
from fastapi import FastAPI, HTTPException, Depends, status
|
| 2 |
+
from fastapi.security import HTTPBearer
|
| 3 |
from pydantic import BaseModel
|
| 4 |
from transformers import pipeline
|
| 5 |
import gradio as gr
|
|
|
|
| 34 |
class EnhanceResponse(BaseModel):
|
| 35 |
enhanced_prompt: str
|
| 36 |
|
| 37 |
+
def verify_api_key(credentials = Depends(security)):
|
| 38 |
+
if credentials.credentials != API_KEY:
|
| 39 |
raise HTTPException(
|
| 40 |
status_code=status.HTTP_401_UNAUTHORIZED,
|
| 41 |
detail="Invalid API key"
|
| 42 |
)
|
| 43 |
+
return credentials.credentials
|
| 44 |
|
| 45 |
@app.post("/enhance", response_model=EnhanceResponse)
|
| 46 |
async def enhance_prompt(request: EnhanceRequest, api_key: str = Depends(verify_api_key)):
|