Skip to content

Commit 7f2a930

Browse files
committed
add batch transcription playground
1 parent feef266 commit 7f2a930

File tree

4 files changed

+123
-15
lines changed

4 files changed

+123
-15
lines changed

.env.template

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ AZURE_OPENAI_API_VERSION="2025-04-01-preview"
2020
AZURE_OPENAI_MODEL_CHAT="gpt-5"
2121
AZURE_OPENAI_MODEL_EMBEDDING="text-embedding-3-small"
2222
AZURE_OPENAI_MODEL_REASONING="o4-mini"
23+
AZURE_OPENAI_MODEL_STT="whisper"
2324

2425
## Azure AI Foundry
2526
AZURE_AI_FOUNDRY_INFERENCE_ENDPOINT="https://xxx.services.ai.azure.com/api/projects/xxx"

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ description = "A GitHub template repository for Python"
55
readme = "README.md"
66
requires-python = ">=3.10"
77
dependencies = [
8+
"audio-recorder-streamlit>=0.0.10",
89
"azure-ai-projects>=1.0.0",
910
"azure-cosmos>=4.9.0",
1011
"azure-identity>=1.23.1",
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
import tempfile
2+
from os import getenv
3+
4+
import streamlit as st
5+
from audio_recorder_streamlit import audio_recorder
6+
from dotenv import load_dotenv
7+
from langchain_community.document_loaders.parsers.audio import AzureOpenAIWhisperParser
8+
from langchain_core.documents.base import Blob
9+
10+
from template_langgraph.loggers import get_logger
11+
12+
load_dotenv(override=True)
13+
logger = get_logger(__name__)
14+
logger.setLevel("DEBUG")
15+
16+
with st.sidebar:
17+
"# Common Settings"
18+
azure_openai_endpoint = st.text_input(
19+
label="AZURE_OPENAI_ENDPOINT",
20+
value=getenv("AZURE_OPENAI_ENDPOINT"),
21+
key="AZURE_OPENAI_ENDPOINT",
22+
type="default",
23+
)
24+
azure_openai_api_key = st.text_input(
25+
label="AZURE_OPENAI_API_KEY",
26+
value=getenv("AZURE_OPENAI_API_KEY"),
27+
key="AZURE_OPENAI_API_KEY",
28+
type="password",
29+
)
30+
azure_openai_api_version = st.text_input(
31+
label="AZURE_OPENAI_API_VERSION",
32+
value=getenv("AZURE_OPENAI_API_VERSION"),
33+
key="AZURE_OPENAI_API_VERSION",
34+
type="default",
35+
)
36+
azure_openai_model_stt = st.text_input(
37+
label="AZURE_OPENAI_MODEL_STT",
38+
value=getenv("AZURE_OPENAI_MODEL_STT"),
39+
key="AZURE_OPENAI_MODEL_STT",
40+
type="default",
41+
)
42+
"### Documents"
43+
"[Azure OpenAI Whisper Parser](https://python.langchain.com/docs/integrations/document_loaders/parsers/azure_openai_whisper_parser/)"
44+
45+
st.title("🎤 Batch Transcription Playground")
46+
47+
audio_bytes = audio_recorder(
48+
text="Click to record",
49+
recording_color="red",
50+
neutral_color="gray",
51+
icon_name="microphone",
52+
icon_size="6x",
53+
)
54+
55+
if audio_bytes:
56+
st.audio(audio_bytes, format="audio/wav")
57+
with tempfile.NamedTemporaryFile(suffix=".wav", delete=False) as temp_audio_file:
58+
temp_audio_file.write(audio_bytes)
59+
temp_audio_file_path = temp_audio_file.name
60+
st.write(f"Audio saved to temporary file: {temp_audio_file_path}")
61+
62+
if st.button("Transcribe", disabled=audio_bytes is None):
63+
with st.spinner("Transcribing..."):
64+
try:
65+
audio_blob = Blob(path=temp_audio_file_path)
66+
parser = AzureOpenAIWhisperParser(
67+
api_key=azure_openai_api_key,
68+
azure_endpoint=azure_openai_endpoint,
69+
api_version=azure_openai_api_version,
70+
deployment_name=azure_openai_model_stt,
71+
)
72+
documents = parser.lazy_parse(
73+
blob=audio_blob,
74+
)
75+
results = [doc.page_content for doc in documents]
76+
st.success("Transcription completed!")
77+
st.text_area("Transcription Result", value="\n".join(results), height=200)
78+
except Exception as e:
79+
logger.error(f"Error during transcription: {e}")
80+
st.error(f"Error during transcription: {e}")

uv.lock

Lines changed: 41 additions & 15 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)