rajk078 commited on
Commit
c0f1091
·
1 Parent(s): 1025da9

Upload 3 files

Browse files
Files changed (3) hide show
  1. app.py +107 -0
  2. requirements.txt +9 -0
  3. utils.py +113 -0
app.py ADDED
@@ -0,0 +1,107 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from utils import *
3
+ from streamlit_chat import message
4
+ import azure.cognitiveservices.speech as speechsdk
5
+
6
+
7
+ if 'conversation' not in st.session_state:
8
+ st.session_state['conversation'] =None
9
+ if 'messages' not in st.session_state:
10
+ st.session_state['messages'] =[]
11
+
12
+ st.set_page_config(page_title="Agent Call Summarization")
13
+ # Define the Streamlit app
14
+ def main():
15
+ st.title("Agent Call Summarization")
16
+ #speech_to_text("CallRecording1.wav")
17
+
18
+ # Upload multiple files
19
+ uploaded_files = st.file_uploader("Upload recorded .mp3 files", type=["wav"], accept_multiple_files=True)
20
+
21
+ if uploaded_files:
22
+ #st.write("Uploaded Files:")
23
+
24
+ # Display uploaded files and buttons in a tabular form
25
+ for uploaded_file in uploaded_files:
26
+ file_name = uploaded_file.name
27
+
28
+ audio_text = get_audio_text(file_name)
29
+
30
+ #audio_text = "Thank you for calling the Office of People Transfer you're speaking with. Existing again. I don't have the number. It's about a box request. I have the student ID. No problem. How can I help you to help you with that? Can I get your name and the student ID please? My name is Carolina Carla and the student ID is 257468439. #10 is 257468439 alright? Thank you. Then how can I help you today, Catalina? We'll put it out on the bus. Um, but for some reason he was kicked out of the system. Couple of almost always ago we put in a request again and I just wanted to know if it was already approved. Alright, alright, alright. Highlands be able to take a look into that. Can I get this doing the same please? Ohh. Thank you. And can you confirm his date of birth? October 28th, 2016. And his address. 1444 Boston Rd. Apt. 4N as in Nancy Banks, New York, 10/4. 6/1 Thank you. Are you calling? Are you sorry? Are you calling from the school or are you back? I'm the mother. I'm OK. Sorry. Thank you. Alright, I'm just pulling up an account here. Give me one moment please. Thank you. And when was it that you called in to report the initial 10 off of the bus they were put in? Let me give you a start, OK? It wasn't the 16th they put in the request. Alright. And I'm seeing that you called and again to follow up on it. Is that right? Yeah. Yes. OK. Alright. Just hold for me a moment, please. I'm just gonna take a further look into that. I'll come right back here. Thank you. Thank you very much for holding. OK, alright, so I'm seeing that there isn't a signed route at the moment. When was the last time that you spoke with your school bus coordinator? The last time that I spoke recording under was on the 20th. On the 20th, yeah, OK, and it is your system. What? He was on the bus all the way up to the 15th and for some reason when I got the phone call in the morning from the medication, she informed me that he was no longer on the list. So when I call you guys, I was informed that he wasn't umm, he was um what was the word that they used? Umm. Uh, he he wasn't. He didn't. So how it which was the translation company, they told me he was late for their system so he was nowhere to be found in transportation system. So we had to put in the request again on the same you know and that's when the put in the request. Umm. I was hoping that, you know, the situation was going to be resolved right away, but obviously has not, so yeah. Yes, and everything all the way up to the 15 and this has caused me issues with work. So, but you know, I work, that's why he got on the bus. I'm at 6 1/2 to be late for work and get out early so that I could drop him off and pick him up and then the next week since then. The week after that like the last week of class before the break. So I'm trying to get this situation resolved. The slash to start again on Tuesday and. I don't want anymore issues with work. And it's done, yeah. So I have to get things resolved as fast as possible for this. Nobody's requested for him to be kicked out of the system like because he was receiving his service with no issue and for some reason, I don't know why, nobody apparently knows the reason why he was kicked out of the system and. He wasn't. You know he was. Add. Exactly. So we have to go ahead and put in the request one more time. So I don't understand the reason why. Yeah, I I wouldn't be able to see why it wasn't thought that it does seem to be something that might have been an error. Since no one is able to see why I I'm going to make it another second. But I think recommend just following up with this school bus coordinator. Just to see if they have maybe a particular risks and not the other high bus or on the side route as of yet. But I am seeing that he is is probably still in the process of being reviewed. So it probably will take some time but most likely it's it would be the case where on Tuesday he gets service but I cannot say for sure because nothing happened yet when, when when they're on break. I see that you guys work but do the independent. The transportation company. Are all for this. It might not be able to know this, but they're still working like in their offices. I am not sure for the offices that some of the companies in the schools are open because they do service multiple schools. They would be open as well. OK. Alright, so just follow up your school bus coordinator just to make sure because they are the ones who actually who would be able to give you a bit more information. OK. OK. Alright. Thank you for calling. Have a great day. Thank you for your help. Bye. Bye."
31
+
32
+ #Transcribe text
33
+ #st.text_area("Transcribe text", audio_text, height=400)
34
+
35
+ #Sentiment text
36
+ #st.write("Sentiment based on Audio", get_audio_senti(file_name))
37
+
38
+
39
+ st.subheader("Call Information", divider='blue')
40
+ user_name_queries = "what is user name? please provide only the name in your response."
41
+ user_Name = get_summary_response(audio_text, user_name_queries)
42
+ agent_Name = "Jessica"
43
+ call_duration = "5 min 2 sec"
44
+ col1, col2 = st.columns(2)
45
+ with col1:
46
+ st.subheader("Agent")
47
+ st.subheader("User")
48
+ st.subheader("Call Duration")
49
+ #your_html_design_as_string = """<svg xmlns="http://www.w3.org/2000/svg"><circle cx="50" cy="50" r="50" fill="red" /><text x="18" y="20.35" class="percentage">30%</text></svg>"""
50
+ #st.markdown(your_html_design_as_string, unsafe_allow_html=True)
51
+ with col2:
52
+ st.subheader(agent_Name)
53
+ st.subheader(user_Name)
54
+ st.subheader(call_duration)
55
+
56
+
57
+ st.divider()
58
+
59
+ st.subheader("1. User's Query", divider='blue')
60
+ user_query_Prompt = "Identify the user's problem or issue based on the following conversation text. Please provide a clear and concise description of the problem without including any other information"
61
+ user_query_response = get_summary_response(audio_text, user_query_Prompt)
62
+ st.info(user_query_response)
63
+
64
+ col1, col2 = st.columns(2)
65
+
66
+ st.subheader("2.Agent performance", divider='blue')
67
+ agent_performance_Prompt = "Please evaluate whether the agent has accurately identified the user's problem from the conversation text provided. Rate the agent's problem identification on a scale of 1 to 10, with 1 being very poor and 10 being excellent. Consider factors such as the agent's ability to understand and address the user's issue effectively."
68
+ agent_performance_response = get_summary_response(audio_text, agent_performance_Prompt)
69
+ st.info(agent_performance_response)
70
+
71
+ st.subheader("3.Agent performance based on Greeting", divider='blue')
72
+ opening_Prompt = "Please evaluate the agent's greeting on a scale of 1 to 10 only numerical, with 1 being very poor and 10 being excellent, based on the following conversation text. Consider factors such as politeness, clarity, and friendliness in your evaluation. Provide the answer in numerical rating first and explain your evaluation in the next line."
73
+ opening_scrore = get_summary_response(audio_text, opening_Prompt)
74
+ st.info(opening_scrore)
75
+
76
+ st.subheader("4.Summary", divider='blue')
77
+ st.info(get_summary_response(audio_text, "Format the above conversation which is happend between an agent and user into separate dialogues. This conversation is started by Agent . clearly distinguishing the user name's messages from the agent's responses:. Don't change the text and word. Use the User name as "+ user_Name +" and Agent Name is "+agent_Name+""))
78
+
79
+
80
+ st.subheader("Still any question", divider='blue')
81
+
82
+ response_container = st.container()
83
+ # Here we will have a container for user input text box
84
+ container = st.container()
85
+
86
+
87
+ with container:
88
+
89
+ with st.form(key='my_form', clear_on_submit=True):
90
+ user_input = st.text_area("Ask your queires here :", key='input', height=100)
91
+ submit_button = st.form_submit_button(label='Send')
92
+ if submit_button:
93
+ st.session_state['messages'].append(user_input)
94
+ model_response=get_summary_response(audio_text, user_input)
95
+ st.session_state['messages'].append(model_response)
96
+
97
+
98
+ with response_container:
99
+ for i in range(len(st.session_state['messages'])):
100
+ if (i % 2) == 0:
101
+ message(st.session_state['messages'][i], is_user=True, key=str(i) + '_user')
102
+ else:
103
+ message(st.session_state['messages'][i], key=str(i) + '_Agent')
104
+
105
+ # Run the Streamlit app
106
+ if __name__ == "__main__":
107
+ main()
requirements.txt ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ ffmpeg-python
2
+ langchain
3
+ whisper
4
+ streamlit
5
+ transformers
6
+ streamlit-chat
7
+ streamlit-mic-recorder
8
+ os
9
+ openai
utils.py ADDED
@@ -0,0 +1,113 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import whisper
2
+ from transformers import pipeline
3
+ from langchain.llms import OpenAI
4
+ from langchain import PromptTemplate
5
+ from langchain.prompts.chat import ChatPromptTemplate
6
+ from langchain.chat_models import ChatOpenAI
7
+ from langchain.prompts import HumanMessagePromptTemplate
8
+ from langchain.schema.messages import SystemMessage
9
+ import os
10
+
11
+ os.environ["OPENAI_API_TYPE"] = "azure"
12
+ os.environ["OPENAI_API_VERSION"] = "2022-12-01"
13
+ os.environ["OPENAI_API_BASE"] = "https://pubsec-careerpathways-openai.openai.azure.com/"
14
+ os.environ["OPENAI_API_KEY"] = "19ac6255a55b448e92190c0e5e75156e"
15
+
16
+
17
+ from langchain.llms import AzureOpenAI
18
+
19
+
20
+
21
+ def get_llm():
22
+ llm = AzureOpenAI(
23
+ deployment_name="CareerPathwaysPOC",
24
+ model_name="gpt-35-turbo",
25
+ temperature=0,
26
+ max_tokens = 2000
27
+ )
28
+ return llm
29
+
30
+
31
+ def get_audio_text(file):
32
+
33
+ # specify a model, here its BASE
34
+ model = whisper.load_model("base")
35
+
36
+ # transcribe audio file
37
+ result = model.transcribe(file)
38
+ print(result["text"])
39
+
40
+ return result["text"]
41
+
42
+ # Send email using zapier
43
+ #agent.run("Send an Email to [email protected] via gmail summarizing the following text provided below : "+result["text"])
44
+
45
+
46
+ def get_audio_senti(file):
47
+
48
+ pipe = pipeline("audio-classification", model="hackathon-pln-es/wav2vec2-base-finetuned-sentiment-classification-MESD")
49
+ result = pipe(file)
50
+ return result
51
+
52
+
53
+ def get_summary_using_chatprompt(user_input):
54
+
55
+
56
+ chat_template = ChatPromptTemplate.from_messages(
57
+ [
58
+ SystemMessage(
59
+ content=(
60
+ "You are a helpful assistant that write a summary of the conversation between a user and the Education call center in bullet point"
61
+ "Extract all relevant information from the text and check whether the agent has violated any rules during the call."
62
+ "The summary should include key details such as the user's inquiry, the agent's responses, any requests made by the user, and any potential violations of call center rules or policies. Additionally, highlight any specific actions or follow-up steps discussed during the call."
63
+ )
64
+ ),
65
+ HumanMessagePromptTemplate.from_template("{text}"),
66
+ ]
67
+ )
68
+
69
+ #llm = ChatOpenAI(openai_api_key= openai_api_key)
70
+ llm = get_llm()
71
+ summary = llm(chat_template.format_messages(text=user_input))
72
+ return summary
73
+
74
+
75
+
76
+ def get_summary_using_prompt(user_input):
77
+
78
+ llm = get_llm()
79
+
80
+ template = "Please provide me the summary of the below conversion between user and agent.\n {uses_conversion}.\n\nSummary:\n"
81
+ prompt = PromptTemplate(
82
+ input_variables=["uses_conversion"],
83
+ template=template
84
+ )
85
+ summary_prompt = prompt.format(uses_conversion=user_input)
86
+
87
+ print(summary_prompt)
88
+ summary = llm(summary_prompt)
89
+ return summary
90
+
91
+
92
+ def get_summary_response(uses_conversion, userqueries):
93
+
94
+ llm = get_llm()
95
+
96
+ role = "You are a conversation analyst responsible for examining and assessing interactions between users and agents."
97
+ instructions = "Provide responses to the specific questions posed within the given conversation. \n Refrain from answering if the answer is not explicitly present in the provided text. \n Avoid offering explanations in your responses."
98
+ conversation_history = ""
99
+ template = "|im_start|>system\n {role} \n Instructions \n {instructions} \n conversation \n ${templateMessage} \n <|im_end|>\n ${conversation_history}\n <|im_start|>user\n${query}\n <|im_end|>\n"
100
+
101
+ #template = "Please answer this question : {userqueries} ? Please don't provide the Explanation for answer. If you don't find the answer in the below text , please don't answer. \n \n\n {uses_conversion} \n\n"
102
+
103
+ prompt = PromptTemplate(
104
+ input_variables=["role","instructions","templateMessage","conversation_history","query"],
105
+ template=template
106
+ )
107
+ summary_prompt = prompt.format(templateMessage=uses_conversion,query= userqueries, role=role,instructions= instructions,conversation_history= conversation_history)
108
+ print(summary_prompt)
109
+ summary = llm(summary_prompt)
110
+ summary = summary.replace('<|im_end|>', '')
111
+ print(summary)
112
+ return summary
113
+