Spaces:
Running
Running
jianghuyihei
commited on
Commit
•
9b426fc
1
Parent(s):
003c3a6
fix
Browse files
app.py
CHANGED
@@ -349,18 +349,21 @@ def fix_markdown(text):
|
|
349 |
return '<br>'.join(result)
|
350 |
|
351 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
352 |
@app.get("/", response_class=HTMLResponse)
|
353 |
def form_get():
|
354 |
-
|
355 |
-
|
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(...)):
|
@@ -372,16 +375,7 @@ def form_post(request: Request,response: Response,topic: str = Form(...), user_i
|
|
372 |
if state == "":
|
373 |
state = "generate"
|
374 |
|
375 |
-
script_template =
|
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..."
|
@@ -390,39 +384,20 @@ def form_post(request: Request,response: Response,topic: str = Form(...), user_i
|
|
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=
|
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 =
|
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=
|
409 |
|
410 |
queue.put([user_id,topic])
|
411 |
new_state = "generate"
|
412 |
new_button_text = "Generate"
|
413 |
-
response.set_cookie(key="state", value=new_state)
|
414 |
queue_len = queue.qsize()
|
415 |
|
416 |
-
script_template =
|
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]:
|
@@ -459,4 +434,4 @@ def form_post(request: Request,response: Response,topic: str = Form(...), user_i
|
|
459 |
error_message = str(e)
|
460 |
# 从队列中移除当前用户
|
461 |
queue.get()
|
462 |
-
return Template(html_template).render(idea=idea, error=error_message, reply_count=reply_count, time_taken=time_taken,button_text=new_button_text,loading_text=loading_text,script=
|
|
|
349 |
return '<br>'.join(result)
|
350 |
|
351 |
|
352 |
+
script_template = """
|
353 |
+
function setstate() {
|
354 |
+
document.getElementById("user_id").value = {user_id};
|
355 |
+
document.getElementById("state").value = {state};
|
356 |
+
let userId = document.getElementById("user_id").value;
|
357 |
+
let state = document.getElementById("state").value;
|
358 |
+
console.log(`1 User ID: ${{userId}}, State: ${{state}}`);
|
359 |
+
}
|
360 |
+
window.onload = setstate();
|
361 |
+
"""
|
362 |
+
|
363 |
@app.get("/", response_class=HTMLResponse)
|
364 |
def form_get():
|
365 |
+
script = script_template.format(user_id="''", state="''")
|
366 |
+
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)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
367 |
|
368 |
@app.post("/", response_class=HTMLResponse)
|
369 |
def form_post(request: Request,response: Response,topic: str = Form(...), user_id: str = Form(...), state: str = Form(...)):
|
|
|
375 |
if state == "":
|
376 |
state = "generate"
|
377 |
|
378 |
+
script = script_template.format(user_id=user_id, state=state)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
379 |
|
380 |
print(f"current0 user_id={user_id}, state={state}")
|
381 |
loading_text = "Generating content, Usually takes 3-4 minutes, please wait..."
|
|
|
384 |
queue_len = queue.qsize()
|
385 |
if queue_len + reply_count >= MAX_REPLIES_PER_DAY:
|
386 |
error_message = "Today's maximum number of replies has been reached. Please try again tomorrow."
|
387 |
+
return Template(html_template).render(idea="", error=error_message, reply_count=reply_count, button_text="Generate",loading_text=loading_text,script=script)
|
388 |
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)
|
389 |
new_state = "continue"
|
390 |
new_button_text = "Continue"
|
391 |
+
script = script_template.format(user_id=user_id, state=new_state)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
392 |
print(f"current1 user_id={user_id}, state={new_state}")
|
393 |
+
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)
|
394 |
|
395 |
queue.put([user_id,topic])
|
396 |
new_state = "generate"
|
397 |
new_button_text = "Generate"
|
|
|
398 |
queue_len = queue.qsize()
|
399 |
|
400 |
+
script = script_template.format(user_id=user_id, state=new_state)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
401 |
print(f"current2 user_id={user_id}, state={new_state}")
|
402 |
# 判断当前是否轮到该用户,如果没轮到则一直等待到轮到为止
|
403 |
while queue.queue[0] != [user_id,topic]:
|
|
|
434 |
error_message = str(e)
|
435 |
# 从队列中移除当前用户
|
436 |
queue.get()
|
437 |
+
return Template(html_template).render(idea=idea, error=error_message, reply_count=reply_count, time_taken=time_taken,button_text=new_button_text,loading_text=loading_text,script=script)
|