sergiomar73 commited on
Commit
fc4f2ad
·
1 Parent(s): 9552f1e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +30 -45
app.py CHANGED
@@ -11,6 +11,12 @@ model = SentenceTransformer('paraphrase-distilroberta-base-v2')
11
 
12
  nlp = spacy.load("en_core_web_sm")
13
 
 
 
 
 
 
 
14
  def calculate_embeddings_with_roberta(text):
15
  embeddings = model.encode(text, convert_to_tensor=True)
16
  return embeddings
@@ -42,49 +48,27 @@ def process_categories(categories):
42
  return df_category_list
43
 
44
  def compare_text(transcript, categories):
45
- df_category_list = process_categories(categories)
46
- doc = nlp(transcript)
47
- sentences = [ sentence.text for sentence in list(doc.sents) ]
48
- embeddings = model.encode(sentences, convert_to_tensor=True)
49
- print(f"{len(sentences)} sentences")
50
- sentences_mini = [ s[:50] for s in sentences ]
51
- df_results_grid = pd.DataFrame(sentences, columns=['Sentence'])
52
- df_results_plot = pd.DataFrame(index=sentences_mini)
53
- for _, df_category in enumerate(df_category_list):
54
- phrases_list = df_category["embeddings"].values.tolist()
55
- phrases = torch.stack(phrases_list)
56
- # Compute cosine-similarities
57
- cosine_scores = util.cos_sim(embeddings, phrases).numpy()
58
- max_scores = np.max(cosine_scores, axis=1)
59
- df_results_plot[df_category.iloc[0,2]] = max_scores
60
- df_results_grid[df_category.iloc[0,2]] = max_scores
61
- df_results_plot = df_results_plot.round(decimals = 2)
62
- df_results_grid = df_results_grid.round(decimals = 3)
63
- # Plot
64
- fig = px.imshow(
65
- df_results_plot,
66
- labels=dict(x="Category", y="Sentence"),
67
- x=df_results_plot.columns, y=df_results_plot.index,
68
- text_auto=True,
69
- aspect="auto",
70
- color_continuous_scale="rdylgn"
71
- # color_continuous_scale=px.colors.sequential.YlGn
72
- # color_continuous_scale=px.colors.sequential.Aggrnyl
73
- # color_continuous_scale=px.colors.sequential.Viridis
74
- # color_continuous_scale=px.colors.sequential.BuGn
75
- # color_continuous_scale=px.colors.sequential.Greens
76
- # color_continuous_scale=px.colors.diverging.RdYlGn
77
- )
78
- fig.update_layout(height=1000)
79
- fig.update_xaxes(side="top")
80
- return df_results_grid, fig
81
 
82
- categories = """Hello=Hello, how are you doing today?;Hi, everybody.;Hi;My name's Johnny
83
- What=most advanced conversation intelligence and AI powered coaching platform;a software platform that helps people reach their potential
84
- How=integrated into video conference platforms;record yourself
85
- Who=everyone is having conversations;if you're an entry-level person
86
- Impact=customer experience;communicating with the customer
87
- Bye=Bye.;And I look forward to talking to you again soon. Thank you very much."""
88
 
89
  with gr.Blocks(css=".gradio-container { background-color: white; background-image: url('file=./qc-logo.png'); background-size: 75px 75px; background-repeat: no-repeat; background-position: 0px 0px; }") as demo:
90
  gr.Markdown(f"# {' ' * 8}Transcript classifier with Roberta")
