Zasha1 commited on
Commit
eda791a
·
verified ·
1 Parent(s): 572378b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +31 -27
app.py CHANGED
@@ -140,38 +140,43 @@ 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
- audio_bytes = (audio_data * 32767).astype(np.int16).tobytes() # Convert to int16 format
 
146
 
147
- # Transcribe the audio
148
- text = transcribe_audio(audio_bytes)
149
- if text:
150
- st.write(f"*Recognized Text:* {text}")
151
 
152
- # Analyze sentiment
153
- sentiment, score = analyze_sentiment(text)
154
- st.write(f"*Sentiment:* {sentiment} (Score: {score})")
 
155
 
156
- # Handle objection
157
- objection_response = handle_objection(text)
158
- st.write(f"*Objection Response:* {objection_response}")
159
 
160
- # Get product recommendation
161
- recommendations = []
162
- if is_valid_input(text) and is_relevant_sentiment(score):
163
- query_embedding = model.encode([text])
164
- distances, indices = product_recommender.index.search(query_embedding, 1)
165
 
166
- if distances[0][0] < 1.5: # Similarity threshold
167
- recommendations = product_recommender.get_recommendations(text)
 
 
 
168
 
169
- if recommendations:
170
- st.write("*Product Recommendations:*")
171
- for rec in recommendations:
172
- st.write(rec)
173
 
174
- return audio_frame
 
 
 
 
 
 
 
175
 
176
  # Start WebRTC audio stream
177
  webrtc_ctx = webrtc_streamer(
@@ -272,5 +277,4 @@ def run_app():
272
  st.error(f"Error loading dashboard: {e}")
273
 
274
  if __name__ == "__main__":
275
- run_app()
276
-
 
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
146
+ print(f"Audio data sample: {audio_data[:10]}") # Debug: Check first 10 samples
147
 
148
+ audio_bytes = (audio_data * 32767).astype(np.int16).tobytes() # Convert to int16 format
 
 
 
149
 
150
+ # Transcribe the audio
151
+ text = transcribe_audio(audio_bytes)
152
+ if text:
153
+ st.write(f"*Recognized Text:* {text}")
154
 
155
+ # Analyze sentiment
156
+ sentiment, score = analyze_sentiment(text)
157
+ st.write(f"*Sentiment:* {sentiment} (Score: {score})")
158
 
159
+ # Handle objection
160
+ objection_response = handle_objection(text)
161
+ st.write(f"*Objection Response:* {objection_response}")
 
 
162
 
163
+ # Get product recommendation
164
+ recommendations = []
165
+ if is_valid_input(text) and is_relevant_sentiment(score):
166
+ query_embedding = model.encode([text])
167
+ distances, indices = product_recommender.index.search(query_embedding, 1)
168
 
169
+ if distances[0][0] < 1.5: # Similarity threshold
170
+ recommendations = product_recommender.get_recommendations(text)
 
 
171
 
172
+ if recommendations:
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(
 
277
  st.error(f"Error loading dashboard: {e}")
278
 
279
  if __name__ == "__main__":
280
+ run_app()