Zasha1 commited on
Commit
6ce6beb
·
verified ·
1 Parent(s): 6b2d7b0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -16
app.py CHANGED
@@ -13,12 +13,17 @@ import streamlit as st
13
  import numpy as np
14
  from io import BytesIO
15
  import wave
 
 
16
 
17
  # Initialize components
18
  objection_handler = ObjectionHandler("objections.csv") # Use relative path
19
  product_recommender = ProductRecommender("recommendations.csv") # Use relative path
20
  model = SentenceTransformer('all-MiniLM-L6-v2')
21
 
 
 
 
22
  def generate_comprehensive_summary(chunks):
23
  """
24
  Generate a comprehensive summary from conversation chunks
@@ -136,10 +141,8 @@ def transcribe_audio(audio_bytes, sample_rate=16000):
136
  print(f"Error transcribing audio: {e}")
137
  return None
138
 
139
- def real_time_analysis():
140
- st.info("Listening... Say 'stop' to end the process.")
141
-
142
- def audio_frame_callback(audio_frame):
143
  # Convert audio frame to bytes
144
  audio_data = audio_frame.to_ndarray()
145
  print(f"Audio data shape: {audio_data.shape}") # Debug: Check audio data shape
@@ -150,6 +153,27 @@ def real_time_analysis():
150
  # Transcribe the audio
151
  text = transcribe_audio(audio_bytes)
152
  if text:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
153
  st.write(f"*Recognized Text:* {text}")
154
 
155
  # Analyze sentiment
@@ -173,18 +197,6 @@ def real_time_analysis():
173
  st.write("*Product Recommendations:*")
174
  for rec in recommendations:
175
  st.write(rec)
176
- else:
177
- st.error("No transcription returned.") # Debug: Check if transcription fails
178
-
179
- return audio_frame
180
-
181
- # Start WebRTC audio stream
182
- webrtc_ctx = webrtc_streamer(
183
- key="real-time-audio",
184
- mode=WebRtcMode.SENDONLY,
185
- audio_frame_callback=audio_frame_callback,
186
- media_stream_constraints={"audio": True, "video": False},
187
- )
188
 
189
  def run_app():
190
  st.set_page_config(page_title="Sales Call Assistant", layout="wide")
 
13
  import numpy as np
14
  from io import BytesIO
15
  import wave
16
+ import threading
17
+ import queue
18
 
19
  # Initialize components
20
  objection_handler = ObjectionHandler("objections.csv") # Use relative path
21
  product_recommender = ProductRecommender("recommendations.csv") # Use relative path
22
  model = SentenceTransformer('all-MiniLM-L6-v2')
23
 
24
+ # Queue to hold transcribed text
25
+ transcription_queue = queue.Queue()
26
+
27
  def generate_comprehensive_summary(chunks):
28
  """
29
  Generate a comprehensive summary from conversation chunks
 
141
  print(f"Error transcribing audio: {e}")
142
  return None
143
 
144
+ def audio_processing_thread(audio_frame):
145
+ """Thread function to process audio frames."""
 
 
146
  # Convert audio frame to bytes
147
  audio_data = audio_frame.to_ndarray()
148
  print(f"Audio data shape: {audio_data.shape}") # Debug: Check audio data shape
 
153
  # Transcribe the audio
154
  text = transcribe_audio(audio_bytes)
155
  if text:
156
+ transcription_queue.put(text) # Add transcribed text to the queue
157
+
158
+ def real_time_analysis():
159
+ st.info("Listening... Say 'stop' to end the process.")
160
+
161
+ def audio_frame_callback(audio_frame):
162
+ # Start a new thread to process the audio frame
163
+ threading.Thread(target=audio_processing_thread, args=(audio_frame,)).start()
164
+ return audio_frame
165
+
166
+ # Start WebRTC audio stream
167
+ webrtc_ctx = webrtc_streamer(
168
+ key="real-time-audio",
169
+ mode=WebRtcMode.SENDONLY,
170
+ audio_frame_callback=audio_frame_callback,
171
+ media_stream_constraints={"audio": True, "video": False},
172
+ )
173
+
174
+ # Display transcribed text from the queue
175
+ while not transcription_queue.empty():
176
+ text = transcription_queue.get()
177
  st.write(f"*Recognized Text:* {text}")
178
 
179
  # Analyze sentiment
 
197
  st.write("*Product Recommendations:*")
198
  for rec in recommendations:
199
  st.write(rec)
 
 
 
 
 
 
 
 
 
 
 
 
200
 
201
  def run_app():
202
  st.set_page_config(page_title="Sales Call Assistant", layout="wide")