upd
This commit is contained in:
parent
333c36c4fd
commit
a9623e6985
46
.dockerignore
Normal file
46
.dockerignore
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
# .dockerignore
|
||||||
|
|
||||||
|
# Игнорировать каталоги с кэшем и логами
|
||||||
|
__pycache__
|
||||||
|
*.pyc
|
||||||
|
*.pyo
|
||||||
|
*.pyd
|
||||||
|
*.log
|
||||||
|
|
||||||
|
# Игнорировать виртуальное окружение и зависимости
|
||||||
|
venv
|
||||||
|
*.egg-info/
|
||||||
|
dist/
|
||||||
|
build/
|
||||||
|
.virtualenv/
|
||||||
|
.pyenv/
|
||||||
|
|
||||||
|
# Игнорировать файлы и каталоги системы контроля версий
|
||||||
|
.git
|
||||||
|
.gitignore
|
||||||
|
.svn
|
||||||
|
.hg
|
||||||
|
.hgignore
|
||||||
|
|
||||||
|
# Игнорировать файлы конфигурации IDE и редакторов
|
||||||
|
.vscode/
|
||||||
|
.idea/
|
||||||
|
*.swp
|
||||||
|
*.swo
|
||||||
|
*.swn
|
||||||
|
*.bak
|
||||||
|
|
||||||
|
# Игнорировать файлы тестов и документации
|
||||||
|
tests/
|
||||||
|
docs/
|
||||||
|
|
||||||
|
# Игнорировать файлы для развертывания и среды
|
||||||
|
.dockerignore
|
||||||
|
Dockerfile
|
||||||
|
*.yml
|
||||||
|
*.yaml
|
||||||
|
*.sh
|
||||||
|
*.md
|
||||||
|
*.txt
|
||||||
|
!requirements.txt
|
||||||
|
LICENSE
|
||||||
@ -1,5 +1,10 @@
|
|||||||
FROM python:3.9-slim-buster
|
FROM python:3.9-slim-buster
|
||||||
|
|
||||||
|
# Установить зависимости для FFmpeg
|
||||||
|
RUN apt-get update && \
|
||||||
|
apt-get install -y --no-install-recommends ffmpeg && \
|
||||||
|
rm -rf /var/lib/apt/lists/*
|
||||||
|
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
COPY requirements.txt requirements.txt
|
COPY requirements.txt requirements.txt
|
||||||
|
|||||||
8
bot.py
8
bot.py
@ -11,6 +11,7 @@ import hashlib
|
|||||||
import threading
|
import threading
|
||||||
from datetime import datetime, timedelta
|
from datetime import datetime, timedelta
|
||||||
from transcription_dict import TranscriptionDict
|
from transcription_dict import TranscriptionDict
|
||||||
|
from custom_openai import CustomAudio
|
||||||
|
|
||||||
# Load the environment variables from the .env file
|
# Load the environment variables from the .env file
|
||||||
load_dotenv()
|
load_dotenv()
|
||||||
@ -146,19 +147,16 @@ def handle_voice_message(message):
|
|||||||
|
|
||||||
audio_bytes = bytearray(mp3_data.read())
|
audio_bytes = bytearray(mp3_data.read())
|
||||||
|
|
||||||
transcript = openai.Audio.transcribe("whisper-1", file=audio_bytes, filename="voice_message.mp3")
|
transcript = CustomAudio.transcribe("whisper-1", file=audio_bytes, filename="voice_message.mp3")
|
||||||
|
|
||||||
transcription = transcript['text']
|
transcription = transcript['text']
|
||||||
|
|
||||||
# Return the transcribed text back to the user
|
|
||||||
bot.reply_to(message, transcription)
|
|
||||||
|
|
||||||
transcription_hash = hashlib.md5(transcription.encode('utf-8')).hexdigest()[:8]
|
transcription_hash = hashlib.md5(transcription.encode('utf-8')).hexdigest()[:8]
|
||||||
transcription_dict.set(transcription_hash, transcription)
|
transcription_dict.set(transcription_hash, transcription)
|
||||||
|
|
||||||
markup = telebot.types.InlineKeyboardMarkup()
|
markup = telebot.types.InlineKeyboardMarkup()
|
||||||
markup.add(telebot.types.InlineKeyboardButton("Отправить текст", callback_data=f"voice_text:{transcription_hash}"))
|
markup.add(telebot.types.InlineKeyboardButton("Отправить текст", callback_data=f"voice_text:{transcription_hash}"))
|
||||||
bot.send_message(message.chat.id, f"Текст сообщения: {transcription}", reply_markup=markup)
|
bot.reply_to(message, transcription, reply_markup=markup)
|
||||||
else:
|
else:
|
||||||
bot.reply_to(message, "Не удалось получить голосовое сообщение.")
|
bot.reply_to(message, "Не удалось получить голосовое сообщение.")
|
||||||
|
|
||||||
|
|||||||
24
custom_openai.py
Normal file
24
custom_openai.py
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
from openai.api_resources.abstract import APIResource
|
||||||
|
from openai.api_resources.audio import Audio
|
||||||
|
from openai import util
|
||||||
|
|
||||||
|
class CustomAudio(Audio):
|
||||||
|
@classmethod
|
||||||
|
def transcribe(
|
||||||
|
cls,
|
||||||
|
model,
|
||||||
|
file,
|
||||||
|
filename,
|
||||||
|
api_key=None,
|
||||||
|
api_base=None,
|
||||||
|
api_type=None,
|
||||||
|
api_version=None,
|
||||||
|
organization=None,
|
||||||
|
**params,
|
||||||
|
):
|
||||||
|
requestor, files, data = cls._prepare_request(file, filename, model, **params)
|
||||||
|
url = cls._get_url("transcriptions")
|
||||||
|
response, _, api_key = requestor.request("post", url, files=files, params=data)
|
||||||
|
return util.convert_to_openai_object(
|
||||||
|
response, api_key, api_version, organization
|
||||||
|
)
|
||||||
Loading…
Reference in New Issue
Block a user