|
import requests |
|
import base64 |
|
import json |
|
import streamlit as st |
|
from speechlib import Transcriptor |
|
|
|
def transcribe_audio(file, log_folder, language, modelSize, ACCESS_TOKEN, voices_folder, quantization): |
|
transcriptor = Transcriptor(file, log_folder, language, modelSize, ACCESS_TOKEN, voices_folder, quantization) |
|
return transcriptor.whisper() |
|
|
|
def transform_transcript(transcript): |
|
result = [] |
|
for segment in transcript: |
|
start_time, end_time, text, speaker = segment |
|
result.append(f"{speaker} ({start_time:.1f} : {end_time:.1f}) : {text}") |
|
return '\n'.join(result) |
|
|
|
st.title('Audio Transcription App') |
|
|
|
ACCESS_TOKEN = st.secrets["HF_TOKEN"] |
|
|
|
uploaded_file = st.file_uploader("Загрузите аудиофайл", type=["mp4", "wav", "m4a"]) |
|
|
|
if uploaded_file is not None: |
|
file_extension = uploaded_file.name.split(".")[-1] |
|
temp_file_path = f"temp_file.{file_extension}" |
|
|
|
with open(temp_file_path, "wb") as f: |
|
f.write(uploaded_file.getbuffer()) |
|
|
|
log_folder = "logs" |
|
language = "ru" |
|
modelSize = "large" |
|
voices_folder = "" |
|
quantization = False |
|
|
|
with st.spinner('Транскрибируем...'): |
|
result = transcribe_audio(temp_file_path, log_folder, language, modelSize, ACCESS_TOKEN, voices_folder, quantization) |
|
|
|
st.write("Результат транскрибации:") |
|
transcript = transform_transcript(result) |
|
st.text(transcript) |
|
|
|
with st.spinner('Резюмируем...'): |
|
username = st.secrets["GIGA_USERNAME"] |
|
password = st.secrets["GIGA_SECRET"] |
|
|
|
|
|
auth_str = f'{username}:{password}' |
|
auth_bytes = auth_str.encode('utf-8') |
|
auth_base64 = base64.b64encode(auth_bytes).decode('utf-8') |
|
url = 'https://ngw.devices.sberbank.ru:9443/api/v2/oauth' |
|
|
|
headers = { |
|
'Authorization': f'Basic {auth_base64}', |
|
'RqUID': '6f0b1291-c7f3-43c6-bb2e-9f3efb2dc98f', |
|
'Content-Type': 'application/x-www-form-urlencoded', |
|
'Accept': 'application/json' |
|
} |
|
|
|
data = { |
|
'scope': 'GIGACHAT_API_PERS' |
|
} |
|
|
|
response = requests.post(url, headers=headers, data=data, verify=False) |
|
access_token = response.json()['access_token'] |
|
print('Got access token') |
|
|
|
url_completion = "https://gigachat.devices.sberbank.ru/api/v1/chat/completions" |
|
|
|
data_copm = json.dumps({ |
|
"model": "GigaChat", |
|
"messages": [ |
|
{ |
|
"role": "user", |
|
"content": "Напиши резюме транскрибации звонка, текст которого приложен в ниже. Выдели самостоятельно цель встречи, потом описать ключевые моменты всей встречи. Потом выделить отдельные темы звонка и выделить ключевые моменты в них. Напиши итоги того, о чем договорились говорящие, если такое возможно выделить из текста. Транскрибация: " + transcript |
|
} |
|
], |
|
"stream": False, |
|
"max_tokens": 1024, |
|
}) |
|
|
|
headers_comp = { |
|
'Content-Type': 'application/json', |
|
'Accept': 'application/json', |
|
'Authorization': 'Bearer ' + access_token |
|
} |
|
|
|
response = requests.post(url_completion, headers=headers_comp, data=data_copm, verify=False) |
|
response_data = response.json() |
|
answer_from_llm = response_data['choices'][0]['message']['content'] |
|
|
|
st.write("Результат резюмирования:") |
|
st.text(answer_from_llm) |