Spaces:
Sleeping
Sleeping
Update src/streamlit_app.py
Browse files- src/streamlit_app.py +8 -9
src/streamlit_app.py
CHANGED
|
@@ -5,7 +5,7 @@ import os
|
|
| 5 |
import base64
|
| 6 |
|
| 7 |
st.set_page_config(layout="wide")
|
| 8 |
-
st.title("
|
| 9 |
|
| 10 |
TEMP_DIR = "/tmp"
|
| 11 |
os.makedirs(TEMP_DIR, exist_ok=True)
|
|
@@ -47,7 +47,7 @@ def render_sidebar():
|
|
| 47 |
config = {"configurable": {"thread_id": new_id}}
|
| 48 |
workflow.update_state(config, {"messages": [system]})
|
| 49 |
st.session_state.chat_dict[new_id] = "New Chat"
|
| 50 |
-
|
| 51 |
for chat_id in st.session_state.chats:
|
| 52 |
if st.button(st.session_state.chat_dict.get(chat_id, "New Chat"), key=chat_id):
|
| 53 |
st.session_state.current_chat_id = chat_id
|
|
@@ -84,9 +84,8 @@ def show_file(file_path: str):
|
|
| 84 |
def render_tool_message(tool_message: ToolMessage):
|
| 85 |
"""Render tool execution based on tool name instead of message content."""
|
| 86 |
file_related_keywords = ["read", "write", "file", "save", "export", "create"]
|
| 87 |
-
with st.chat_message("assistant"):
|
| 88 |
tool_name = getattr(tool_message, "name", "").lower()
|
| 89 |
-
st.info(f"🧰
|
| 90 |
|
| 91 |
# Check if this is a file-related tool
|
| 92 |
if any(k in tool_name for k in file_related_keywords):
|
|
@@ -98,10 +97,9 @@ def render_tool_message(tool_message: ToolMessage):
|
|
| 98 |
)
|
| 99 |
if created_files:
|
| 100 |
st.success("📄 File(s) created by tool:")
|
| 101 |
-
for file_path in created_files[:3]:
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
st.warning("No new file detected in /tmp.")
|
| 105 |
|
| 106 |
|
| 107 |
def loadchats():
|
|
@@ -147,4 +145,5 @@ if "current_chat_id" in st.session_state:
|
|
| 147 |
elif isinstance(message, ToolMessage):
|
| 148 |
render_tool_message(message)
|
| 149 |
|
| 150 |
-
|
|
|
|
|
|
| 5 |
import base64
|
| 6 |
|
| 7 |
st.set_page_config(layout="wide")
|
| 8 |
+
st.title("My Chatbot")
|
| 9 |
|
| 10 |
TEMP_DIR = "/tmp"
|
| 11 |
os.makedirs(TEMP_DIR, exist_ok=True)
|
|
|
|
| 47 |
config = {"configurable": {"thread_id": new_id}}
|
| 48 |
workflow.update_state(config, {"messages": [system]})
|
| 49 |
st.session_state.chat_dict[new_id] = "New Chat"
|
| 50 |
+
st.rerun()
|
| 51 |
for chat_id in st.session_state.chats:
|
| 52 |
if st.button(st.session_state.chat_dict.get(chat_id, "New Chat"), key=chat_id):
|
| 53 |
st.session_state.current_chat_id = chat_id
|
|
|
|
| 84 |
def render_tool_message(tool_message: ToolMessage):
|
| 85 |
"""Render tool execution based on tool name instead of message content."""
|
| 86 |
file_related_keywords = ["read", "write", "file", "save", "export", "create"]
|
|
|
|
| 87 |
tool_name = getattr(tool_message, "name", "").lower()
|
| 88 |
+
st.info(f"🧰 Using tool :- {tool_name or ''}")
|
| 89 |
|
| 90 |
# Check if this is a file-related tool
|
| 91 |
if any(k in tool_name for k in file_related_keywords):
|
|
|
|
| 97 |
)
|
| 98 |
if created_files:
|
| 99 |
st.success("📄 File(s) created by tool:")
|
| 100 |
+
for file_path in created_files[:3]:
|
| 101 |
+
if("chatbot" not in file_path):
|
| 102 |
+
show_file(file_path)
|
|
|
|
| 103 |
|
| 104 |
|
| 105 |
def loadchats():
|
|
|
|
| 145 |
elif isinstance(message, ToolMessage):
|
| 146 |
render_tool_message(message)
|
| 147 |
|
| 148 |
+
response_placeholder.markdown(full_response + "|")
|
| 149 |
+
st.rerun()
|