Spaces:
Runtime error
Runtime error
Commit
·
d22849a
1
Parent(s):
97a5f88
fix
Browse files
app.py
CHANGED
|
@@ -227,6 +227,11 @@ html_template = """
|
|
| 227 |
startTime = Date.now();
|
| 228 |
intervalId = setInterval(updateTime, 100);
|
| 229 |
progressIntervalId = setInterval(updateProgressBar, 100);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 230 |
}
|
| 231 |
function hideLoading() {
|
| 232 |
document.getElementById("loading").style.display = "none";
|
|
@@ -302,14 +307,12 @@ html_template = """
|
|
| 302 |
</div>
|
| 303 |
</div>
|
| 304 |
{% endif %}
|
| 305 |
-
</div>
|
| 306 |
-
<script>
|
| 307 |
hideLoading();
|
|
|
|
| 308 |
<script>
|
| 309 |
async function getUserId() {
|
| 310 |
// 清除 sessionStorage 中的 user_id
|
| 311 |
sessionStorage.removeItem("user_id");
|
| 312 |
-
|
| 313 |
// 请求新的 user_id
|
| 314 |
const response = await fetch("/user_id");
|
| 315 |
const data = await response.json();
|
|
@@ -317,7 +320,6 @@ html_template = """
|
|
| 317 |
sessionStorage.setItem("user_id", userId);
|
| 318 |
console.log("User ID:", userId);
|
| 319 |
}
|
| 320 |
-
|
| 321 |
window.onload = getUserId;
|
| 322 |
</script>
|
| 323 |
</body>
|
|
@@ -335,7 +337,24 @@ scheduler.add_job(reset_counter, 'cron', hour=0, minute=0)
|
|
| 335 |
scheduler.start()
|
| 336 |
|
| 337 |
queue = Queue()
|
| 338 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 339 |
|
| 340 |
@app.middleware("http")
|
| 341 |
async def add_user_id_and_state_cookie(request: Request, call_next):
|
|
@@ -418,8 +437,8 @@ def form_post(request: Request,response: Response,topic: str = Form(...)):
|
|
| 418 |
print(f"begin to generate idea of topic {topic}")
|
| 419 |
idea, related_experiments, entities, idea_chain, ideas, trend, future, human, year = deep_research_agent.generate_idea_with_chain(topic)
|
| 420 |
|
| 421 |
-
idea = idea
|
| 422 |
-
|
| 423 |
# 更新每日回复次数
|
| 424 |
reply_count += 1
|
| 425 |
end_time = time.time()
|
|
|
|
| 227 |
startTime = Date.now();
|
| 228 |
intervalId = setInterval(updateTime, 100);
|
| 229 |
progressIntervalId = setInterval(updateProgressBar, 100);
|
| 230 |
+
// 隐藏错误消息
|
| 231 |
+
const errorBox = document.querySelector(".error");
|
| 232 |
+
if (errorBox) {
|
| 233 |
+
errorBox.style.display = "none";
|
| 234 |
+
}
|
| 235 |
}
|
| 236 |
function hideLoading() {
|
| 237 |
document.getElementById("loading").style.display = "none";
|
|
|
|
| 307 |
</div>
|
| 308 |
</div>
|
| 309 |
{% endif %}
|
|
|
|
|
|
|
| 310 |
hideLoading();
|
| 311 |
+
</div>
|
| 312 |
<script>
|
| 313 |
async function getUserId() {
|
| 314 |
// 清除 sessionStorage 中的 user_id
|
| 315 |
sessionStorage.removeItem("user_id");
|
|
|
|
| 316 |
// 请求新的 user_id
|
| 317 |
const response = await fetch("/user_id");
|
| 318 |
const data = await response.json();
|
|
|
|
| 320 |
sessionStorage.setItem("user_id", userId);
|
| 321 |
console.log("User ID:", userId);
|
| 322 |
}
|
|
|
|
| 323 |
window.onload = getUserId;
|
| 324 |
</script>
|
| 325 |
</body>
|
|
|
|
| 337 |
scheduler.start()
|
| 338 |
|
| 339 |
queue = Queue()
|
| 340 |
+
def fix_markdown(text):
|
| 341 |
+
lines = text.split('\n')
|
| 342 |
+
# Initialize the result list
|
| 343 |
+
result = []
|
| 344 |
+
|
| 345 |
+
# Iterate through the lines
|
| 346 |
+
for i, line in enumerate(lines):
|
| 347 |
+
# Check if the current line starts with a numbered list item
|
| 348 |
+
numbers = ['1.', '2.', '3.', '4.', '5.', '6.', '7.', '8.', '9.', '10.', '11.', '12.', '13.', '14.', '15.', '16.', '17.', '18.', '19.', '20.','21.','22.','23.','24.','25.','26.','27.','28.','29.','30.']
|
| 349 |
+
if line.lstrip().startswith(tuple(numbers)):
|
| 350 |
+
# If it's not the first line and the previous line is not blank, add a blank line
|
| 351 |
+
if i > 0 and lines[i - 1].strip():
|
| 352 |
+
result.append('')
|
| 353 |
+
# Append the current line to the result
|
| 354 |
+
result.append(line)
|
| 355 |
+
|
| 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):
|
|
|
|
| 437 |
print(f"begin to generate idea of topic {topic}")
|
| 438 |
idea, related_experiments, entities, idea_chain, ideas, trend, future, human, year = deep_research_agent.generate_idea_with_chain(topic)
|
| 439 |
|
| 440 |
+
idea = fix_markdown(idea)
|
| 441 |
+
idea = markdown.markdown(idea)
|
| 442 |
# 更新每日回复次数
|
| 443 |
reply_count += 1
|
| 444 |
end_time = time.time()
|