Spaces:
Sleeping
Sleeping
Update streamlit_app.py
Browse files- streamlit_app.py +18 -50
streamlit_app.py
CHANGED
@@ -36,60 +36,28 @@ user_input = st.chat_input(prompt_label, key=input_key)
|
|
36 |
deferred_response = None
|
37 |
deferred_spinner_msg = ""
|
38 |
|
39 |
-
|
40 |
-
# st.session_state.chat_history.append(HumanMessage(content=user_input))
|
41 |
-
|
42 |
-
# if re.search(r'https?://\S+', user_input):
|
43 |
-
# accent_tool_obj.last_transcript = ""
|
44 |
-
# deferred_spinner_msg = "Analyzing new video..."
|
45 |
-
# def run_agent():
|
46 |
-
# return analysis_agent.invoke(st.session_state.chat_history)[-1].content
|
47 |
-
# else:
|
48 |
-
# deferred_spinner_msg = "Responding based on transcript..."
|
49 |
-
# def run_agent():
|
50 |
-
# return follow_up_agent.invoke(st.session_state.chat_history).content
|
51 |
-
|
52 |
-
# # Run response generation inside spinner after chat is rendered
|
53 |
-
# def process_response():
|
54 |
-
# with st.spinner(deferred_spinner_msg):
|
55 |
-
# try:
|
56 |
-
# result = run_agent()
|
57 |
-
# except Exception as e:
|
58 |
-
# result = f"Error: {str(e)}"
|
59 |
-
# st.session_state.chat_history.append(AIMessage(content=result))
|
60 |
-
# st.rerun()
|
61 |
-
|
62 |
-
if user_input and not st.session_state.get("processing_started", False):
|
63 |
st.session_state.chat_history.append(HumanMessage(content=user_input))
|
64 |
-
|
65 |
if re.search(r'https?://\S+', user_input):
|
66 |
accent_tool_obj.last_transcript = ""
|
67 |
-
|
68 |
-
|
|
|
69 |
else:
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
if st.session_state.run_agent_type == "analysis":
|
84 |
-
result = analysis_agent.invoke(st.session_state.chat_history)[-1].content
|
85 |
-
else:
|
86 |
-
result = follow_up_agent.invoke(st.session_state.chat_history).content
|
87 |
-
except Exception as e:
|
88 |
-
result = f"Error: {str(e)}"
|
89 |
-
|
90 |
-
st.session_state.chat_history.append(AIMessage(content=result))
|
91 |
-
st.session_state.processing_started = False
|
92 |
-
st.rerun()
|
93 |
|
94 |
# Display full chat history (before running spinner)
|
95 |
for msg in st.session_state.chat_history:
|
|
|
36 |
deferred_response = None
|
37 |
deferred_spinner_msg = ""
|
38 |
|
39 |
+
if user_input:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
40 |
st.session_state.chat_history.append(HumanMessage(content=user_input))
|
41 |
+
|
42 |
if re.search(r'https?://\S+', user_input):
|
43 |
accent_tool_obj.last_transcript = ""
|
44 |
+
deferred_spinner_msg = "Analyzing new video..."
|
45 |
+
def run_agent():
|
46 |
+
return analysis_agent.invoke(st.session_state.chat_history)[-1].content
|
47 |
else:
|
48 |
+
deferred_spinner_msg = "Responding based on transcript..."
|
49 |
+
def run_agent():
|
50 |
+
return follow_up_agent.invoke(st.session_state.chat_history).content
|
51 |
+
|
52 |
+
# Run response generation inside spinner after chat is rendered
|
53 |
+
def process_response():
|
54 |
+
with st.spinner(deferred_spinner_msg):
|
55 |
+
try:
|
56 |
+
result = run_agent()
|
57 |
+
except Exception as e:
|
58 |
+
result = f"Error: {str(e)}"
|
59 |
+
st.session_state.chat_history.append(AIMessage(content=result))
|
60 |
+
st.rerun()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
61 |
|
62 |
# Display full chat history (before running spinner)
|
63 |
for msg in st.session_state.chat_history:
|