49
49
key = "AZURE_AI_SPEECH_API_REGION" ,
50
50
type = "default" ,
51
51
)
52
- azure_ai_speech_api_language = st .text_input (
52
+ azure_ai_speech_api_language = st .selectbox (
53
53
label = "AZURE_AI_SPEECH_API_LANGUAGE" ,
54
- value = "en-US" ,
54
+ options = [
55
+ "en-US" ,
56
+ "ja-JP" ,
57
+ ],
55
58
key = "AZURE_AI_SPEECH_API_LANGUAGE" ,
56
- type = "default" ,
57
59
)
58
60
"[Azure Portal](https://portal.azure.com/)"
59
61
"[Azure OpenAI Studio](https://oai.azure.com/resource/overview)"
@@ -71,11 +73,6 @@ def is_configured():
71
73
72
74
st .info ("This is a sample to transcribe text." )
73
75
74
- supported_tasks = [
75
- "Create summaries" ,
76
- "Do something" ,
77
- ]
78
-
79
76
# ---
80
77
# 2 column layout
81
78
@@ -102,10 +99,14 @@ def is_configured():
102
99
row2_left , row2_right = st .columns (2 )
103
100
104
101
with row2_left :
105
- target = st .selectbox (
102
+ selected_task = st .selectbox (
106
103
"Task" ,
107
- supported_tasks ,
108
- key = "target" ,
104
+ [
105
+ "Create summaries from the following text" ,
106
+ "Translate the following text into English" ,
107
+ # Add more tasks here
108
+ ],
109
+ key = "selected_task" ,
109
110
index = 0 ,
110
111
)
111
112
@@ -121,15 +122,7 @@ def start_recognition():
121
122
process = subprocess .Popen (command , shell = True )
122
123
123
124
124
- def stop_recognition ():
125
- global process
126
- if process :
127
- pathlib .Path (".stop" ).touch ()
128
- process .wait ()
129
- process = None
130
-
131
-
132
- def run_task (target : str , input : str ) -> str :
125
+ def run_task (selected_task : str , input : str ) -> str :
133
126
client = AzureOpenAI (
134
127
api_key = azure_openai_api_key ,
135
128
api_version = azure_openai_api_version ,
@@ -142,7 +135,7 @@ def run_task(target: str, input: str) -> str:
142
135
{
143
136
"role" : "system" ,
144
137
"content" : f"""
145
- You are a professional translator. Please transcribe the following text into { target } .
138
+ Task: { selected_task } .
146
139
---
147
140
{ input }
148
141
---
@@ -160,29 +153,22 @@ def load_transcribed_text():
160
153
161
154
if start_transcribe_button :
162
155
if not st .session_state .get ("process" ):
156
+ transcription_status .info ("Transcribing..." )
163
157
start_recognition ()
164
- transcription_status .info ("音声認識を開始しました。" )
165
- st .success ("音声認識を開始しました。" )
166
158
else :
167
- transcription_status .warning ("音声認識は既に実行中です。" )
168
- st .warning ("音声認識は既に実行中です。" )
159
+ transcription_status .warning ("Transcription is already running." )
169
160
170
161
if stop_transcribe_button :
162
+ pathlib .Path (".stop" ).touch ()
171
163
output = load_transcribed_text ()
172
164
st .session_state .transcribed_result = output
173
165
st .rerun ()
174
166
175
- if st .session_state .get ("process" ):
176
- stop_recognition ()
177
- st .success ("音声認識を停止しました。" )
178
- else :
179
- st .warning ("音声認識は実行されていません。" )
180
-
181
167
if run_task_button :
182
168
transcribed_text = load_transcribed_text ()
183
169
with st .spinner ("Running..." ):
184
170
output = run_task (
185
- target = target ,
171
+ selected_task = selected_task ,
186
172
input = transcribed_text ,
187
173
)
188
174
st .write (output )
0 commit comments