Spaces:
Runtime error
Runtime error
Commit
·
d2fc417
1
Parent(s):
a28c21c
fix
Browse files- __pycache__/app.cpython-310.pyc +0 -0
- app.py +4 -18
__pycache__/app.cpython-310.pyc
CHANGED
|
Binary files a/__pycache__/app.cpython-310.pyc and b/__pycache__/app.cpython-310.pyc differ
|
|
|
app.py
CHANGED
|
@@ -312,13 +312,14 @@ html_template = """
|
|
| 312 |
<script>
|
| 313 |
async function getUserId() {
|
| 314 |
let userId = sessionStorage.getItem("user_id");
|
|
|
|
| 315 |
if (!userId) {
|
| 316 |
const response = await fetch("/user_id");
|
| 317 |
const data = await response.json();
|
| 318 |
userId = data.user_id;
|
| 319 |
sessionStorage.setItem("user_id", userId);
|
| 320 |
}
|
| 321 |
-
console.log("User ID:", userId);
|
| 322 |
}
|
| 323 |
window.onload = getUserId;
|
| 324 |
</script>
|
|
@@ -356,28 +357,13 @@ def fix_markdown(text):
|
|
| 356 |
# Join the result list into a single string with newline characters
|
| 357 |
return '<br>'.join(result)
|
| 358 |
|
| 359 |
-
@app.middleware("http")
|
| 360 |
-
async def add_user_id_and_state_cookie(request: Request, call_next):
|
| 361 |
-
user_id = request.cookies.get("user_id")
|
| 362 |
-
state = request.cookies.get("state")
|
| 363 |
-
print(f"Before call_next: user_id={user_id}, state={state}")
|
| 364 |
-
response = await call_next(request)
|
| 365 |
-
if not user_id:
|
| 366 |
-
user_id = str(uuid.uuid4())
|
| 367 |
-
state = "generate"
|
| 368 |
-
response.set_cookie(key="user_id", value=user_id)
|
| 369 |
-
response.set_cookie(key="state", value=state)
|
| 370 |
-
elif not state:
|
| 371 |
-
state = "generate"
|
| 372 |
-
response.set_cookie(key="state", value=state)
|
| 373 |
-
print(f"After call_next: user_id={user_id}, state={state}")
|
| 374 |
-
return response
|
| 375 |
|
| 376 |
@app.get("/user_id")
|
| 377 |
async def get_user_id(request: Request):
|
| 378 |
user_id = request.cookies.get("user_id")
|
| 379 |
if not user_id:
|
| 380 |
user_id = str(uuid.uuid4())
|
|
|
|
| 381 |
return {"user_id": user_id}
|
| 382 |
|
| 383 |
|
|
@@ -397,7 +383,7 @@ def form_post(request: Request,response: Response,topic: str = Form(...)):
|
|
| 397 |
response.set_cookie(key="user_id", value=user_id)
|
| 398 |
response.set_cookie(key="state", value=state)
|
| 399 |
|
| 400 |
-
print(user_id,state)
|
| 401 |
loading_text = "Generating content, Usually takes 3-4 minutes, please wait..."
|
| 402 |
if state == "generate":
|
| 403 |
if not queue.empty():
|
|
|
|
| 312 |
<script>
|
| 313 |
async function getUserId() {
|
| 314 |
let userId = sessionStorage.getItem("user_id");
|
| 315 |
+
console.log("original User ID:", userId);
|
| 316 |
if (!userId) {
|
| 317 |
const response = await fetch("/user_id");
|
| 318 |
const data = await response.json();
|
| 319 |
userId = data.user_id;
|
| 320 |
sessionStorage.setItem("user_id", userId);
|
| 321 |
}
|
| 322 |
+
console.log("set User ID:", userId);
|
| 323 |
}
|
| 324 |
window.onload = getUserId;
|
| 325 |
</script>
|
|
|
|
| 357 |
# Join the result list into a single string with newline characters
|
| 358 |
return '<br>'.join(result)
|
| 359 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 360 |
|
| 361 |
@app.get("/user_id")
|
| 362 |
async def get_user_id(request: Request):
|
| 363 |
user_id = request.cookies.get("user_id")
|
| 364 |
if not user_id:
|
| 365 |
user_id = str(uuid.uuid4())
|
| 366 |
+
print("successfully set user_id = ", user_id)
|
| 367 |
return {"user_id": user_id}
|
| 368 |
|
| 369 |
|
|
|
|
| 383 |
response.set_cookie(key="user_id", value=user_id)
|
| 384 |
response.set_cookie(key="state", value=state)
|
| 385 |
|
| 386 |
+
print(f"current user_id={user_id}, state={state}")
|
| 387 |
loading_text = "Generating content, Usually takes 3-4 minutes, please wait..."
|
| 388 |
if state == "generate":
|
| 389 |
if not queue.empty():
|