We write a small application in Python to increase productivity using AI and BotHub API
Everyone is familiar with the situation: an important online meeting took place, tasks were distributed, ideas were discussed, but no one remembers who said what. It seems that in order not to miss anything, you need a separate person who writes down everything for everyone and makes reports. What if an app could do this? Moreover, do it quickly, accurately, and in several languages?
In this tutorial, I'll show you how to create an application for automated meeting analysis and reporting using the BotHub API. This application recognizes speech from audio recordings, highlights key points – who promised what and what tasks were discussed – and creates a convenient report. In addition, it works with calendars, video conferencing and instant messengers, so you can easily connect it to your usual work tools.
We'll go through everything step by step: from speech recognition to report generation, so that by the end you have a ready-made application that can become an ideal assistant for all those who are tired of manually taking notes from meetings.
Installing dependencies and setting up the project
Before we begin, let's make sure that we have all the necessary components installed, such as Python and libraries for working with APIs and audio files. We will install the following libraries:
os
Andpathlib.Path
: for working with environment variables and file paths.dotenv
: To load sensitive data from .env file.fpdf
: To generate PDF files.openai
: for work with the API provided by BotHub.
pip install python-dotenv fpdf openai
And import them:
import os
from pathlib import Path
from dotenv import load_dotenv
from fpdf import FPDF
from openai import OpenAI
import logging
We will also need logging
for logging the program execution process. Logging will help us track the progress of the program and also record any errors or important messages. We will set up basic logging at the level INFO
.
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(name)
Setting up access to BotHub API
To interact with the BotHub API, you must first register on the BotHub platform and get an API key. This key serves to authenticate the requests that we will send.
After receiving the key to ensure storage security, we create a file .env
in the root folder of our project and place the API key that we generated there.
BOTHUB_API_KEY=наш_ключ
Next, using the library dotenv
by using load_dotenv()
loading data from .env
to make them available to our code.
load_dotenv()
To work with the BotHub API, create an instance OpenAI
to which we transfer api_key
And base_url
for the BotHub service. The API key is loaded from the environment using os.getenv('BOTHUB_API_KEY')
client = OpenAI(
api_key=os.getenv('BOTHUB_API_KEY'),
base_url="https://bothub.chat/api/v2/openai/v1"
)
Main function for audio processing
In this step, we create a function that transcribes the audio file into text. We use BotHub API and Whisper-1 for speech recognition. Open the audio file in mode rb
(reading in binary mode), then use the method client.audio.transcriptions.create
to send an audio file to the server for processing. In response, we receive a text transcription. If transcription is successful, a Transcription Complete message is displayed and the text is returned for further processing. In case of an error, we log the error message.
def transcribe_audio(audio_file_path):
try:
with open(audio_file_path, "rb") as audio_file:
transcript = client.audio.transcriptions.create(
model="whisper-1",
file=audio_file
)
logger.info("Транскрипция завершена.")
return transcript.text
except Exception as e:
logger.error(f"Ошибка при транскрипции аудио: {e}")
return None
Extracting Key Points
After the transcription, we have the text of our meeting. Our goal now is to highlight the key points, such as the issues discussed, decisions made, and problems. By using client.chat.completions.create
create a request to highlight key points, indicating the model, the text of the meeting, and the request in the format messages
where it is described that it is necessary to highlight the main tasks and problems. The function returns a list of key points if successful.
def extract_key_points(meeting_text):
try:
response = client.chat.completions.create(
model="claude-3.5-sonnet",
messages=[
{
"role": "user",
"content": f"Проанализируй текст встречи и выдели ключевые моменты, такие как задачи, решения и обсуждаемые проблемы:\n\n{meeting_text}"
}
]
)
logger.info("Извлечение ключевых моментов завершено.")
return response.choices[0].message.content
except Exception as e:
logger.error(f"Ошибка при извлечении ключевых моментов: {e}")
return None
Key
We can also analyze the tone of the meeting text, just like in extract_key_points
used client.chat.completions.create
where we request a sentiment analysis of the transmitted text. The function returns the tone analysis result or an error message.
def analyze_sentiment(meeting_text):
try:
response = client.chat.completions.create(
model="claude-3.5-sonnet",
messages=[
{
"role": "user",
"content": f"Проанализируй тональность текста:\n\n{meeting_text}"
}
]
)
logger.info("Анализ тональности завершен.")
return response.choices[0].message.content
except Exception as e:
logger.error(f"Ошибка при анализе тональности: {e}")
return None
Generating a report
Once the key points have been identified and sentiment analysis has been carried out, we need to assemble a report from them. This report should be logical, consistent and concise. Used client.chat.completions.create
where we pass a request with the listed key points and sentiment analysis, so that the API generates the finished report text. If successful, the function returns the report text.
def generate_report(key_points, sentiment):
"""Создание отчета на основе ключевых моментов и тональности"""
try:
content = f"Составь отчет по встрече с учетом следующих ключевых моментов и анализа тональности:\n\nКлючевые моменты:\n{key_points}\n\nТональность:\n{sentiment}"
report = client.chat.completions.create(
model="claude-3.5-sonnet",
messages=[
{
"role": "user",
"content": content
}
]
)
logger.info("Генерация отчета завершена.")
return report.choices[0].message.content
except Exception as e:
logger.error(f"Ошибка при генерации отчета: {e}")
return None
To make the report convenient to store and forward, we save it in PDF format. Library is used to create PDF FPDF
. We add a page, set automatic text wrapping along lines (multi_cell
). Add a font that supports Cyrillic if necessary (the example uses DejaVu Sans), and set the font size for the main text. After creating the page and filling it with text, save the report using output(file_path)
.
def save_report_as_pdf(report_text, file_path="meeting_report.pdf"):
pdf = FPDF()
pdf.add_page()
pdf.set_auto_page_break(auto=True, margin=15)
pdf.add_font("DejaVu", "", "/Users/veseluhha/Library/Fonts/DejaVuSans.ttf", uni=True)
pdf.set_font("DejaVu", size=12)
pdf.multi_cell(0, 10, report_text)
pdf.output(file_path)
logger.info(f"Отчет сохранен как {file_path}")
Main function
This function combines all previous steps. It starts by transcribing the audio: if it fails, an error message is printed and the function exits. A function is then run to highlight key points. If an error occurs, it also returns an appropriate message. Similarly, sentiment analysis is performed and, if successful, report text is generated. If all steps are completed successfully, s is calledave_report_as_pdf
to save the report in PDF format. At the end, the function returns the text of the report.
def analyze_meeting(audio_file_path):
meeting_text = transcribe_audio(audio_file_path)
if not meeting_text:
return "Ошибка при транскрипции аудио."
key_points = extract_key_points(meeting_text)
if not key_points:
return "Ошибка при извлечении ключевых моментов."
sentiment = analyze_sentiment(meeting_text)
if not sentiment:
return "Ошибка при анализе тональности."
report_text = generate_report(key_points, sentiment)
if not report_text:
return "Ошибка при генерации отчета."
save_report_as_pdf(report_text)
return report_text
So, together with you, we have made a small application that can make your days more productive and help you manage your time more efficiently. We have implemented with you the order of the main functions, namely audio transcription, highlighting key points, drawing up a report and saving it in PDF format. Such a tool will allow you not to lose important ideas and tasks, saving time and effort.