Spaces:
Running
Running
jianghuyihei
commited on
Commit
•
867ffb5
1
Parent(s):
f3b97a0
fix
Browse files
app.py
CHANGED
@@ -329,7 +329,7 @@ html_template = """
|
|
329 |
<div class="example-topics">
|
330 |
<button onclick="fillTopic('Realistic Image Synthesis in Medical Imaging')">Realistic Image Synthesis in Medical Imaging</button>
|
331 |
<button onclick="fillTopic('Using diffusion to generate road layout')">Using diffusion to generate road layout</button>
|
332 |
-
<button onclick="fillTopic('Using LLM-based agent to generate
|
333 |
</div>
|
334 |
</div>
|
335 |
<div id="loading" class="loading">{{ loading_text }}</div>
|
@@ -433,40 +433,45 @@ def form_post(topic: str = Form(...), user_id: str = Form(...), state: str = For
|
|
433 |
script = script_template.format(user_id=user_id, state=new_state)
|
434 |
print(f"current2 user_id={user_id}, state={new_state}")
|
435 |
# 判断当前是否轮到该用户,如果没轮到则一直等待到轮到为止
|
436 |
-
print(
|
437 |
while queue.queue[0] != [user_id,topic]:
|
438 |
time.sleep(10)
|
439 |
continue
|
440 |
-
|
441 |
-
user_id, topic = queue.get()
|
442 |
-
with lock:
|
443 |
-
logging.info(f"Processing request for topic: {topic}")
|
444 |
-
start_time = time.time()
|
445 |
-
error_message = None
|
446 |
-
idea = ""
|
447 |
-
time_taken = 0
|
448 |
-
# 检查是否超过每日最大回复次数
|
449 |
-
if reply_count >= MAX_REPLIES_PER_DAY:
|
450 |
-
error_message = "Today's maximum number of replies has been reached. Please try again tomorrow."
|
451 |
-
logging.info(f"Today's maximum number of replies has been reached. Please try again tomorrow.")
|
452 |
-
try:
|
453 |
-
main_llm, cheap_llm = get_llms()
|
454 |
-
deep_research_agent = DeepResearchAgent(llm=main_llm, cheap_llm=cheap_llm, improve_cnt=1, max_chain_length=5, min_chain_length=3, max_chain_numbers=1)
|
455 |
-
print(f"begin to generate idea of topic {topic}")
|
456 |
-
idea, related_experiments, entities, idea_chain, ideas, trend, future, human, year = deep_research_agent.generate_idea_with_chain(topic)
|
457 |
|
458 |
-
|
459 |
-
|
460 |
-
|
461 |
-
|
462 |
-
|
463 |
-
|
464 |
-
|
465 |
-
|
466 |
-
|
467 |
-
|
468 |
-
|
469 |
-
|
470 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
471 |
queue.get()
|
472 |
-
return Template(html_template).render(idea=
|
|
|
329 |
<div class="example-topics">
|
330 |
<button onclick="fillTopic('Realistic Image Synthesis in Medical Imaging')">Realistic Image Synthesis in Medical Imaging</button>
|
331 |
<button onclick="fillTopic('Using diffusion to generate road layout')">Using diffusion to generate road layout</button>
|
332 |
+
<button onclick="fillTopic('Using LLM-based agent to generate research ideas')">Using LLM-based agent to generate research ideas</button>
|
333 |
</div>
|
334 |
</div>
|
335 |
<div id="loading" class="loading">{{ loading_text }}</div>
|
|
|
433 |
script = script_template.format(user_id=user_id, state=new_state)
|
434 |
print(f"current2 user_id={user_id}, state={new_state}")
|
435 |
# 判断当前是否轮到该用户,如果没轮到则一直等待到轮到为止
|
436 |
+
print(queue.queue[0], [user_id,topic])
|
437 |
while queue.queue[0] != [user_id,topic]:
|
438 |
time.sleep(10)
|
439 |
continue
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
440 |
|
441 |
+
try:
|
442 |
+
with lock:
|
443 |
+
logging.info(f"Processing request for topic: {topic}")
|
444 |
+
start_time = time.time()
|
445 |
+
error_message = None
|
446 |
+
idea = ""
|
447 |
+
time_taken = 0
|
448 |
+
# 检查是否超过每日最大回复次数
|
449 |
+
if reply_count >= MAX_REPLIES_PER_DAY:
|
450 |
+
error_message = "Today's maximum number of replies has been reached. Please try again tomorrow."
|
451 |
+
logging.info(f"Today's maximum number of replies has been reached. Please try again tomorrow.")
|
452 |
+
try:
|
453 |
+
main_llm, cheap_llm = get_llms()
|
454 |
+
deep_research_agent = DeepResearchAgent(llm=main_llm, cheap_llm=cheap_llm, improve_cnt=1, max_chain_length=5, min_chain_length=3, max_chain_numbers=1)
|
455 |
+
print(f"begin to generate idea of topic {topic}")
|
456 |
+
idea, related_experiments, entities, idea_chain, ideas, trend, future, human, year = deep_research_agent.generate_idea_with_chain(topic)
|
457 |
+
|
458 |
+
idea = fix_markdown(idea)
|
459 |
+
idea = markdown.markdown(idea)
|
460 |
+
# 更新每日回复次数
|
461 |
+
reply_count += 1
|
462 |
+
end_time = time.time()
|
463 |
+
time_taken = round(end_time - start_time, 2)
|
464 |
+
logging.info(f"Successfully generated idea for topic: {topic}")
|
465 |
+
except Exception as e:
|
466 |
+
end_time = time.time()
|
467 |
+
time_taken = round(end_time - start_time, 2)
|
468 |
+
logging.error(f"Failed to generate idea for topic: {topic}, Error: {str(e)}")
|
469 |
+
error_message = str(e)
|
470 |
+
# 从队列中移除当前用户
|
471 |
+
finished = queue.get()
|
472 |
+
print(f"finished: {finished}, still in queue: {queue.qsize()}")
|
473 |
+
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)
|
474 |
+
except Exception as e:
|
475 |
+
error_message = str(e)
|
476 |
queue.get()
|
477 |
+
return Template(html_template).render(idea="", error=error_message, reply_count=reply_count, button_text="Generate",loading_text=loading_text,script=script)
|