enoreyes commited on
Commit
f4a0f65
1 Parent(s): 771b4d6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +3 -25
app.py CHANGED
@@ -53,46 +53,24 @@ speech_to_text = partial(
53
  )
54
 
55
  def summarize(diarized, summarization_pipeline):
56
- """
57
- diarized: a list of tuples. Each tuple has a string to be displayed and a label for highlighting.
58
- The start/end times are not highlighted [(speaker text, speaker id), (start time/end time, None)]
59
- check is a list of speaker ids whose speech will get summarized
60
- """
61
-
62
  text = ""
63
  for d in diarized:
64
  text += f"\n{d[1]}: {d[0]}"
65
 
66
- return call_summarize_api(text)
67
 
68
  def sentiment(diarized, emotion_pipeline):
69
- """
70
- diarized: a list of tuples. Each tuple has a string to be displayed and a label for highlighting.
71
- The start/end times are not highlighted [(speaker text, speaker id), (start time/end time, None)]
72
-
73
- This function gets the customer's sentiment and returns a list for highlighted text.
74
- """
75
-
76
  customer_sentiments = []
77
 
78
  for i in range(0, len(diarized), 2):
79
  speaker_speech, speaker_id = diarized[i]
80
- times, _ = diarized[i + 1]
81
-
82
  sentences = split(speaker_speech)
83
-
84
- start_time, end_time = times[5:].split("-")
85
- start_time, end_time = float(start_time), float(end_time)
86
- interval_size = (end_time - start_time) / len(sentences)
87
- if "Customer" in speaker_id:
88
 
 
89
  outputs = emotion_pipeline(sentences)
90
-
91
  for idx, (o, t) in enumerate(zip(outputs, sentences)):
92
  if o["score"] > thresholds[o["label"]]:
93
- customer_sentiments.append(
94
- (t + f"({round(idx*interval_size+start_time,1)} s)", o["label"])
95
- )
96
 
97
  return customer_sentiments
98
 
 
53
  )
54
 
55
  def summarize(diarized, summarization_pipeline):
 
 
 
 
 
 
56
  text = ""
57
  for d in diarized:
58
  text += f"\n{d[1]}: {d[0]}"
59
 
60
+ return summarization_pipeline(text)[0]["summary_text"]
61
 
62
  def sentiment(diarized, emotion_pipeline):
 
 
 
 
 
 
 
63
  customer_sentiments = []
64
 
65
  for i in range(0, len(diarized), 2):
66
  speaker_speech, speaker_id = diarized[i]
 
 
67
  sentences = split(speaker_speech)
 
 
 
 
 
68
 
69
+ if "Customer" in speaker_id:
70
  outputs = emotion_pipeline(sentences)
 
71
  for idx, (o, t) in enumerate(zip(outputs, sentences)):
72
  if o["score"] > thresholds[o["label"]]:
73
+ customer_sentiments.append((t, o["label"]))
 
 
74
 
75
  return customer_sentiments
76