devchavda11 commited on
Commit
079ade3
·
verified ·
1 Parent(s): 6c69211

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +24 -8
src/streamlit_app.py CHANGED
@@ -5,8 +5,9 @@ os.environ["STREAMLIT_HOME"] = "/tmp/.streamlit"
5
  import streamlit as st
6
  from chat_langraph import system, workflow, HumanMessage, AIMessage, get_all_chat_ids, ToolMessage
7
  import uuid
8
-
9
  import base64
 
10
 
11
  st.set_page_config(layout="wide")
12
  st.title("My Chatbot")
@@ -16,6 +17,11 @@ os.makedirs(TEMP_DIR, exist_ok=True)
16
 
17
 
18
  # --- Helpers ---
 
 
 
 
 
19
 
20
  def set_title(messages):
21
  if messages:
@@ -43,6 +49,7 @@ def load_session_state():
43
 
44
  def render_sidebar():
45
  with st.sidebar:
 
46
  st.title("Chats")
47
  if st.button("➕ New Chat"):
48
  new_id = str(uuid.uuid4())
@@ -108,7 +115,19 @@ render_sidebar()
108
 
109
  if "current_chat_id" in st.session_state:
110
  loadchats()
111
- if user_input := st.chat_input("Your message:"):
 
 
 
 
 
 
 
 
 
 
 
 
112
  with st.chat_message("human"):
113
  st.write(user_input)
114
 
@@ -129,11 +148,8 @@ if "current_chat_id" in st.session_state:
129
  tool_name = message.tool_calls[0]['name']
130
  elif isinstance(message, ToolMessage):
131
  st.info("Using Appropriate tool")
132
-
133
- if(tool_name == "read_file" or tool_name == "write_file"):
134
- tool_download_msg += message.content
135
- tool_link = create_download_link(tool_download_msg)
136
-
137
-
138
  response_placeholder.markdown(full_response + " ")
 
 
 
139
  st.rerun()
 
5
  import streamlit as st
6
  from chat_langraph import system, workflow, HumanMessage, AIMessage, get_all_chat_ids, ToolMessage
7
  import uuid
8
+ import speech_recognition as sr
9
  import base64
10
+ import pyttsx3
11
 
12
  st.set_page_config(layout="wide")
13
  st.title("My Chatbot")
 
17
 
18
 
19
  # --- Helpers ---
20
+ if ("recognizer" not in st.session_state):
21
+ st.session_state.recognizer = sr.Recognizer()
22
+ if ("speaker" not in st.session_state):
23
+ st.session_state.speaker = pyttsx3.init()
24
+ st.session_state.tospeak = False
25
 
26
  def set_title(messages):
27
  if messages:
 
49
 
50
  def render_sidebar():
51
  with st.sidebar:
52
+ st.button("🎙️" , key="mic")
53
  st.title("Chats")
54
  if st.button("➕ New Chat"):
55
  new_id = str(uuid.uuid4())
 
115
 
116
  if "current_chat_id" in st.session_state:
117
  loadchats()
118
+ user_input = st.chat_input("Your message:")
119
+ if st.session_state.mic:
120
+ st.session_state.tospeak = True
121
+ with sr.Microphone() as source:
122
+ try:
123
+ st.toast("Listening ...")
124
+ r = st.session_state.recognizer
125
+ audio = r.listen(source , timeout = 200)
126
+ text = r.recognize_google(audio)
127
+ user_input = text
128
+ except Exception as E:
129
+ st.toast("Some Error Occoured Try again ...")
130
+ if user_input :
131
  with st.chat_message("human"):
132
  st.write(user_input)
133
 
 
148
  tool_name = message.tool_calls[0]['name']
149
  elif isinstance(message, ToolMessage):
150
  st.info("Using Appropriate tool")
 
 
 
 
 
 
151
  response_placeholder.markdown(full_response + " ")
152
+ if(st.session_state.tospeak):
153
+ st.session_state.speaker.say(full_response)
154
+ st.session_state.runAndWait()
155
  st.rerun()