Spaces:
Running
Running
jianghuyihei
commited on
Commit
•
81b2a65
1
Parent(s):
f985a01
fix
Browse files- __pycache__/app.cpython-310.pyc +0 -0
- app.py +24 -24
__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
@@ -108,6 +108,7 @@ html_template = """
|
|
108 |
color: #007bff;
|
109 |
animation: fadeIn 0.5s ease-in-out;
|
110 |
text-align: center;
|
|
|
111 |
}
|
112 |
.time-counter-container {
|
113 |
display: flex;
|
@@ -298,7 +299,7 @@ html_template = """
|
|
298 |
<button onclick="fillTopic('Using LLM-based agent to generate idea')">Using LLM-based agent to generate idea</button>
|
299 |
</div>
|
300 |
</div>
|
301 |
-
<div id="loading" class="loading"
|
302 |
{% if error %}
|
303 |
<div class="error">
|
304 |
<div class="box">
|
@@ -309,19 +310,17 @@ html_template = """
|
|
309 |
{% endif %}
|
310 |
</div>
|
311 |
<script>
|
312 |
-
|
313 |
-
|
314 |
-
|
315 |
-
|
316 |
-
|
317 |
-
|
318 |
-
|
319 |
-
|
320 |
-
|
321 |
-
|
322 |
-
|
323 |
-
}
|
324 |
-
window.onload = getUserId;
|
325 |
</script>
|
326 |
</body>
|
327 |
</html>
|
@@ -361,25 +360,23 @@ def fix_markdown(text):
|
|
361 |
async def add_user_id_and_state_cookie(request: Request, call_next):
|
362 |
user_id = request.cookies.get("user_id")
|
363 |
state = request.cookies.get("state")
|
364 |
-
|
|
|
365 |
if not user_id:
|
366 |
user_id = str(uuid.uuid4())
|
367 |
state = "generate"
|
368 |
-
response = await call_next(request)
|
369 |
response.set_cookie(key="user_id", value=user_id)
|
370 |
response.set_cookie(key="state", value=state)
|
371 |
elif not state:
|
372 |
state = "generate"
|
373 |
-
response = await call_next(request)
|
374 |
response.set_cookie(key="state", value=state)
|
375 |
-
else:
|
376 |
-
response = await call_next(request)
|
377 |
-
|
378 |
return response
|
379 |
|
380 |
@app.get("/user_id")
|
381 |
-
async def get_user_id():
|
382 |
-
user_id =
|
|
|
|
|
383 |
return {"user_id": user_id}
|
384 |
|
385 |
|
@@ -393,9 +390,12 @@ def form_post(request: Request,response: Response,topic: str = Form(...)):
|
|
393 |
start_time = time.time()
|
394 |
|
395 |
# 获得每个网页的user_id
|
396 |
-
user_id = request.cookies.get("user_id")
|
397 |
state = request.cookies.get("state", "generate")
|
398 |
|
|
|
|
|
|
|
399 |
print(user_id,state)
|
400 |
loading_text = "Generating content, Usually takes 2-3 minutes, please wait..."
|
401 |
if state == "generate":
|
@@ -404,7 +404,7 @@ def form_post(request: Request,response: Response,topic: str = Form(...)):
|
|
404 |
if queue_len + reply_count >= MAX_REPLIES_PER_DAY:
|
405 |
error_message = "Today's maximum number of replies has been reached. Please try again tomorrow."
|
406 |
return Template(html_template).render(idea="", error=error_message, reply_count=reply_count, button_text="Generate",loading_text=loading_text)
|
407 |
-
error_message = "There are currently {} requests being processed. If you want to queue, please click the Continue button and you will enter the queue.".format(queue_len)
|
408 |
new_state = "continue"
|
409 |
new_button_text = "Continue"
|
410 |
response.set_cookie(key="state", value=new_state)
|
|
|
108 |
color: #007bff;
|
109 |
animation: fadeIn 0.5s ease-in-out;
|
110 |
text-align: center;
|
111 |
+
display: none;
|
112 |
}
|
113 |
.time-counter-container {
|
114 |
display: flex;
|
|
|
299 |
<button onclick="fillTopic('Using LLM-based agent to generate idea')">Using LLM-based agent to generate idea</button>
|
300 |
</div>
|
301 |
</div>
|
302 |
+
<div id="loading" class="loading">{{ loading_text }}</div>
|
303 |
{% if error %}
|
304 |
<div class="error">
|
305 |
<div class="box">
|
|
|
310 |
{% endif %}
|
311 |
</div>
|
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>
|
325 |
</body>
|
326 |
</html>
|
|
|
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 |
+
response = await call_next(request)
|
364 |
+
|
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 |
return response
|
374 |
|
375 |
@app.get("/user_id")
|
376 |
+
async def get_user_id(request: Request):
|
377 |
+
user_id = request.cookies.get("user_id")
|
378 |
+
if not user_id:
|
379 |
+
user_id = str(uuid.uuid4())
|
380 |
return {"user_id": user_id}
|
381 |
|
382 |
|
|
|
390 |
start_time = time.time()
|
391 |
|
392 |
# 获得每个网页的user_id
|
393 |
+
user_id = request.cookies.get("user_id", str(uuid.uuid4()))
|
394 |
state = request.cookies.get("state", "generate")
|
395 |
|
396 |
+
response.set_cookie(key="user_id", value=user_id)
|
397 |
+
response.set_cookie(key="state", value=state)
|
398 |
+
|
399 |
print(user_id,state)
|
400 |
loading_text = "Generating content, Usually takes 2-3 minutes, please wait..."
|
401 |
if state == "generate":
|
|
|
404 |
if queue_len + reply_count >= MAX_REPLIES_PER_DAY:
|
405 |
error_message = "Today's maximum number of replies has been reached. Please try again tomorrow."
|
406 |
return Template(html_template).render(idea="", error=error_message, reply_count=reply_count, button_text="Generate",loading_text=loading_text)
|
407 |
+
error_message = "There are currently {} requests being processed. If you want to queue, please rewrite your topic and click the Continue button and you will enter the queue.".format(queue_len)
|
408 |
new_state = "continue"
|
409 |
new_button_text = "Continue"
|
410 |
response.set_cookie(key="state", value=new_state)
|