Skip to content

Commit

Permalink
feat(audioanalyser): ✨ added summarization capabilities and WIP UI
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastienrousseau committed Jan 10, 2024
1 parent 0f3d8ac commit 442d800
Show file tree
Hide file tree
Showing 184 changed files with 30,676 additions and 298 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Basic Makefile for AzureSpeechToText Application

# Copyright (C) 2023 Sebastien Rousseau.
# Copyright (C) 2023-2024 Sebastien Rousseau.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ The minimum supported Python version is 3.6.

- Azure Cognitive Services for speech and text processing.
- CherryPy for the web server.
- Open AI Services for summarization.
- Python's standard libraries including asyncio, sqlite3, and threading.

![divider][divider]
Expand Down
1 change: 1 addition & 0 deletions analysis_status.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Completed
4 changes: 2 additions & 2 deletions audioanalyser/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (C) 2023 Sebastien Rousseau.
# Copyright (C) 2023-2024 Sebastien Rousseau.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand All @@ -14,4 +14,4 @@
# limitations under the License.

"""The Python Audio Analyser module."""
__version__ = "0.0.1"
__version__ = "0.0.2"
13 changes: 12 additions & 1 deletion audioanalyser/__main__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (C) 2023 Sebastien Rousseau.
# Copyright (C) 2023-2024 Sebastien Rousseau.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -27,6 +27,7 @@
from audioanalyser.modules.azure_speech_to_text import azure_speech_to_text
from audioanalyser.modules.azure_text_analysis import azure_text_analysis
from audioanalyser.modules.audio_analyser_server import audio_analyser_server
from audioanalyser.modules.azure_recommendation import azure_recommendation


