Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -51,6 +51,12 @@ load_dotenv()
|
|
51 |
# langfuse analytics
|
52 |
from langfuse.callback import CallbackHandler
|
53 |
|
|
|
|
|
|
|
|
|
|
|
|
|
54 |
# LangFuse API keys and host settings
|
55 |
os.environ["LANGFUSE_PUBLIC_KEY"] = os.getenv("LANGFUSE_PUBLIC_KEY")
|
56 |
os.environ["LANGFUSE_SECRET_KEY"] = os.getenv("LANGFUSE_SECRET_KEY")
|
@@ -550,6 +556,18 @@ iterations = 0
|
|
550 |
|
551 |
|
552 |
def answer_question(user_question, chatbot, audio=None):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
553 |
global iterations
|
554 |
iterations = 0
|
555 |
# Ensure the temporary chart directory exists
|
@@ -675,6 +693,17 @@ def handle_dislike(data: gr.LikeData):
|
|
675 |
def update_message(request: gr.Request):
|
676 |
return f"<h2 style=' font-family: Calibri;'>Welcome, {request.username}</h4>"
|
677 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
678 |
# CSS for styling the buttons and other elements
|
679 |
css = """
|
680 |
/* Example of custom button styling */
|
@@ -748,6 +777,9 @@ with gr.Blocks(css=css, theme=gr.themes.Soft()) as demo:
|
|
748 |
with gr.Column(scale=1):
|
749 |
with gr.Row():
|
750 |
button = gr.Button("Submit", elem_id="submit",elem_classes="gr-button")
|
|
|
|
|
|
|
751 |
|
752 |
button.click(answer_question, [message, chatbot], [chatbot])
|
753 |
message.submit(answer_question, [message, chatbot], [chatbot])
|
|
|
51 |
# langfuse analytics
|
52 |
from langfuse.callback import CallbackHandler
|
53 |
|
54 |
+
import multiprocessing
|
55 |
+
|
56 |
+
# Define global variables to manage the process and queue
|
57 |
+
process = None
|
58 |
+
queue = None
|
59 |
+
|
60 |
# LangFuse API keys and host settings
|
61 |
os.environ["LANGFUSE_PUBLIC_KEY"] = os.getenv("LANGFUSE_PUBLIC_KEY")
|
62 |
os.environ["LANGFUSE_SECRET_KEY"] = os.getenv("LANGFUSE_SECRET_KEY")
|
|
|
556 |
|
557 |
|
558 |
def answer_question(user_question, chatbot, audio=None):
|
559 |
+
|
560 |
+
#initialize the process
|
561 |
+
"""
|
562 |
+
Starts the agent in a separate process.
|
563 |
+
"""
|
564 |
+
global process
|
565 |
+
|
566 |
+
# Create a multiprocessing queue to get the result back from the process
|
567 |
+
queue = multiprocessing.Queue()
|
568 |
+
|
569 |
+
process.start()
|
570 |
+
|
571 |
global iterations
|
572 |
iterations = 0
|
573 |
# Ensure the temporary chart directory exists
|
|
|
693 |
def update_message(request: gr.Request):
|
694 |
return f"<h2 style=' font-family: Calibri;'>Welcome, {request.username}</h4>"
|
695 |
|
696 |
+
def stop_agent():
|
697 |
+
"""
|
698 |
+
Stops the agent process if it is still running.
|
699 |
+
"""
|
700 |
+
global process
|
701 |
+
if process and process.is_alive():
|
702 |
+
process.terminate() # Terminate the process forcefully
|
703 |
+
process.join() # Ensure the process is properly terminated
|
704 |
+
return "Agent execution stopped."
|
705 |
+
return "No active process to stop."
|
706 |
+
|
707 |
# CSS for styling the buttons and other elements
|
708 |
css = """
|
709 |
/* Example of custom button styling */
|
|
|
777 |
with gr.Column(scale=1):
|
778 |
with gr.Row():
|
779 |
button = gr.Button("Submit", elem_id="submit",elem_classes="gr-button")
|
780 |
+
# Button to stop the agent process
|
781 |
+
stop_button = gr.Button("Stop Agent")
|
782 |
+
stop_button.click(stop_agent, [])
|
783 |
|
784 |
button.click(answer_question, [message, chatbot], [chatbot])
|
785 |
message.submit(answer_question, [message, chatbot], [chatbot])
|