Skip to content

Commit

Permalink
ADDED: Authentication on text2image
Browse files Browse the repository at this point in the history
  • Loading branch information
AquibPy committed May 14, 2024
1 parent 6f35da2 commit cd3a92c
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion api.py
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,18 @@ async def ats(resume_pdf: UploadFile = File(...), job_description: str = Form(..
4. Stable_Diffusion_v2 - The latest version of Stable Diffusion, with improved performance and quality compared to the base version.
""")
def generate_image(prompt: str = Form("Astronaut riding a horse"), model: str = Form("Stable_Diffusion_base")):
def generate_image(prompt: str = Form("Astronaut riding a horse"), model: str = Form("Stable_Diffusion_base"),
token: str = Depends(oauth2_scheme)):
try:
payload = jwt.decode(token, os.getenv("TOKEN_SECRET_KEY"), algorithms=[settings.ALGORITHM])
email = payload.get("sub")
if email is None:
raise HTTPException(status_code=status.HTTP_401_UNAUTHORIZED, detail="Invalid token")
user = users_collection.find_one({"email": email})
if user is None:
raise HTTPException(status_code=status.HTTP_401_UNAUTHORIZED, detail="User not found")
except JWTError:
raise HTTPException(status_code=status.HTTP_401_UNAUTHORIZED, detail="Invalid token")
try:
if model in settings.diffusion_models:
def query(payload):
Expand Down

0 comments on commit cd3a92c

Please sign in to comment.