Spaces:
Sleeping
Sleeping
Update app.py
Browse files348 unmodified lines349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383348 unmodified lineslog_queue.put(("result", context.conversation_history))# -------------------- Process Generator and Human Input --------------------def process_conversation_generator(task_message: str, api_key: str,human_event: threading.Event, human_input_queue: queue.Queue,log_queue: queue.Queue) -> Generator[str, None, None]:"""Runs the conversation and yields log messages."""# Run the conversation asynchronously.asyncio.run(multi_agent_conversation(task_message, log_queue, api_key, human_event, human_input_queue))final_result = Nonewhile True:try:msg = log_queue.get_nowait()if isinstance(msg, tuple) and msg[0] == "result":final_result = msg[1]yield gr.Chatbot.update(value=final_result, visible=True)yield "Conversation complete."breakelse:yield msgexcept queue.Empty:pass# If human feedback is requested, yield an appropriate message.if human_event.is_set():yield "Waiting for human feedback..."# Use a short asynchronous sleep to avoid busy-waiting.asyncio.run(asyncio.sleep(0.1))def get_human_feedback(placeholder_text: str, human_input_queue: queue.Queue) -> gr.Blocks:"""348 unmodified lines349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387348 unmodified lineslog_queue.put(("result", context.conversation_history))# -------------------- Process Generator and Human Input --------------------def process_conversation_generator(task_message: str, api_key: str,human_event: threading.Event, human_input_queue: queue.Queue,log_queue: queue.Queue) -> Generator[str, None, None]:"""Runs the multi-agent conversation in a background thread and yields log messagesto update the chat box without blocking the UI."""def run_conversation():asyncio.run(multi_agent_conversation(task_message, log_queue, api_key, human_event, human_input_queue))# Start the asynchronous conversation in a separate thread.conversation_thread = threading.Thread(target=run_conversation)conversation_thread.start()# Continuously yield log messages until the conversation is complete.while conversation_thread.is_alive() or not log_queue.empty():try:msg = log_queue.get(timeout=0.1)if isinstance(msg, tuple) and msg[0] == "result":# Update the chat box with the final conversation history.yield gr.Chatbot.update(value=msg[1], visible=True)else:yield msgexcept queue.Empty:passif human_event.is_set():yield "Waiting for human feedback..."# Small sleep to prevent busy-waiting.time.sleep(0.1)yield "Conversation complete."def get_human_feedback(placeholder_text: str, human_input_queue: queue.Queue) -> gr.Blocks:"""
app.py+20-16