Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,6 +2,7 @@ import os
|
|
| 2 |
from fastapi import FastAPI, Request, HTTPException
|
| 3 |
import uvicorn
|
| 4 |
from gradio_client import Client
|
|
|
|
| 5 |
|
| 6 |
# Keys
|
| 7 |
VALID_API_KEY = os.getenv("APP_API_KEY") # for your FastAPI security
|
|
@@ -24,8 +25,12 @@ async def chat(request: Request):
|
|
| 24 |
raise HTTPException(status_code=403, detail="Invalid API Key")
|
| 25 |
|
| 26 |
user_message = data.get("message")
|
| 27 |
-
#
|
| 28 |
-
user_id = data.get("user_id")
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
|
| 30 |
if not user_message:
|
| 31 |
raise HTTPException(status_code=400, detail="Message is required")
|
|
@@ -40,7 +45,7 @@ async def chat(request: Request):
|
|
| 40 |
)
|
| 41 |
|
| 42 |
|
| 43 |
-
return {"response": result}
|
| 44 |
|
| 45 |
if __name__ == "__main__":
|
| 46 |
uvicorn.run(app, host="0.0.0.0", port=7860)
|
|
|
|
| 2 |
from fastapi import FastAPI, Request, HTTPException
|
| 3 |
import uvicorn
|
| 4 |
from gradio_client import Client
|
| 5 |
+
import uuid
|
| 6 |
|
| 7 |
# Keys
|
| 8 |
VALID_API_KEY = os.getenv("APP_API_KEY") # for your FastAPI security
|
|
|
|
| 25 |
raise HTTPException(status_code=403, detail="Invalid API Key")
|
| 26 |
|
| 27 |
user_message = data.get("message")
|
| 28 |
+
# Check for user_id in the request data, generate one if not present
|
| 29 |
+
user_id = data.get("user_id")
|
| 30 |
+
if not user_id:
|
| 31 |
+
user_id = str(uuid.uuid4()) # Generate a unique ID if none is provided
|
| 32 |
+
print(f"Generated user_id: {user_id} for this request.")
|
| 33 |
+
|
| 34 |
|
| 35 |
if not user_message:
|
| 36 |
raise HTTPException(status_code=400, detail="Message is required")
|
|
|
|
| 45 |
)
|
| 46 |
|
| 47 |
|
| 48 |
+
return {"response": result, "user_id": user_id} # Return the user_id so the client can potentially reuse it
|
| 49 |
|
| 50 |
if __name__ == "__main__":
|
| 51 |
uvicorn.run(app, host="0.0.0.0", port=7860)
|