Commit ·
b916c3e
1
Parent(s): ce63e0b
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# import gradio as gr
|
| 2 |
+
# import openai
|
| 3 |
+
|
| 4 |
+
# from gtts import gTTS
|
| 5 |
+
# import os
|
| 6 |
+
# import subprocess
|
| 7 |
+
# from pydub import AudioSegment
|
| 8 |
+
# import math
|
| 9 |
+
# from transformers import pipeline
|
| 10 |
+
# openai.api_key = " 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"
|
| 11 |
+
# messages = [
|
| 12 |
+
# {"role": "system", "content": "You are a call center quality and assurance auditor. Your job is to review the call recording, and provide a very brief summary of the key information in the call including Operator’s Name, Call Category, Issue, and Solution. Also, you need to conduct sentiment analysis on the call and evaluate the customers satisfaction rate from 1 to 10 and provide a very short straight-to-the-point area of improvement to the operator."},
|
| 13 |
+
# ]
|
| 14 |
+
|
| 15 |
+
# def transcribe(audio):
|
| 16 |
+
# global messages
|
| 17 |
+
|
| 18 |
+
# segment_length = 60000
|
| 19 |
+
# # Open the audio file
|
| 20 |
+
# audio_file = AudioSegment.from_file(audio)
|
| 21 |
+
# # Get the duration of the audio file in milliseconds
|
| 22 |
+
# duration_ms = len(audio_file)
|
| 23 |
+
|
| 24 |
+
# # Calculate the number of segments needed
|
| 25 |
+
# num_segments = math.ceil(duration_ms / segment_length)
|
| 26 |
+
|
| 27 |
+
# # Create an empty string to hold the concatenated text
|
| 28 |
+
# all_text = ""
|
| 29 |
+
# # Split the audio file into segments
|
| 30 |
+
|
| 31 |
+
# for i in range(num_segments):
|
| 32 |
+
|
| 33 |
+
import streamlit as st
|
| 34 |
+
import openai
|
| 35 |
+
import os
|
| 36 |
+
from pydub import AudioSegment
|
| 37 |
+
import math
|
| 38 |
+
from transformers import pipeline
|
| 39 |
+
from dotenv import load_dotenv
|
| 40 |
+
|
| 41 |
+
load_dotenv()
|
| 42 |
+
|
| 43 |
+
# Initialize messages outside of the function to persist state between Streamlit sessions
|
| 44 |
+
messages = [
|
| 45 |
+
{"role": "system", "content": "You are a call center quality and assurance auditor. Your job is to review the call recording, and provide a very brief summary of the key information in the call including Operator’s Name, Call Category, Issue, and Solution. Also, you need to conduct sentiment analysis on the call and evaluate the customer's satisfaction rate from 1 to 10 and provide a very short straight-to-the-point area of improvement to the operator."},
|
| 46 |
+
]
|
| 47 |
+
|
| 48 |
+
def transcribe(audio):
|
| 49 |
+
# summarizer = pipeline("summarization", model="philschmid/bart-large-cnn-samsum")
|
| 50 |
+
global messages
|
| 51 |
+
|
| 52 |
+
segment_length = 60000
|
| 53 |
+
# Open the audio file
|
| 54 |
+
audio_file = AudioSegment.from_file(audio)
|
| 55 |
+
# Get the duration of the audio file in milliseconds
|
| 56 |
+
duration_ms = len(audio_file)
|
| 57 |
+
|
| 58 |
+
# Calculate the number of segments needed
|
| 59 |
+
num_segments = math.ceil(duration_ms / segment_length)
|
| 60 |
+
|
| 61 |
+
# Create an empty string to hold the concatenated text
|
| 62 |
+
all_text = ""
|
| 63 |
+
# Split the audio file into segments
|
| 64 |
+
|
| 65 |
+
for i in range(num_segments):
|
| 66 |
+
start = i * segment_length
|
| 67 |
+
end = min((i + 1) * segment_length, duration_ms)
|
| 68 |
+
segment = audio_file[start:end]
|
| 69 |
+
segment.export(f"segment_{i}.mp3", format="mp3")
|
| 70 |
+
|
| 71 |
+
for i in range(num_segments):
|
| 72 |
+
audio_file = open(f"segment_{i}.mp3", "rb")
|
| 73 |
+
transcript = openai.Audio.transcribe("whisper-1", audio_file)
|
| 74 |
+
all_text += transcript["text"]
|
| 75 |
+
|
| 76 |
+
summarizer = pipeline("summarization", model="slauw87/bart_summarisation")
|
| 77 |
+
|
| 78 |
+
st.write(all_text)
|
| 79 |
+
st.write('Summarizing...')
|
| 80 |
+
st.write('---------------------------------')
|
| 81 |
+
summary = summarizer(all_text)
|
| 82 |
+
st.write(summary)
|
| 83 |
+
messages.append({"role": "user", "content": all_text})
|
| 84 |
+
|
| 85 |
+
response = openai.ChatCompletion.create(
|
| 86 |
+
model="gpt-3.5-turbo",
|
| 87 |
+
messages=messages
|
| 88 |
+
)
|
| 89 |
+
|
| 90 |
+
systems_message = response["choices"][0]["message"]["content"]
|
| 91 |
+
messages.append({"role": "assistant", "content": systems_message})
|
| 92 |
+
|
| 93 |
+
chat_transcript = ""
|
| 94 |
+
for message in messages:
|
| 95 |
+
if message['role'] != 'system':
|
| 96 |
+
chat_transcript += message['role'] + ": " + message['content'] + "\n\n"
|
| 97 |
+
|
| 98 |
+
st.write(systems_message)
|
| 99 |
+
|
| 100 |
+
# Streamlit app layout
|
| 101 |
+
st.title("AI Auditor for Call Center's Quality Assurance")
|
| 102 |
+
st.markdown("AI Alliance for Audio Analytics Team. Our project's objective is to conduct quality assurance on recorded calls, by transcribing the speech in the call to text using Whisper and then employing GPT-3 for sentiment analysis, summarization, and feedback including areas for improvement.")
|
| 103 |
+
|
| 104 |
+
# Streamlit file uploader
|
| 105 |
+
uploaded_file = st.file_uploader("Upload an audio file", type=["mp3", "wav"])
|
| 106 |
+
|
| 107 |
+
# Check if a file is uploaded
|
| 108 |
+
if uploaded_file:
|
| 109 |
+
# Display the transcribe function result
|
| 110 |
+
transcribe(uploaded_file)
|