devchavda11 commited on
Commit
f3c5b24
·
verified ·
1 Parent(s): 71a54fa

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +0 -23
src/streamlit_app.py CHANGED
@@ -5,7 +5,6 @@ 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
- import speech_recognition as sr
9
  import base64
10
  # import pyttsx3
11
 
@@ -17,8 +16,6 @@ os.makedirs(TEMP_DIR, exist_ok=True)
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
@@ -49,9 +46,6 @@ def load_session_state():
49
 
50
  def render_sidebar():
51
  with st.sidebar:
52
- audio_file = st.audio_input("🎙️ Speak here :" , key="mic")
53
- if audio_file:
54
- st.session_state.mic = audio_file
55
  st.title("Chats")
56
  if st.button("➕ New Chat"):
57
  new_id = str(uuid.uuid4())
@@ -118,19 +112,6 @@ render_sidebar()
118
  if "current_chat_id" in st.session_state:
119
  loadchats()
120
  user_input = st.chat_input("Your message:")
121
- if "mic" in st.session_state and st.session_state.mic is not None:
122
- audio = st.session_state.mic
123
- st.session_state.mic = None
124
- # st.session_state.tospeak = True
125
- with sr.AudioFile(audio) as source:
126
- try:
127
- st.toast("Recognizing...")
128
- r = st.session_state.recognizer
129
- audio = r.record(source)
130
- text = r.recognize_google(audio)
131
- user_input = text
132
- except Exception as E:
133
- st.toast("Some Error Occoured Try again ...")
134
  if user_input :
135
  with st.chat_message("human"):
136
  st.write(user_input)
@@ -138,8 +119,6 @@ if "current_chat_id" in st.session_state:
138
  with st.chat_message("assistant"):
139
  response_placeholder = st.empty()
140
  full_response = ""
141
- tool_name = ""
142
- tool_download_msg = ""
143
  for message, metadata in workflow.stream(
144
  {"messages": [system, HumanMessage(user_input)]},
145
  config={"configurable": {"thread_id": st.session_state.current_chat_id}},
@@ -148,8 +127,6 @@ if "current_chat_id" in st.session_state:
148
  tool_link = ""
149
  if isinstance(message, AIMessage):
150
  full_response += message.content or ""
151
- if(message.tool_calls):
152
- tool_name = message.tool_calls[0]['name']
153
  elif isinstance(message, ToolMessage):
154
  st.info("Using Appropriate tool")
155
  response_placeholder.markdown(full_response + " ")
 
5
  import streamlit as st
6
  from chat_langraph import system, workflow, HumanMessage, AIMessage, get_all_chat_ids, ToolMessage
7
  import uuid
 
8
  import base64
9
  # import pyttsx3
10
 
 
16
 
17
 
18
  # --- Helpers ---
 
 
19
  # if ("speaker" not in st.session_state):
20
  # st.session_state.speaker = pyttsx3.init()
21
  # st.session_state.tospeak = False
 
46
 
47
  def render_sidebar():
48
  with st.sidebar:
 
 
 
49
  st.title("Chats")
50
  if st.button("➕ New Chat"):
51
  new_id = str(uuid.uuid4())
 
112
  if "current_chat_id" in st.session_state:
113
  loadchats()
114
  user_input = st.chat_input("Your message:")
 
 
 
 
 
 
 
 
 
 
 
 
 
115
  if user_input :
116
  with st.chat_message("human"):
117
  st.write(user_input)
 
119
  with st.chat_message("assistant"):
120
  response_placeholder = st.empty()
121
  full_response = ""
 
 
122
  for message, metadata in workflow.stream(
123
  {"messages": [system, HumanMessage(user_input)]},
124
  config={"configurable": {"thread_id": st.session_state.current_chat_id}},
 
127
  tool_link = ""
128
  if isinstance(message, AIMessage):
129
  full_response += message.content or ""
 
 
130
  elif isinstance(message, ToolMessage):
131
  st.info("Using Appropriate tool")
132
  response_placeholder.markdown(full_response + " ")