jerry f commited on
Commit
ec2398c
·
1 Parent(s): e13cd9e
.gitignore ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+ # Default ignored files
2
+ /.idea/*
3
+ /.venv/*
4
+ /__pycache__/*
5
+ /.segments/*
6
+ ../.segments/*
7
+ ../.segments/
8
+ ../__pycache__/
LICENSE ADDED
@@ -0,0 +1,201 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
README.md CHANGED
@@ -1,12 +1,12 @@
1
  ---
2
- title: Streamlit Template Space
3
  emoji: 🚀
4
  colorFrom: red
5
  colorTo: red
6
  sdk: docker
7
  app_port: 8501
8
  tags:
9
- - streamlit
10
  pinned: false
11
  short_description: Streamlit template space
12
  ---
 
1
  ---
2
+ title: AICallCenter2
3
  emoji: 🚀
4
  colorFrom: red
5
  colorTo: red
6
  sdk: docker
7
  app_port: 8501
8
  tags:
9
+ - streamlit
10
  pinned: false
11
  short_description: Streamlit template space
12
  ---
make_env ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ pip uninstall torch torchvision torchaudio
2
+
3
+ pip install torch==2.7.0 --index-url https://download.pytorch.org/whl/cu126
4
+ pip install torchaudio==2.7.0 --index-url https://download.pytorch.org/whl/cu126
5
+ pip install torchvision==0.22.0 --index-url https://download.pytorch.org/whl/cu126
6
+
7
+ pip install -r requirements.txt
8
+
9
+ git config --global user.email "jerryf31415@gmail.com"
10
+ git config --global user.name "jerry flynn"
11
+
12
+ streamlit run ./src/app.py
requirements.txt CHANGED
@@ -1,3 +1,165 @@
1
- altair
2
- pandas
3
- streamlit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ accelerate==1.6.0
2
+ aiohappyeyeballs==2.6.1
3
+ aiohttp==3.11.17
4
+ aiosignal==1.3.2
5
+ alembic==1.15.2
6
+ altair==5.5.0
7
+ annotated-types==0.7.0
8
+ antlr4-python3-runtime==4.9.3
9
+ anyio==4.9.0
10
+ assemblyai==0.38.0
11
+ asteroid-filterbanks==0.4.0
12
+ async-timeout==5.0.1
13
+ attrs==25.3.0
14
+ bibtexparser==1.4.3
15
+ binaryornot==0.4.4
16
+ blinker==1.9.0
17
+ bracex==2.5.post1
18
+ cachetools==5.5.2
19
+ certifi==2025.1.31
20
+ cffi==1.17.1
21
+ chardet==5.2.0
22
+ charset-normalizer==3.4.1
23
+ click==8.1.8
24
+ colorama==0.4.6
25
+ colorlog==6.9.0
26
+ contourpy==1.3.2
27
+ cycler==0.12.1
28
+ distro==1.9.0
29
+ dnspython==2.7.0
30
+ docopt==0.6.2
31
+ einops==0.8.1
32
+ email_validator==2.2.0
33
+ exceptiongroup==1.2.2
34
+ filelock==3.18.0
35
+ filetype==1.2.0
36
+ fonttools==4.57.0
37
+ frozenlist==1.6.0
38
+ fsspec==2025.3.2
39
+ gitdb==4.0.12
40
+ GitPython==3.1.44
41
+ greenlet==3.2.0
42
+ h11==0.14.0
43
+ httpcore==1.0.8
44
+ httptools==0.6.4
45
+ httpx==0.28.1
46
+ huggingface-hub==0.30.2
47
+ HyperPyYAML==1.2.2
48
+ idna==3.10
49
+ insanely-fast-whisper==0.0.15
50
+ Jinja2==3.1.6
51
+ jiter==0.9.0
52
+ joblib==1.4.2
53
+ jsonschema==4.23.0
54
+ jsonschema-specifications==2025.4.1
55
+ julius==0.2.7
56
+ kiwisolver==1.4.8
57
+ lightning==2.5.1
58
+ lightning-utilities==0.14.3
59
+ llvmlite==0.44.0
60
+ Mako==1.3.10
61
+ markdown-it-py==3.0.0
62
+ MarkupSafe==3.0.2
63
+ matplotlib==3.10.1
64
+ mdurl==0.1.2
65
+ monty==2025.3.3
66
+ more-itertools==10.6.0
67
+ mpmath==1.3.0
68
+ mrcfile==1.5.4
69
+ multidict==6.4.3
70
+ narwhals==1.37.0
71
+ networkx==3.4.2
72
+ numba==0.61.2
73
+ numpy==2.2.5
74
+ omegaconf==2.3.0
75
+ openai==1.76.0
76
+ openai-whisper==20240930
77
+ optimum==1.24.0
78
+ optuna==4.3.0
79
+ orjson==3.10.16
80
+ packaging==24.2
81
+ palettable==3.3.3
82
+ pandas==2.2.3
83
+ pillow==11.2.1
84
+ plotly==6.0.1
85
+ primePy==1.3
86
+ propcache==0.3.1
87
+ protobuf==5.29.4
88
+ psutil==7.0.0
89
+ pyannote.audio==3.3.2
90
+ pyannote.core==5.0.0
91
+ pyannote.database==5.1.3
92
+ pyannote.metrics==3.2.1
93
+ pyannote.pipeline==3.0.1
94
+ pyarrow==20.0.0
95
+ pycparser==2.22
96
+ pydantic==2.11.3
97
+ pydantic_core==2.33.1
98
+ pydeck==0.9.1
99
+ pydub==0.25.1
100
+ Pygments==2.19.1
101
+ pymatgen==2025.4.24
102
+ pyparsing==3.2.3
103
+ python-dateutil==2.9.0.post0
104
+ python-dotenv==1.1.0
105
+ python-multipart==0.0.20
106
+ pytorch-lightning==2.5.1
107
+ pytorch-metric-learning==2.8.1
108
+ pytz==2025.2
109
+ PyYAML==6.0.2
110
+ referencing==0.36.2
111
+ regex==2024.11.6
112
+ requests==2.32.3
113
+ rich==14.0.0
114
+ rich-toolkit==0.14.3
115
+ rpds-py==0.24.0
116
+ ruamel.yaml==0.18.10
117
+ ruamel.yaml.clib==0.2.12
118
+ safetensors==0.5.3
119
+ scikit-learn==1.6.1
120
+ scipy==1.15.2
121
+ semver==3.0.4
122
+ sentencepiece==0.2.0
123
+ shellingham==1.5.4
124
+ six==1.17.0
125
+ smmap==5.0.2
126
+ sniffio==1.3.1
127
+ sortedcontainers==2.4.0
128
+ soundfile==0.13.1
129
+ speechbrain==1.0.3
130
+ spglib==2.6.0
131
+ SQLAlchemy==2.0.40
132
+ starlette==0.37.2
133
+ streamlit==1.44.1
134
+ streamlit-ace==0.1.1
135
+ streamlit-antd==0.8.3
136
+ streamlit-embeded==0.0.1
137
+ streamlit-molstar==0.4.21
138
+ sympy==1.13.1
139
+ tabulate==0.9.0
140
+ tenacity==9.1.2
141
+ tensorboardX==2.6.2.2
142
+ threadpoolctl==3.6.0
143
+ tiktoken==0.9.0
144
+ tokenizers==0.21.1
145
+ toml==0.10.2
146
+ torch-audiomentations==0.12.0
147
+ torch_pitch_shift==1.2.5
148
+ torchao
149
+ torchmetrics==1.7.1
150
+ tornado==6.4.2
151
+ tqdm==4.67.1
152
+ transformers==4.51.3
153
+ typer==0.15.2
154
+ typing-inspection==0.4.0
155
+ typing_extensions==4.13.2
156
+ tzdata==2025.2
157
+ ujson==5.10.0
158
+ uncertainties==3.2.3
159
+ urllib3==2.4.0
160
+ uvicorn==0.34.2
161
+ watchdog==6.0.0
162
+ watchfiles==1.0.5
163
+ wcmatch==10.0
164
+ websockets==15.0.1
165
+ yarl==1.20.0
requirements2.txt ADDED
Binary file (984 Bytes). View file
 
src/CallCenter.py ADDED
@@ -0,0 +1,98 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Install the assemblyai package by executing the command `pip3 install assemblyai` (macOS) or `pip install assemblyai` (Windows).
2
+ import io
3
+ import os
4
+ import time
5
+ from pyannote.audio import Pipeline
6
+
7
+ # Import the AssemblyAI module
8
+ from pprint import pprint
9
+ import torch
10
+ from transformers import pipeline
11
+ from transformers.utils import is_flash_attn_2_available
12
+ from pydub import AudioSegment
13
+ import numpy as np
14
+
15
+ from segment_wave_files import segment_wave_files
16
+ from transcribe_files import transcribe_segments
17
+ from transcript_analysis import transcript_analysis
18
+ #from huggingface_hub import login
19
+ #login()
20
+ hugging_face = os.environ.get("HUGGING_FACE")
21
+ pipelineDiary = Pipeline.from_pretrained(
22
+ "pyannote/speaker-diarization-3.1",
23
+ use_auth_token=hugging_face)
24
+
25
+ pipelineDiary.to(torch.device("cuda"))
26
+
27
+ def diarize_wav_file(file_name):
28
+ print("DIARIZING " + file_name)
29
+ start = time.time()
30
+ diarization = pipelineDiary(file_name, num_speakers=2)
31
+ print("Elapsed " + str(time.time() - start))
32
+ # {"waveform": audio_tensor, "sample_rate": sample_rate_tensor})
33
+ speakers = []
34
+ contSpeaker = ""
35
+ dict = None
36
+ for turn, _, speaker in diarization.itertracks(yield_label=True):
37
+ if contSpeaker != speaker:
38
+ if dict is not None:
39
+ speakers.append(dict)
40
+ dict = {'speaker': speaker, 'start': round(turn.start, 1),
41
+ 'end': round(turn.end, 1)}
42
+ contSpeaker = speaker
43
+ else:
44
+ dict['end'] = round(turn.end, 1)
45
+
46
+ return speakers
47
+
48
+
49
+ def convert_mono_16khz(location, file):
50
+ sound = AudioSegment.from_file(location+file, "wav")
51
+ sound = sound.set_channels(1)
52
+ sound = sound.set_frame_rate(16000)
53
+ sound.export(location+"16khz"+file, "wav")
54
+
55
+ location = os.path.join(".", "data") + os.sep
56
+ def get_included_files():
57
+ files = os.listdir(location)
58
+
59
+ return location, files
60
+
61
+ def main():
62
+
63
+ dir_list = os.listdir(location)
64
+ for file in dir_list :
65
+ #input_file=location+file
66
+ input_file='C:\\Users\\jerry\\Downloads\\SampleCallsWave\\Tech Support Help from Call Center Experts1.wav'
67
+
68
+ # apply pretrained pipeline
69
+ # Pass the audio tensor and sample rate to the pipeline
70
+ speakers = diarize_wav_file(input_file)
71
+
72
+ speakers = segment_wave_files(speakers, input_file)
73
+
74
+ transcript = transcribe_segments(speakers)
75
+ print(
76
+ "---------------------------------------------------------------------")
77
+ pprint(transcript)
78
+ print("---------------------------------------------------------------------")
79
+
80
+ summary = transcript_analysis(transcript)
81
+ pprint(summary) #.encode('utf-8').decode('utf-8'))
82
+ print("\n\n\n\n\n\n\n")
83
+
84
+ def convertMp3ToWav(file) :
85
+ # convert mp3 file to a wav file
86
+ sound = AudioSegment.from_mp3(file)
87
+ # sound.export(output_file, format="wav")
88
+
89
+ sample_rate = sound.frame_count() / sound.duration_seconds
90
+ print(sample_rate)
91
+ duration = sound.duration_seconds
92
+ sound = sound.set_frame_rate(16000)
93
+ sound = sound.set_channels(1)
94
+ outFile = os.path.splitext(file)[0]+".wav"
95
+ sound.export(outFile, format="wav")
96
+ return outFile
97
+
98
+ main()
src/app.py ADDED
@@ -0,0 +1,88 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import pandas as pd
3
+ from CallCenter import get_included_files, convertMp3ToWav, diarize_wav_file
4
+ import os
5
+
6
+ from segment_wave_files import segment_wave_files
7
+ from transcript_analysis import transcript_analysis
8
+ from transcribe_files import transcribe_segments
9
+
10
+ location, wave_files = get_included_files()
11
+
12
+
13
+ def main():
14
+ # --- Streamlit App ---
15
+ st.title("Call Center Analysis")
16
+
17
+ # --- Selectable Elements ---
18
+
19
+ def get_file_sel():
20
+ if selected_file is None:
21
+ return
22
+ st.session_state.selected_file = location+selected_file # Store the selected option in session state
23
+ st.write(f"{selected_file} is selected") # Display feedback
24
+ st.session_state.wave_file = st.session_state.selected_file
25
+
26
+ selected_file = st.selectbox("Select an element:", wave_files)
27
+ get_file_sel()
28
+
29
+ # --- File Upload ---
30
+ uploaded_file = st.file_uploader("Upload a file", type=['mp3', 'wav'])
31
+ if uploaded_file:
32
+ st.session_state.uploaded_file = uploaded_file.name
33
+ if st.session_state.uploaded_file is not None:
34
+ if os.path.splitext(uploaded_file.name)[1].lower()==".mp3":
35
+ bytes_data = uploaded_file.read() # read the content of the file in binary
36
+ if not os.path.exists("/tmp"):
37
+ os.makedirs("/tmp")
38
+
39
+ with open(os.path.join("/tmp", uploaded_file.name), "wb") as f:
40
+ f.write(bytes_data) # write this content elsewhere
41
+ wav_file = convertMp3ToWav(f"/tmp/{uploaded_file.name}")
42
+ st.session_state.wave_file = wav_file # Store the selected option in session state
43
+ else:
44
+ bytes_data = uploaded_file.read() # read the content of the file in binary
45
+ with open(os.path.join("/tmp", uploaded_file.name), "wb") as f:
46
+ f.write(bytes_data) # write this content elsewhere
47
+ st.session_state.wave_file = os.path.join("/tmp", uploaded_file.name) # Store the selected option in session state
48
+
49
+ st.write(f"You uploaded: {uploaded_file.name}") # Display feedback
50
+ uploaded_file = None
51
+
52
+ analysis = ""
53
+ # --- Start Button ---
54
+ if st.button("Start"):
55
+ if st.session_state.wave_file is not None:
56
+ with st.spinner("Please wait..."):
57
+ try:
58
+ speakers = diarize_wav_file(st.session_state.wave_file )
59
+
60
+ speakers = segment_wave_files(speakers, st.session_state.wave_file )
61
+
62
+ transcripts = transcribe_segments(speakers)
63
+ analysis = transcript_analysis(transcripts)
64
+ except Exception as e:
65
+ st.error(f"Error processing file: {st.session_state.wave_file}")
66
+ else:
67
+ st.warning("Please upload a file.")
68
+
69
+ # --- Reset Button ---
70
+ if st.button("Reset"):
71
+ st.experimental_rerun()
72
+
73
+ # --- Large Text Box (Display Only) ---
74
+ if analysis != "":
75
+ analysis = analysis[9:]
76
+ index=analysis.lower().find("sentiment")
77
+ summary=analysis[0:index].lstrip("\n")
78
+
79
+ sentiment = analysis[index:]
80
+ index=sentiment.lower().find(":")
81
+ sentiment = sentiment[index+1:].lstrip("\n")
82
+
83
+ height = 34*15
84
+ st.text_area("SUMMARY:", value=summary, disabled=True, height=height)
85
+ st.text_area("SENTIMENT:", value=sentiment, disabled=True, height=height)
86
+
87
+
88
+ main()
src/segment_wave_files.py ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ from pydub import AudioSegment
3
+ import shutil
4
+
5
+
6
+ def segment_wave_files(speakers, file):
7
+
8
+ folder = ".segments"
9
+ if os.path.exists(folder):
10
+ shutil.rmtree(folder)
11
+ if not os.path.exists(folder):
12
+ os.makedirs(folder)
13
+
14
+ audio = AudioSegment.from_file(file, format="wav")#.resample(sample_rate_Hz=8000, sample_width=2, channels=1)
15
+
16
+ i=0
17
+ speakers_out = []
18
+ for speaker in speakers:
19
+ # {'speaker': speaker, 'start': round(turn.start, 1), 'end': round(turn.end, 1)}
20
+ start = speaker['start']*1000
21
+ stop = speaker['end']*1000
22
+ clip = audio[start:stop]
23
+ clip_name = folder+"\\clipFor"+speaker['speaker']+"_"+str(i)+".wav"
24
+ i+=1
25
+ clip.export(clip_name, format="wav")
26
+ speaker['clipFile'] = clip_name
27
+ speakers_out.append(speaker)
28
+
29
+ return speakers_out
30
+
31
+
src/transcribe_files.py ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+
3
+ import whisper
4
+ import time
5
+ def transcribe_segments(speakers):
6
+ print(f"Whisper models {whisper.available_models()}")
7
+ model = whisper.load_model("tiny.en", device="cuda")
8
+ #model = whisper.load_model("medium.en", device="cuda")
9
+ # model = whisper.load_model("turbo", device="cuda")
10
+ #model = whisper.load_model("large-v3-turbo", device="cuda")
11
+ transcripts = []
12
+ input_file = ""
13
+ print("Transcribing ALL segments")
14
+ total_start = time.time()
15
+ for speaker in speakers:
16
+ # {'speaker': speaker, 'start': round(turn.start, 1),
17
+ # 'end': round(turn.end, 1), 'clipFile':clipName}
18
+ input_file = speaker['clipFile']
19
+
20
+ print("TRANSCRIBING " + input_file)
21
+ start = time.time()
22
+ transcript = model.transcribe(input_file)
23
+ print("Elapsed " + str(time.time() - start))
24
+ segments = transcript["segments"]
25
+ outText = ""
26
+ for segment in segments:
27
+ outText += segment['text']
28
+
29
+ transcripts.append(speaker['speaker']+" : "+outText)
30
+ os.remove(input_file)
31
+
32
+ print("Total Elapsed " + str(time.time() - total_start))
33
+ currdir= input_file[0:input_file.index('\\')]
34
+ os.rmdir(currdir)
35
+
36
+ return transcripts
src/transcript_analysis.py ADDED
@@ -0,0 +1,131 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from encodings.utf_8 import encode
2
+
3
+ from openai import OpenAI
4
+ import time
5
+ from transformers import pipeline
6
+
7
+ def use_openai(input):
8
+ client = OpenAI()
9
+ response = client.responses.create(
10
+ model="o3-mini-2025-01-31",
11
+ # model="gpt-4.1",
12
+ input=f"""You are an helpful assistant. Analyze the following transcript and
13
+ give a summary of the conversation. Also give the sentiment of each speaker
14
+ as the conversation progresses. Also replace Speaker_0x with name or title
15
+ if it can be derived from conversation. Response should only contain ascii
16
+ characters. {input}"""
17
+ )
18
+ return response.output_text
19
+
20
+ from transformers import BigBirdPegasusForConditionalGeneration, AutoTokenizer
21
+ def use_bigbird_pegasus_large_arxiv(input):
22
+
23
+ tokenizer = AutoTokenizer.from_pretrained("google/bigbird-pegasus-large-arxiv")
24
+
25
+ # by default encoder-attention is `block_sparse` with num_random_blocks=3, block_size=64
26
+ model = BigBirdPegasusForConditionalGeneration.from_pretrained("google/bigbird-pegasus-large-arxiv")
27
+
28
+ # decoder attention type can't be changed & will be "original_full"
29
+ # you can change `attention_type` (encoder only) to full attention like this:
30
+ model = BigBirdPegasusForConditionalGeneration.from_pretrained("google/bigbird-pegasus-large-arxiv", attention_type="original_full")
31
+
32
+ # you can change `block_size` & `num_random_blocks` like this:
33
+ model = BigBirdPegasusForConditionalGeneration.from_pretrained("google/bigbird-pegasus-large-arxiv", block_size=16, num_random_blocks=2)
34
+
35
+ input=f"""You are an helpful assistant. Analyze the following transcript and
36
+ give a summary of the conversation. Also give the sentiment of each speaker
37
+ as the conversation progresses. Also replace Speaker_0x with name or title
38
+ if it can be derived from conversation. Response should only contain ascii
39
+ characters. {input}"""
40
+ inputs = tokenizer(input, return_tensors='pt')
41
+ prediction = model.generate(**inputs)
42
+ prediction = tokenizer.batch_decode(prediction)
43
+
44
+ import torch
45
+
46
+ def use_huggingface(input):
47
+ # Define the model name
48
+ # model_name = "cnicu/t5-small-booksum"
49
+ # model_name = "sshleifer/distilbart-cnn-12-6"
50
+ #model_name = "facebook/bart-large-cnn"
51
+ model_name = "huggyllama/llama-7b"
52
+ #model_name = "google/pegasus-large"
53
+
54
+ # summarizer = pipeline(task="summarization", model=model_name, device_map="cuda")
55
+ summarizer = pipeline(task="summarization", model=model_name,
56
+ torch_dtype=torch.float16)
57
+
58
+
59
+ max_length = 1024
60
+ #input = "summarize the following transcript:"+input
61
+ # length = len(input)
62
+ # if length < 1024:
63
+ # max_length = length
64
+ # else:
65
+ # input = input[0:1023]
66
+ input = """ New York (CNN)When Liana Barrientos was 23 years old, she got married in Westchester County, New York.
67
+ A year later, she got married again in Westchester County, but to a different man and without divorcing her first husband.
68
+ Only 18 days after that marriage, she got hitched yet again. Then, Barrientos declared "I do" five more times, sometimes only within two weeks of each other.
69
+ In 2010, she married once more, this time in the Bronx. In an application for a marriage license, she stated it was her "first and only" marriage.
70
+ Barrientos, now 39, is facing two criminal counts of "offering a false instrument for filing in the first degree," referring to her false statements on the
71
+ 2010 marriage license application, according to court documents.
72
+ Prosecutors said the marriages were part of an immigration scam.
73
+ On Friday, she pleaded not guilty at State Supreme Court in the Bronx, according to her attorney, Christopher Wright, who declined to comment further.
74
+ After leaving court, Barrientos was arrested and charged with theft of service and criminal trespass for allegedly sneaking into the New York subway through an emergency exit, said Detective
75
+ Annette Markowski, a police spokeswoman. In total, Barrientos has been married 10 times, with nine of her marriages occurring between 1999 and 2002.
76
+ All occurred either in Westchester County, Long Island, New Jersey or the Bronx. She is believed to still be married to four men, and at one time, she was married to eight men at once, prosecutors say.
77
+ Prosecutors said the immigration scam involved some of her husbands, who filed for permanent residence status shortly after the marriages.
78
+ Any divorces happened only after such filings were approved. It was unclear whether any of the men will be prosecuted.
79
+ The case was referred to the Bronx District Attorney\'s Office by Immigration and Customs Enforcement and the Department of Homeland Security\'s
80
+ Investigation Division. Seven of the men are from so-called "red-flagged" countries, including Egypt, Turkey, Georgia, Pakistan and Mali.
81
+ Her eighth husband, Rashid Rajput, was deported in 2006 to his native Pakistan after an investigation by the Joint Terrorism Task Force.
82
+ If convicted, Barrientos faces up to four years in prison. Her next court appearance is scheduled for May 18.
83
+ """
84
+ # # Pass the long text to the model to summarize it with a maximum length of 50 tokens
85
+ outputs = summarizer(input, max_length=max_length, do_sample=False)
86
+ # , min_length = 25, max_length=500
87
+ # Access and print the summarized text in the outputs variable
88
+ return outputs[0]['summary_text']
89
+
90
+
91
+ from transformers import TorchAoConfig, AutoModelForCausalLM, AutoTokenizer
92
+
93
+ def use_huggingface2(input):
94
+ # Define the model name
95
+ # model_name = "cnicu/t5-small-booksum"
96
+ # model_name = "sshleifer/distilbart-cnn-12-6"
97
+ #model_name = "facebook/bart-large-cnn"
98
+ model_name = "huggyllama/llama-7b"
99
+ #model_name = "google/pegasus-large"
100
+
101
+ quantization_config = TorchAoConfig("int4_weight_only", group_size=128)
102
+ model = AutoModelForCausalLM.from_pretrained(
103
+ model_name,
104
+ torch_dtype=torch.bfloat16,
105
+ device_map="auto",
106
+ quantization_config=quantization_config
107
+ )
108
+
109
+ tokenizer = AutoTokenizer.from_pretrained(model_name)
110
+ input_ids = tokenizer(input, return_tensors="pt").to("cuda")
111
+
112
+ output = model.generate(**input_ids, cache_implementation="static")
113
+ print(tokenizer.decode(output[0], skip_special_tokens=True))
114
+
115
+ def transcript_analysis(transcript):
116
+ results = []
117
+ #print(os.environ['OPENAI_API_KEY'])
118
+
119
+ input=""
120
+ for speaker in transcript:
121
+ input += speaker + "\n"
122
+
123
+ start = time.time()
124
+ response = use_huggingface2(input)
125
+ # response = use_openai(input)
126
+ #response = use_bigbird_pegasus_large_arxiv(input)
127
+ stop = time.time()
128
+ elapsed=stop-start
129
+ print("transcript analysis consumed "+str(elapsed))
130
+
131
+ return response