Update app.py
Browse files
app.py
CHANGED
@@ -8,6 +8,7 @@ from langchain.agents import create_react_agent, AgentExecutor, Tool
|
|
8 |
from langchain.prompts import PromptTemplate
|
9 |
from langchain.memory import ConversationBufferMemory
|
10 |
from langchain.schema import AgentAction, AgentFinish
|
|
|
11 |
import time
|
12 |
|
13 |
# Email configuration
|
@@ -74,6 +75,14 @@ agent_executor = AgentExecutor.from_agent_and_tools(
|
|
74 |
early_stopping_method="generate" # Stop if the agent starts looping
|
75 |
)
|
76 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
77 |
st.title("CyberSecurity Program Meeting Scheduler")
|
78 |
st.write("Chat with the AI to schedule your meeting. The AI will ask for your name, email, and preferred meeting date.")
|
79 |
|
@@ -93,7 +102,7 @@ if prompt := st.chat_input("Your message"):
|
|
93 |
with st.spinner("Thinking..."):
|
94 |
try:
|
95 |
start_time = time.time()
|
96 |
-
response = agent_executor
|
97 |
if isinstance(response, dict) and "output" in response:
|
98 |
assistant_response = response["output"]
|
99 |
elif isinstance(response, (AgentAction, AgentFinish)):
|
|
|
8 |
from langchain.prompts import PromptTemplate
|
9 |
from langchain.memory import ConversationBufferMemory
|
10 |
from langchain.schema import AgentAction, AgentFinish
|
11 |
+
import concurrent.futures
|
12 |
import time
|
13 |
|
14 |
# Email configuration
|
|
|
75 |
early_stopping_method="generate" # Stop if the agent starts looping
|
76 |
)
|
77 |
|
78 |
+
def run_agent_with_timeout(executor, input_data, timeout):
|
79 |
+
with concurrent.futures.ThreadPoolExecutor() as pool:
|
80 |
+
future = pool.submit(executor, input_data)
|
81 |
+
try:
|
82 |
+
return future.result(timeout=timeout)
|
83 |
+
except concurrent.futures.TimeoutError:
|
84 |
+
raise TimeoutError("The operation timed out.")
|
85 |
+
|
86 |
st.title("CyberSecurity Program Meeting Scheduler")
|
87 |
st.write("Chat with the AI to schedule your meeting. The AI will ask for your name, email, and preferred meeting date.")
|
88 |
|
|
|
102 |
with st.spinner("Thinking..."):
|
103 |
try:
|
104 |
start_time = time.time()
|
105 |
+
response = run_agent_with_timeout(agent_executor, {"input": prompt}, timeout=10)
|
106 |
if isinstance(response, dict) and "output" in response:
|
107 |
assistant_response = response["output"]
|
108 |
elif isinstance(response, (AgentAction, AgentFinish)):
|