def main():
Expand Down Expand Up @@ -60,6 +61,14 @@ def main():
points.
'''
)
parser.add_argument(
'-rec',
'--recommendation',
action='store_true',
help='''
This command generates recommendations based on the specified transcript.
'''
)
parser.add_argument(
'-s',
'--server',
Expand All @@ -77,6 +86,8 @@ def main():
azure_speech_to_text()
elif args.text_analysis:
azure_text_analysis()
elif args.recommendation:
azure_recommendation()
elif args.server:
audio_analyser_server()
else:
Expand Down
2 changes: 1 addition & 1 deletion audioanalyser/modules/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (C) 2023 Sebastien Rousseau.
# Copyright (C) 2023-2024 Sebastien Rousseau.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down
149 changes: 149 additions & 0 deletions audioanalyser/modules/audio_analyser_server.bak
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
import cherrypy
import glob
import os
import io
import sys
import threading
import asyncio

# Import your custom functions
from audioanalyser.modules.azure_speech_to_text import azure_speech_to_text
from audioanalyser.modules.azure_text_analysis import azure_text_analysis


class SpeechTextAnalysisServer:
@cherrypy.expose
def index(self):
return open('docs/index.html')

@cherrypy.expose
@cherrypy.tools.json_out()
def process_all_speech_to_text(self):
try:
# Redirect stdout to capture logs
old_stdout = sys.stdout
sys.stdout = log_capture_string = io.StringIO()

# Run the speech-to-text process
azure_speech_to_text()

# Reset stdout and get log output
sys.stdout = old_stdout
log_output = log_capture_string.getvalue()

return {"result": "Processing completed", "logs": log_output}
except Exception as e:
cherrypy.log(f"Error during speech-to-text processing: {str(e)}")
cherrypy.response.status = 500
return {
"error": "An error occurred during speech-to-text processing"
}

@cherrypy.expose
@cherrypy.tools.json_out()
def process_text_analysis(self):
try:
# Run the text analysis process in a separate thread
thread = threading.Thread(target=self.run_analysis_thread)
thread.start()
return {"result": "Text analysis process started"}
except Exception as e:
cherrypy.log(f"Error during text analysis: {str(e)}")
cherrypy.response.status = 500
return {"error": "An error occurred during text analysis"}

def run_analysis_thread(self):
temporary_folder = './'
status_file_path = os.path.join(
temporary_folder,
'analysis_status.txt'
)
try:
asyncio.run(azure_text_analysis())
with open(status_file_path, 'w') as file:
file.write('Completed')
except Exception as e:
with open(status_file_path, 'w') as file:
file.write(f'Error: {str(e)}')

@cherrypy.expose
@cherrypy.tools.json_out()
def get_analysis_status(self):
temporary_folder = './'
status_file_path = os.path.join(
temporary_folder,
'analysis_status.txt'
)
if os.path.exists(status_file_path):
with open(status_file_path, 'r') as file:
status = file.read()
return {"status": status}
else:
return {"status": "Processing"}

@cherrypy.expose
@cherrypy.tools.json_out()
def get_transcripts_list(self):
outputs_folder = './resources/transcripts/'
try:
# Find all transcript files in the Outputs folder
list_of_files = glob.glob(os.path.join(outputs_folder, '*.txt'))
transcripts = []
for file_path in list_of_files:
with open(file_path, 'r') as file:
content = file.read()
transcripts.append(
{
"filename": os.path.basename(file_path),
"content": content
}
)
return transcripts
except IOError:
cherrypy.response.status = 500
return {"error": "Error reading transcript files."}

@cherrypy.expose
@cherrypy.tools.json_out()
def get_reports_list(self):
outputs_folder = './resources/reports/'
try:
# Find all report files in the Outputs folder
list_of_files = glob.glob(os.path.join(outputs_folder, '*.txt'))
reports = []
for file_path in list_of_files:
with open(file_path, 'r') as file:
content = file.read()
reports.append(
{
"filename": os.path.basename(file_path),
"content": content
}
)
return reports
except IOError:
cherrypy.response.status = 500
return {"error": "Error reading report files."}


def audio_analyser_server():
current_dir = os.path.dirname(os.path.abspath(__file__))
print('Current directory: ' + current_dir)
project_root = os.path.abspath(os.path.join(current_dir, '../..'))
print('Project root: ' + project_root)
docs_dir = os.path.join(project_root, 'docs')
print('Docs directory: ' + docs_dir)

config = {
'/': {
'tools.staticdir.on': True,
'tools.staticdir.dir': docs_dir, # Set current_dir to docs_dir
'tools.staticdir.index': 'index.html',
},
}
cherrypy.config.update({'server.socket_port': 8080})
cherrypy.quickstart(SpeechTextAnalysisServer(), '/', config)


if __name__ == '__main__':
audio_analyser_server()
67 changes: 64 additions & 3 deletions audioanalyser/modules/audio_analyser_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@
# Import your custom functions
from audioanalyser.modules.azure_speech_to_text import azure_speech_to_text
from audioanalyser.modules.azure_text_analysis import azure_text_analysis
from audioanalyser.modules.azure_recommendation import azure_recommendation


class SpeechTextAnalysisServer:
@cherrypy.expose
def index(self):
return open('index.html')
return open('dashboard/index.html')

@cherrypy.expose
@cherrypy.tools.json_out()
Expand Down Expand Up @@ -125,15 +126,75 @@ def get_reports_list(self):
cherrypy.response.status = 500
return {"error": "Error reading report files."}

@cherrypy.expose
@cherrypy.tools.json_out()
def get_summaries_list(self):
outputs_folder = './resources/recommendations/'
try:
# Find all report files in the Outputs folder
list_of_files = glob.glob(os.path.join(outputs_folder, '*.txt'))
reports = []
for file_path in list_of_files:
with open(file_path, 'r') as file:
content = file.read()
reports.append(
{
"filename": os.path.basename(file_path),
"content": content
}
)
return reports
except IOError:
cherrypy.response.status = 500
return {"error": "Error reading report files."}

@cherrypy.expose
@cherrypy.tools.json_out()
def generate_recommendations(self):

try:
# Run the executive summary generation process in a separate thread
thread = threading.Thread(target=self.run_recommendations_thread)
thread.start()
return {"result": "Process started"}
except Exception as e:
cherrypy.log(
f"Error during executive summary generation: {str(e)}"
)
cherrypy.response.status = 500
return {"error": "An error occurred during summary generation"}

def run_recommendations_thread(self):
temporary_folder = './'
status_file_path = os.path.join(
temporary_folder,
'recommendations_status.txt'
)
try:
asyncio.run(azure_recommendation())
with open(status_file_path, 'w') as file:
file.write('Completed')
except Exception as e:
with open(status_file_path, 'w') as file:
file.write(f'Error: {str(e)}')


def audio_analyser_server():
current_dir = os.path.dirname(os.path.abspath(__file__))
print('Current directory: ' + current_dir)
project_root = os.path.abspath(os.path.join(current_dir, '../..'))
print('Project root: ' + project_root)
dashboard_dir = os.path.join(project_root, 'dashboard')
print('Docs directory: ' + dashboard_dir)

config = {
'/': {
'tools.staticdir.on': True,
'tools.staticdir.dir': current_dir
}
'tools.staticdir.dir': dashboard_dir,
'tools.staticdir.index': 'index.html',
},
}
cherrypy.config.update({'server.socket_port': 8080})
cherrypy.quickstart(SpeechTextAnalysisServer(), '/', config)


Expand Down
Loading

0 comments on commit 442d800

Please sign in to comment.