devchavda11 commited on
Commit
e3dcbc2
·
verified ·
1 Parent(s): 0e1b27a

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +6 -33
src/streamlit_app.py CHANGED
@@ -68,38 +68,7 @@ def create_download_link(file_path: str, label: str = None) -> str:
68
  return f"Error creating download link: {e}"
69
 
70
 
71
- def show_file(file_path: str):
72
- """Show file inline + download link."""
73
- if not os.path.exists(file_path):
74
- return
75
- ext = os.path.splitext(file_path)[1].lower()
76
- if ext in [".png", ".jpg", ".jpeg"]:
77
- st.image(file_path, caption=os.path.basename(file_path))
78
- elif ext in [".txt", ".py", ".java", ".cpp", ".md"]:
79
- with open(file_path, "r", encoding="utf-8", errors="ignore") as f:
80
- st.code(f.read(), language=ext.lstrip("."))
81
- st.markdown(create_download_link(file_path), unsafe_allow_html=True)
82
-
83
-
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):
92
- # Find all files in TEMP_DIR (freshly modified ones)
93
- created_files = sorted(
94
- [os.path.join(TEMP_DIR, f) for f in os.listdir(TEMP_DIR)],
95
- key=lambda x: os.path.getmtime(x),
96
- reverse=True,
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():
@@ -143,7 +112,11 @@ if "current_chat_id" in st.session_state:
143
  if isinstance(message, AIMessage):
144
  full_response += message.content or ""
145
  elif isinstance(message, ToolMessage):
146
- render_tool_message(message)
 
 
 
 
147
 
148
  response_placeholder.markdown(full_response + "|")
149
  st.rerun()
 
68
  return f"Error creating download link: {e}"
69
 
70
 
71
+
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
72
 
73
 
74
  def loadchats():
 
112
  if isinstance(message, AIMessage):
113
  full_response += message.content or ""
114
  elif isinstance(message, ToolMessage):
115
+ st.info("Using Appropriate tool")
116
+ tool_name = message.tool_calls[0]['name']
117
+ if(tool_name == "read_file" or tool_name == "write_file"):
118
+ create_download_link(message.content)
119
+
120
 
121
  response_placeholder.markdown(full_response + "|")
122
  st.rerun()