@@ -93,11 +77,12 @@ with gr.Blocks(css=".gradio-container { background-color: white; background-imag
93
  with gr.Row():
94
  target = gr.Textbox(lines=3, label="Categories", placeholder="Target categories")
95
  btn = gr.Button(value="Compare!", variant="primary")
 
 
 
96
  with gr.Row():
97
  grid = gr.Dataframe(wrap=True)
98
- with gr.Row():
99
- plot = gr.Plot()
100
- btn.click(fn=compare_text, inputs=[source,target], outputs=[grid,plot])
101
  gr.Examples([
102
  ["Hello, how are you doing today? I'm here to tell you a little bit about, uh, quantified communications and the quantified platform and how it impacts organizations, who it helps and how it works. So I'll get started off by telling you just a little bit about a high level about, um, the quantified platform. Oh, so the quantified platform is one of the most advanced communication intelligence in AI powered coaching systems. And what does that really mean? So, um, communication coaching is something that is typically delivered one on one between a communication coach who has a, uh, a doctorate or a, um, background and experience in teaching people how to be better communicators and how to express themselves effectively. Um, those coaches would work one-on-one with individuals, um, maybe put their information in front of audiences and see how well they respond. And that can be a very costly process as well as a time consuming. And, um, not always backed by the science of what really drives great communication. So the quantified platform allows all of that to be automated through our AI coaching system. Um, our system empowers, um, uh, is empowered by behavioral science in order to be able to take videos into the system and be able to render exactly how a audience is going to perceive you and provide the communication feedback that you need in order to be, become a better communicator. So that helps you sell more, that helps drive better experiences and improves your external communication with your clients. So how does it work? Um, I touched on that a little bit, um, but let me kind of unpack exactly the science behind it. Um, so we started off with a, a large swath of videos of from fantastic communicators, all the people that you would idolize and wanna be like, and we took those videos and we put them in front of panelists and we scored them to see exactly how well they would perform in front of an audience. So how likable, uh, uh, was that speaker, um, how effective were they at communicating their ideas? You know, were they persuasive? Would you actually buy something from them? Did you wanna listen to them longer? Um, did you find them engaging? These things are innately human in their, um, in how communication elicits a response from us? Those are the types of things that we actually measured and built an algorithm around. So the way that the system works is it, um, uh, you are allowed to record yourself inside the application. Um, we also embed into video conferencing platforms as well. So you can invite a bot into your live meeting conversations if you wish. And we have other integration options as well, including having a role playing conversations inside the application. Um, once we have that, the system analyzes, uh, the video content for the words that you say, so your sentence structure, phrases, um, sentiment analysis, pronoun usage, ver burb tone and usage. Um, how you conduct your face, the microexpressions that you have, um, do you appear happy, calm, angry, and your gestures? Um, you know, part of being an appealing, um, conversationalist is being engaging and have people want to, <laugh> want to listen to you. And, and so all of these things all come together into really, um, defining what makes a great piece of communication. And we use that as our benchmark of how to define that inside of our platform. So when you go into the platform, you're really being measured against the best communicators, as well as our entire community of people using the quantified platforms. So you can see where you are against other, um, roles, similar to yours, other people, similar career paths, and see how you grow and, um, get better from there and to optimize your behavior. So who does it help? Um, it can help everybody, everybody can improve their lives, their personal lives, their professional lives, um, their business contacts, their ability to be able to sell and deliver products, um, through having better communications and being able to effectively deliver your message. This is fantastic for people in leadership programs who are looking to accelerate to senior executive executive positions, uh, who are looking to improve their status inside of an organization, their ability to be a leader and be inspiring, um, as well as entry level people who really want to represent their brand well, they wanna have a great impact on their external customer experience, as well as their internal ones. And this, this whole system can be tailored specifically for an organization so that we identify the key characteristics of your top sales leaders, your top performers, your top leaders, and replicate that across the rest of your organization. So it doesn't come with a one size fits all. It is very specific on thinking about the characteristics and the behavioral patterns and the communication styles of those who are already effective inside your organization and creating the patterns to duplicate that. So depending on, on your brand presence and what you value inside of your organization, that can be replicated at scale. So who's it gonna have the greatest impact on, um, those participating in customer experiences, those communicating with customers directly, um, uh, spending time with members of your team, inspiring them, providing leadership guidance, visibility into the overall vision of an organization. Um, there are so much science out there that says really effective leaders lead from great communication. Um, and we wanna remake those people remarkably better. Everybody can improve their communication and everybody deserves to be a great communicator. Um, we see growth early on in the process. So, um, as people participate in the program, they usually, uh, get about 30% better within their first six weeks to 12 weeks. So there's a huge uptick in ability to be able to become more trustworthy, authentic, credible, um, have better collective performances across your team and across your organization and have that individual growth as a team leader. Um, this is all based on evidence based research and a ton of analytics, which we're all very, very proud of. Uh, so I hope that explains our quantified platform. And I look forward to talking to you again soon. Thank you very much.",categories],
103
  ["Hi, everybody. I'm really excited to be first here to try this out. Not only do I get to go first and be the Guinea pig, but I also know that I will be first on the leaderboard. So tell me about quantified. What is it exactly quantified is an AI powered coaching platform. We are here to make people remarkably better communicators by combining behavioral science, artificial intelligence, and experiential learning to give them the experience of what the world's best communication coach would do with them. If they were sitting with them in every single conversation they had, we know that through our intelligence insights feedback, and we can help people go from not knowing where they stand, when it comes to being how they communicate to becoming exceptional, confident, and inspirational in the way that they communicate, build relationships and succeed professionally in their career. So how does it work? Quantified works by 10, the behaviors that you do, what you do with your voice, your face, your gestures, and your words, and understanding how that an audience is going to react to that we have essentially built a audience digital twin that predicts how people are going to respond to you when you speak. And the technology behind that is really complex, but what's important is the experience is actually pretty simple. We just need a video. So we need a three minute video from you. From those three minutes, we pull out 1400 behaviors and predict audience preference, give you feedback, give you coaching, give you guidance and support your learning journey. So you can go from where you are today to being exceptional in the way that you communicate and speak. Who's helped most by quantified. Well, everybody communicates all day as part of their jobs. We actually study that 80% of your time at work is spent communicating. So who's helped most anyone that talks to customers, anyone that talks to other team members, anyone that talks to people for a living is going to be helped the most, really the more that you communicate as a critical component of your job, the more you're gonna be helped. Finally, how can quantified have the greatest impact on my organization? Well, my organization is quantified, so that's a little bit of a strange answer for me, but, you know, I think directly even what we do for our customers is really important for us, right? Have to represent that we have to represent effective communication to each other and to our clients. And so quantified becoming an exceptional communicator, supporting each other and teaching teaching what great coaching looks like is something that every organization can benefit, certainly including us. And so I'm excited to bring this knowledge and this program to our ourselves and, um, you know, I'm really excited to kick it off. Uh, thank you for allowing me to be first here and let's see how these scores come out. Bye.",categories],
 
11
 
12
  nlp = spacy.load("en_core_web_sm")
13
 
14
+ def transcript_to_sentences(transcript):
15
+ doc = nlp(transcript)
16
+ sentences = [ sentence.text for sentence in list(doc.sents) ]
17
+ # print(sentences[:3])
18
+ return sentences
19
+
20
  def calculate_embeddings_with_roberta(text):
21
  embeddings = model.encode(text, convert_to_tensor=True)
22
  return embeddings
 
48
  return df_category_list
49
 
50
  def compare_text(transcript, categories):
51
+ df_sentences = pd.DataFrame(columns=['line', 'sentence', 'embedding'])
52
+ for idx, sentence in enumerate(transcript_to_sentences(transcript)):
53
+ embedding = calculate_embeddings_with_roberta(sentence)
54
+ # Create new row
55
+ new_row = {
56
+ 'line': idx + 1,
57
+ 'sentence': sentence,
58
+ 'embedding': embedding
59
+ }
60
+ df_sentences = df_sentences.append(new_row, ignore_index=True)
61
+ # print(df_sentences.shape)
62
+ # df_sentences.head()
63
+ return df_sentences
64
+ #return res, fig, details
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
65
 
66
+ categories = """Hello=Hello, how are you doing today?;Hi, everybody;Hi;My name's Johnny
67
+ What=most advanced conversation intelligence and AI powered coaching platform;a software platform that helps people reach their potential;for communicating and connecting;empowered by behavioral science;uses artificial intelligence;drives performance outcomes for customer facing teams;help them sell more;help them deliver better experiences
68
+ How=integrated into video conference platforms;record yourself;prompts with fun and realistic experiences;That's all we need you to do;have conversations like the types you have every day;we've built technology;looks at the words that you say;what you do with your voice;your face;your gestures;simple input;create benchmarking;scoring feedback;personalized guidance;understand how you come across;relay to you how you're doing;how you can get better;coach you using artificial intelligence;as if the world's best communication coach was sitting there with you in every one of your conversations;telling you how to get better;telling you how to optimize your behavior
69
+ Who=everyone is having conversations;if you're an entry-level person;If you’re the most senior executive;the most powerful group that we can help are customer facing teams;sales teams, customer service teams, customer support, and customer success teams;anyone who is talking to the customer as a core part of their day-to-day job;words that they use, the way that they present themselves, how they come across;has an impact on the performance outcomes of the organization;giving coaching to them;coaching them at scale that is standardized and scientific;It's hard to find time for the managers to coach;It's hard for us to give feedback;It's hard for people to feel empowered, to work on something that is personal and private in a safe space
70
+ Impact=customer experience;communicating with the customer;spending time;spending a lot of time communicating;With other members of your team;internal communication and external communication;we want to make you remarkably better;we want to make you extraordinary at that behavior;meant to be learned along the way;No one at work can stop you for six months, 12 months, 18 months helping you become exceptional;your leadership journey;this is the most important skill right now for you;they don't have the time and they don't know how to do it;we can provide intentional guidance;deliver that on a personal basis for every single member of your organization that faces the customer;30% better at connecting with other people;measured by evidence-based research;the impact that that could have on individual performance;your individual growth as a leader;collective performance of the teams in the organization;make you be perceived as trustworthy, authentic, credible;improve how you connect
71
+ Bye=Bye;And I look forward to talking to you again soon. Thank you very much"""
72
 
73
  with gr.Blocks(css=".gradio-container { background-color: white; background-image: url('file=./qc-logo.png'); background-size: 75px 75px; background-repeat: no-repeat; background-position: 0px 0px; }") as demo:
74
  gr.Markdown(f"# {'&nbsp;' * 8}Transcript classifier with Roberta")
 
77
  with gr.Row():
78
  target = gr.Textbox(lines=3, label="Categories", placeholder="Target categories")
79
  btn = gr.Button(value="Compare!", variant="primary")
80
+ #with gr.Row():
81
+ # label = gr.Label()
82
+ # plot = gr.Plot()
83
  with gr.Row():
84
  grid = gr.Dataframe(wrap=True)
85
+ btn.click(fn=compare_text, inputs=[source,target], outputs=[grid])
 
 
86
  gr.Examples([
87
  ["Hello, how are you doing today? I'm here to tell you a little bit about, uh, quantified communications and the quantified platform and how it impacts organizations, who it helps and how it works. So I'll get started off by telling you just a little bit about a high level about, um, the quantified platform. Oh, so the quantified platform is one of the most advanced communication intelligence in AI powered coaching systems. And what does that really mean? So, um, communication coaching is something that is typically delivered one on one between a communication coach who has a, uh, a doctorate or a, um, background and experience in teaching people how to be better communicators and how to express themselves effectively. Um, those coaches would work one-on-one with individuals, um, maybe put their information in front of audiences and see how well they respond. And that can be a very costly process as well as a time consuming. And, um, not always backed by the science of what really drives great communication. So the quantified platform allows all of that to be automated through our AI coaching system. Um, our system empowers, um, uh, is empowered by behavioral science in order to be able to take videos into the system and be able to render exactly how a audience is going to perceive you and provide the communication feedback that you need in order to be, become a better communicator. So that helps you sell more, that helps drive better experiences and improves your external communication with your clients. So how does it work? Um, I touched on that a little bit, um, but let me kind of unpack exactly the science behind it. Um, so we started off with a, a large swath of videos of from fantastic communicators, all the people that you would idolize and wanna be like, and we took those videos and we put them in front of panelists and we scored them to see exactly how well they would perform in front of an audience. So how likable, uh, uh, was that speaker, um, how effective were they at communicating their ideas? You know, were they persuasive? Would you actually buy something from them? Did you wanna listen to them longer? Um, did you find them engaging? These things are innately human in their, um, in how communication elicits a response from us? Those are the types of things that we actually measured and built an algorithm around. So the way that the system works is it, um, uh, you are allowed to record yourself inside the application. Um, we also embed into video conferencing platforms as well. So you can invite a bot into your live meeting conversations if you wish. And we have other integration options as well, including having a role playing conversations inside the application. Um, once we have that, the system analyzes, uh, the video content for the words that you say, so your sentence structure, phrases, um, sentiment analysis, pronoun usage, ver burb tone and usage. Um, how you conduct your face, the microexpressions that you have, um, do you appear happy, calm, angry, and your gestures? Um, you know, part of being an appealing, um, conversationalist is being engaging and have people want to, <laugh> want to listen to you. And, and so all of these things all come together into really, um, defining what makes a great piece of communication. And we use that as our benchmark of how to define that inside of our platform. So when you go into the platform, you're really being measured against the best communicators, as well as our entire community of people using the quantified platforms. So you can see where you are against other, um, roles, similar to yours, other people, similar career paths, and see how you grow and, um, get better from there and to optimize your behavior. So who does it help? Um, it can help everybody, everybody can improve their lives, their personal lives, their professional lives, um, their business contacts, their ability to be able to sell and deliver products, um, through having better communications and being able to effectively deliver your message. This is fantastic for people in leadership programs who are looking to accelerate to senior executive executive positions, uh, who are looking to improve their status inside of an organization, their ability to be a leader and be inspiring, um, as well as entry level people who really want to represent their brand well, they wanna have a great impact on their external customer experience, as well as their internal ones. And this, this whole system can be tailored specifically for an organization so that we identify the key characteristics of your top sales leaders, your top performers, your top leaders, and replicate that across the rest of your organization. So it doesn't come with a one size fits all. It is very specific on thinking about the characteristics and the behavioral patterns and the communication styles of those who are already effective inside your organization and creating the patterns to duplicate that. So depending on, on your brand presence and what you value inside of your organization, that can be replicated at scale. So who's it gonna have the greatest impact on, um, those participating in customer experiences, those communicating with customers directly, um, uh, spending time with members of your team, inspiring them, providing leadership guidance, visibility into the overall vision of an organization. Um, there are so much science out there that says really effective leaders lead from great communication. Um, and we wanna remake those people remarkably better. Everybody can improve their communication and everybody deserves to be a great communicator. Um, we see growth early on in the process. So, um, as people participate in the program, they usually, uh, get about 30% better within their first six weeks to 12 weeks. So there's a huge uptick in ability to be able to become more trustworthy, authentic, credible, um, have better collective performances across your team and across your organization and have that individual growth as a team leader. Um, this is all based on evidence based research and a ton of analytics, which we're all very, very proud of. Uh, so I hope that explains our quantified platform. And I look forward to talking to you again soon. Thank you very much.",categories],
88
  ["Hi, everybody. I'm really excited to be first here to try this out. Not only do I get to go first and be the Guinea pig, but I also know that I will be first on the leaderboard. So tell me about quantified. What is it exactly quantified is an AI powered coaching platform. We are here to make people remarkably better communicators by combining behavioral science, artificial intelligence, and experiential learning to give them the experience of what the world's best communication coach would do with them. If they were sitting with them in every single conversation they had, we know that through our intelligence insights feedback, and we can help people go from not knowing where they stand, when it comes to being how they communicate to becoming exceptional, confident, and inspirational in the way that they communicate, build relationships and succeed professionally in their career. So how does it work? Quantified works by 10, the behaviors that you do, what you do with your voice, your face, your gestures, and your words, and understanding how that an audience is going to react to that we have essentially built a audience digital twin that predicts how people are going to respond to you when you speak. And the technology behind that is really complex, but what's important is the experience is actually pretty simple. We just need a video. So we need a three minute video from you. From those three minutes, we pull out 1400 behaviors and predict audience preference, give you feedback, give you coaching, give you guidance and support your learning journey. So you can go from where you are today to being exceptional in the way that you communicate and speak. Who's helped most by quantified. Well, everybody communicates all day as part of their jobs. We actually study that 80% of your time at work is spent communicating. So who's helped most anyone that talks to customers, anyone that talks to other team members, anyone that talks to people for a living is going to be helped the most, really the more that you communicate as a critical component of your job, the more you're gonna be helped. Finally, how can quantified have the greatest impact on my organization? Well, my organization is quantified, so that's a little bit of a strange answer for me, but, you know, I think directly even what we do for our customers is really important for us, right? Have to represent that we have to represent effective communication to each other and to our clients. And so quantified becoming an exceptional communicator, supporting each other and teaching teaching what great coaching looks like is something that every organization can benefit, certainly including us. And so I'm excited to bring this knowledge and this program to our ourselves and, um, you know, I'm really excited to kick it off. Uh, thank you for allowing me to be first here and let's see how these scores come out. Bye.",categories],