Spaces:
Sleeping
Sleeping
Update src/streamlit_app.py
Browse files- src/streamlit_app.py +12 -12
src/streamlit_app.py
CHANGED
|
@@ -7,7 +7,7 @@ from chat_langraph import system, workflow, HumanMessage, AIMessage, get_all_cha
|
|
| 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")
|
|
@@ -19,9 +19,9 @@ os.makedirs(TEMP_DIR, exist_ok=True)
|
|
| 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 |
-
|
| 24 |
-
st.session_state.tospeak = False
|
| 25 |
|
| 26 |
def set_title(messages):
|
| 27 |
if messages:
|
|
@@ -49,7 +49,7 @@ def load_session_state():
|
|
| 49 |
|
| 50 |
def render_sidebar():
|
| 51 |
with st.sidebar:
|
| 52 |
-
st.
|
| 53 |
st.title("Chats")
|
| 54 |
if st.button("➕ New Chat"):
|
| 55 |
new_id = str(uuid.uuid4())
|
|
@@ -117,12 +117,12 @@ 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.
|
| 122 |
try:
|
| 123 |
-
st.toast("
|
| 124 |
r = st.session_state.recognizer
|
| 125 |
-
audio = r.
|
| 126 |
text = r.recognize_google(audio)
|
| 127 |
user_input = text
|
| 128 |
except Exception as E:
|
|
@@ -149,7 +149,7 @@ if "current_chat_id" in st.session_state:
|
|
| 149 |
elif isinstance(message, ToolMessage):
|
| 150 |
st.info("Using Appropriate tool")
|
| 151 |
response_placeholder.markdown(full_response + " ")
|
| 152 |
-
if(st.session_state.tospeak):
|
| 153 |
-
|
| 154 |
-
|
| 155 |
st.rerun()
|
|
|
|
| 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")
|
|
|
|
| 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.audio_input("🎙️ Speak here :" , key="mic")
|
| 53 |
st.title("Chats")
|
| 54 |
if st.button("➕ New Chat"):
|
| 55 |
new_id = str(uuid.uuid4())
|
|
|
|
| 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.AudioFile(st.session_state.mic) as source:
|
| 122 |
try:
|
| 123 |
+
st.toast("Recognizing...")
|
| 124 |
r = st.session_state.recognizer
|
| 125 |
+
audio = r.record(source)
|
| 126 |
text = r.recognize_google(audio)
|
| 127 |
user_input = text
|
| 128 |
except Exception as E:
|
|
|
|
| 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()
|