Update app.py
Browse files
app.py
CHANGED
@@ -1,5 +1,3 @@
|
|
1 |
-
import numpy as np
|
2 |
-
import pyaudio
|
3 |
import speech_recognition as sr
|
4 |
from sentiment_analysis import analyze_sentiment
|
5 |
from product_recommender import ProductRecommender
|
@@ -14,37 +12,13 @@ from googleapiclient.discovery import build
|
|
14 |
import pandas as pd
|
15 |
import plotly.express as px
|
16 |
import plotly.graph_objs as go
|
17 |
-
import streamlit as st
|
|
|
18 |
|
19 |
# Initialize components
|
20 |
objection_handler = ObjectionHandler('objections.csv')
|
21 |
product_recommender = ProductRecommender('recommendations.csv')
|
22 |
model = SentenceTransformer('all-MiniLM-L6-v2')
|
23 |
-
|
24 |
-
def record_audio(duration=5, sample_rate=16000):
|
25 |
-
"""
|
26 |
-
Record audio using PyAudio and return as NumPy array
|
27 |
-
"""
|
28 |
-
p = pyaudio.PyAudio()
|
29 |
-
stream = p.open(format=pyaudio.paFloat32,
|
30 |
-
channels=1,
|
31 |
-
rate=sample_rate,
|
32 |
-
input=True,
|
33 |
-
frames_per_buffer=1024)
|
34 |
-
|
35 |
-
st.write("Recording...")
|
36 |
-
frames = []
|
37 |
-
for _ in range(0, int(sample_rate / 1024 * duration)):
|
38 |
-
data = stream.read(1024)
|
39 |
-
frames.append(np.frombuffer(data, dtype=np.float32))
|
40 |
-
|
41 |
-
stream.stop_stream()
|
42 |
-
stream.close()
|
43 |
-
p.terminate()
|
44 |
-
|
45 |
-
st.write("Recording finished.")
|
46 |
-
audio_data = np.concatenate(frames)
|
47 |
-
return audio_data, sample_rate
|
48 |
|
49 |
def numpy_to_audio_data(audio_data):
|
50 |
"""
|
|
|
|
|
|
|
1 |
import speech_recognition as sr
|
2 |
from sentiment_analysis import analyze_sentiment
|
3 |
from product_recommender import ProductRecommender
|
|
|
12 |
import pandas as pd
|
13 |
import plotly.express as px
|
14 |
import plotly.graph_objs as go
|
15 |
+
import streamlit as st
|
16 |
+
|
17 |
|
18 |
# Initialize components
|
19 |
objection_handler = ObjectionHandler('objections.csv')
|
20 |
product_recommender = ProductRecommender('recommendations.csv')
|
21 |
model = SentenceTransformer('all-MiniLM-L6-v2')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
22 |
|
23 |
def numpy_to_audio_data(audio_data):
|
24 |
"""
|