Spaces:
Runtime error
Runtime error
Commit
·
003c3a6
1
Parent(s):
d4a7c84
fix
Browse files
app.py
CHANGED
|
@@ -312,17 +312,6 @@ html_template = """
|
|
| 312 |
{% endif %}
|
| 313 |
</div>
|
| 314 |
<script>
|
| 315 |
-
function populateFormData() {
|
| 316 |
-
const userId = sessionStorage.getItem("user_id") || "";
|
| 317 |
-
const state = sessionStorage.getItem("state") || "";
|
| 318 |
-
|
| 319 |
-
document.getElementById("user_id").value = userId;
|
| 320 |
-
document.getElementById("state").value = state;
|
| 321 |
-
|
| 322 |
-
console.log(`original userId: ${userId}, state: ${state}`);
|
| 323 |
-
}
|
| 324 |
-
|
| 325 |
-
window.onload = populateFormData;
|
| 326 |
{{ script}}
|
| 327 |
</script>
|
| 328 |
</body>
|
|
@@ -362,7 +351,16 @@ def fix_markdown(text):
|
|
| 362 |
|
| 363 |
@app.get("/", response_class=HTMLResponse)
|
| 364 |
def form_get():
|
| 365 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 366 |
|
| 367 |
@app.post("/", response_class=HTMLResponse)
|
| 368 |
def form_post(request: Request,response: Response,topic: str = Form(...), user_id: str = Form(...), state: str = Form(...)):
|
|
@@ -377,23 +375,36 @@ def form_post(request: Request,response: Response,topic: str = Form(...), user_i
|
|
| 377 |
script_template = f"""
|
| 378 |
// 在页面加载时更新 sessionStorage
|
| 379 |
window.onload = function() {{
|
| 380 |
-
|
| 381 |
-
|
|
|
|
|
|
|
|
|
|
| 382 |
}};
|
| 383 |
"""
|
| 384 |
|
| 385 |
-
print(f"
|
| 386 |
loading_text = "Generating content, Usually takes 3-4 minutes, please wait..."
|
| 387 |
if state == "generate":
|
| 388 |
if not queue.empty():
|
| 389 |
queue_len = queue.qsize()
|
| 390 |
if queue_len + reply_count >= MAX_REPLIES_PER_DAY:
|
| 391 |
error_message = "Today's maximum number of replies has been reached. Please try again tomorrow."
|
| 392 |
-
return Template(html_template).render(idea="", error=error_message, reply_count=reply_count, button_text="Generate",loading_text=loading_text)
|
| 393 |
error_message = "There are currently {} requests being processed. If you want to queue, please write your original topic and click the Continue button and you will enter the queue.".format(queue_len)
|
| 394 |
new_state = "continue"
|
| 395 |
new_button_text = "Continue"
|
| 396 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 397 |
return Template(html_template).render(idea="", error=error_message, reply_count=reply_count, button_text=new_button_text,loading_text=f"Generating content, Usually takes {(queue_len+1)*3}-{(queue_len+1)*4} minutes, please wait...",script=script_template)
|
| 398 |
|
| 399 |
queue.put([user_id,topic])
|
|
@@ -405,10 +416,13 @@ def form_post(request: Request,response: Response,topic: str = Form(...), user_i
|
|
| 405 |
script_template = f"""
|
| 406 |
// 在页面加载时更新 sessionStorage
|
| 407 |
window.onload = function() {{
|
| 408 |
-
|
| 409 |
-
|
|
|
|
|
|
|
|
|
|
| 410 |
}};
|
| 411 |
-
"""
|
| 412 |
print(f"current2 user_id={user_id}, state={new_state}")
|
| 413 |
# 判断当前是否轮到该用户,如果没轮到则一直等待到轮到为止
|
| 414 |
while queue.queue[0] != [user_id,topic]:
|
|
|
|
| 312 |
{% endif %}
|
| 313 |
</div>
|
| 314 |
<script>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 315 |
{{ script}}
|
| 316 |
</script>
|
| 317 |
</body>
|
|
|
|
| 351 |
|
| 352 |
@app.get("/", response_class=HTMLResponse)
|
| 353 |
def form_get():
|
| 354 |
+
script_template = """
|
| 355 |
+
window.onload = function() {
|
| 356 |
+
document.getElementById("user_id").value = "";
|
| 357 |
+
document.getElementById("state").value = "";
|
| 358 |
+
let userId = document.getElementById("user_id").value;
|
| 359 |
+
let state = document.getElementById("state").value;
|
| 360 |
+
console.log(`0 User ID: ${userId}, State: ${state}`);
|
| 361 |
+
}
|
| 362 |
+
"""
|
| 363 |
+
return Template(html_template).render(idea= "This is a example of the idea geneartion", error=None, reply_count=reply_count,button_text="Generate",loading_text="Generating content, Usually takes 3-4 minutes, please wait...",script=script_template)
|
| 364 |
|
| 365 |
@app.post("/", response_class=HTMLResponse)
|
| 366 |
def form_post(request: Request,response: Response,topic: str = Form(...), user_id: str = Form(...), state: str = Form(...)):
|
|
|
|
| 375 |
script_template = f"""
|
| 376 |
// 在页面加载时更新 sessionStorage
|
| 377 |
window.onload = function() {{
|
| 378 |
+
document.getElementById("user_id").value = {user_id};
|
| 379 |
+
document.getElementById("state").value = {state};
|
| 380 |
+
let userId = document.getElementById("user_id").value;
|
| 381 |
+
let state = document.getElementById("state").value;
|
| 382 |
+
console.log(`1 User ID: ${{userId}}, State: ${{state}}`);
|
| 383 |
}};
|
| 384 |
"""
|
| 385 |
|
| 386 |
+
print(f"current0 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():
|
| 390 |
queue_len = queue.qsize()
|
| 391 |
if queue_len + reply_count >= MAX_REPLIES_PER_DAY:
|
| 392 |
error_message = "Today's maximum number of replies has been reached. Please try again tomorrow."
|
| 393 |
+
return Template(html_template).render(idea="", error=error_message, reply_count=reply_count, button_text="Generate",loading_text=loading_text,script=script_template)
|
| 394 |
error_message = "There are currently {} requests being processed. If you want to queue, please write your original topic and click the Continue button and you will enter the queue.".format(queue_len)
|
| 395 |
new_state = "continue"
|
| 396 |
new_button_text = "Continue"
|
| 397 |
+
script_template = f"""
|
| 398 |
+
// 在页面加载时更新 sessionStorage
|
| 399 |
+
window.onload = function() {{
|
| 400 |
+
document.getElementById("user_id").value = {user_id};
|
| 401 |
+
document.getElementById("state").value = {new_state};
|
| 402 |
+
let userId = document.getElementById("user_id").value;
|
| 403 |
+
let state = document.getElementById("state").value;
|
| 404 |
+
console.log(`2 User ID: ${{userId}}, State: ${{state}}`);
|
| 405 |
+
}};
|
| 406 |
+
"""
|
| 407 |
+
print(f"current1 user_id={user_id}, state={new_state}")
|
| 408 |
return Template(html_template).render(idea="", error=error_message, reply_count=reply_count, button_text=new_button_text,loading_text=f"Generating content, Usually takes {(queue_len+1)*3}-{(queue_len+1)*4} minutes, please wait...",script=script_template)
|
| 409 |
|
| 410 |
queue.put([user_id,topic])
|
|
|
|
| 416 |
script_template = f"""
|
| 417 |
// 在页面加载时更新 sessionStorage
|
| 418 |
window.onload = function() {{
|
| 419 |
+
document.getElementById("user_id").value = {user_id};
|
| 420 |
+
document.getElementById("state").value = {new_state};
|
| 421 |
+
let userId = document.getElementById("user_id").value;
|
| 422 |
+
let state = document.getElementById("state").value;
|
| 423 |
+
console.log(`3 User ID: ${{userId}}, State: ${{state}}`);
|
| 424 |
}};
|
| 425 |
+
"""
|
| 426 |
print(f"current2 user_id={user_id}, state={new_state}")
|
| 427 |
# 判断当前是否轮到该用户,如果没轮到则一直等待到轮到为止
|
| 428 |
while queue.queue[0] != [user_id,topic]:
|