Skip to content

Commit 1e220a9

Browse files
committed
make fix
1 parent 81c31da commit 1e220a9

File tree

5 files changed

+135
-161
lines changed

5 files changed

+135
-161
lines changed

scripts/speeches.py

Lines changed: 60 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,11 @@
33

44
import json
55
import time
6-
from typing import List
76

87
import typer
98
from rich.console import Console
10-
from rich.table import Table
119
from rich.progress import Progress, SpinnerColumn, TextColumn
10+
from rich.table import Table
1211

1312
from template_fastapi.models.speech import BatchTranscriptionRequest, TranscriptionStatus
1413
from template_fastapi.repositories.speeches import SpeechRepository
@@ -20,33 +19,33 @@
2019

2120
@app.command()
2221
def create_transcription(
23-
content_urls: List[str] = typer.Argument(..., help="転写するファイルのURL(複数指定可能)"),
22+
content_urls: list[str] = typer.Argument(..., help="転写するファイルのURL(複数指定可能)"),
2423
locale: str = typer.Option("ja-JP", "--locale", "-l", help="言語設定"),
2524
display_name: str = typer.Option(None, "--name", "-n", help="転写ジョブの表示名"),
2625
model: str = typer.Option(None, "--model", "-m", help="使用するモデル"),
2726
):
2827
"""新しい転写ジョブを作成する"""
29-
console.print(f"[bold green]転写ジョブを作成します[/bold green]")
28+
console.print("[bold green]転写ジョブを作成します[/bold green]")
3029
console.print(f"ファイルURL: {', '.join(content_urls)}")
3130
console.print(f"言語設定: {locale}")
32-
31+
3332
try:
3433
request = BatchTranscriptionRequest(
3534
content_urls=content_urls,
3635
locale=locale,
3736
display_name=display_name or "CLI Batch Transcription",
38-
model=model
37+
model=model,
3938
)
40-
39+
4140
response = speech_repo.create_transcription_job(request)
42-
43-
console.print(f"✅ [bold green]転写ジョブが正常に作成されました[/bold green]")
41+
42+
console.print("✅ [bold green]転写ジョブが正常に作成されました[/bold green]")
4443
console.print(f"ジョブID: {response.job_id}")
4544
console.print(f"ステータス: {response.status.value}")
46-
45+
4746
if response.message:
4847
console.print(f"メッセージ: {response.message}")
49-
48+
5049
except Exception as e:
5150
console.print(f"❌ [bold red]エラー[/bold red]: {str(e)}")
5251

@@ -56,22 +55,22 @@ def get_transcription(
5655
job_id: str = typer.Argument(..., help="転写ジョブID"),
5756
):
5857
"""転写ジョブの状態を取得する"""
59-
console.print(f"[bold green]転写ジョブの状態を取得します[/bold green]")
58+
console.print("[bold green]転写ジョブの状態を取得します[/bold green]")
6059
console.print(f"ジョブID: {job_id}")
61-
60+
6261
try:
6362
job = speech_repo.get_transcription_job(job_id)
64-
65-
console.print(f"\n[bold blue]転写ジョブ情報[/bold blue]:")
63+
64+
console.print("\n[bold blue]転写ジョブ情報[/bold blue]:")
6665
console.print(f"ID: {job.id}")
6766
console.print(f"名前: {job.name}")
6867
console.print(f"ステータス: {job.status.value}")
6968
console.print(f"作成日時: {job.created_date_time}")
7069
console.print(f"最終更新日時: {job.last_action_date_time}")
71-
70+
7271
if job.links:
7372
console.print(f"リンク: {json.dumps(job.links, indent=2, ensure_ascii=False)}")
74-
73+
7574
except Exception as e:
7675
console.print(f"❌ [bold red]エラー[/bold red]: {str(e)}")
7776

@@ -81,32 +80,30 @@ def get_transcription_files(
8180
job_id: str = typer.Argument(..., help="転写ジョブID"),
8281
):
8382
"""転写ジョブのファイル一覧を取得する"""
84-
console.print(f"[bold green]転写ファイル一覧を取得します[/bold green]")
83+
console.print("[bold green]転写ファイル一覧を取得します[/bold green]")
8584
console.print(f"ジョブID: {job_id}")
86-
85+
8786
try:
8887
files = speech_repo.get_transcription_files(job_id)
89-
88+
9089
if not files:
9190
console.print("[yellow]転写ファイルが見つかりませんでした[/yellow]")
9291
return
93-
92+
9493
# テーブルで表示
9594
table = Table(title="転写ファイル一覧")
9695
table.add_column("名前", style="cyan")
9796
table.add_column("種類", style="green")
9897
table.add_column("リンク", style="yellow")
99-
98+
10099
for file in files:
101100
table.add_row(
102-
file.get("name", "N/A"),
103-
file.get("kind", "N/A"),
104-
file.get("links", {}).get("contentUrl", "N/A")
101+
file.get("name", "N/A"), file.get("kind", "N/A"), file.get("links", {}).get("contentUrl", "N/A")
105102
)
106-
103+
107104
console.print(table)
108105
console.print(f"[bold blue]合計: {len(files)}件[/bold blue]")
109-
106+
110107
except Exception as e:
111108
console.print(f"❌ [bold red]エラー[/bold red]: {str(e)}")
112109

@@ -117,36 +114,36 @@ def get_transcription_result(
117114
save_file: str = typer.Option(None, "--save", "-s", help="結果を保存するファイル名"),
118115
):
119116
"""転写結果を取得する"""
120-
console.print(f"[bold green]転写結果を取得します[/bold green]")
117+
console.print("[bold green]転写結果を取得します[/bold green]")
121118
console.print(f"ファイルURL: {file_url}")
122-
119+
123120
try:
124121
result = speech_repo.get_transcription_result(file_url)
125-
126-
console.print(f"\n[bold blue]転写結果[/bold blue]:")
122+
123+
console.print("\n[bold blue]転写結果[/bold blue]:")
127124
console.print(f"ソース: {result.source}")
128125
console.print(f"タイムスタンプ: {result.timestamp}")
129126
console.print(f"継続時間: {result.duration_in_ticks}")
130-
127+
131128
if result.combined_recognized_phrases:
132-
console.print(f"\n[bold yellow]統合認識フレーズ[/bold yellow]:")
129+
console.print("\n[bold yellow]統合認識フレーズ[/bold yellow]:")
133130
for phrase in result.combined_recognized_phrases:
134131
console.print(f"- {phrase.get('display', 'N/A')}")
135-
132+
136133
if result.recognized_phrases:
137134
console.print(f"\n[bold yellow]認識フレーズ({len(result.recognized_phrases)}件)[/bold yellow]:")
138135
for i, phrase in enumerate(result.recognized_phrases[:5]): # 最初の5件のみ表示
139-
console.print(f"{i+1}. {phrase.get('display', 'N/A')}")
140-
136+
console.print(f"{i + 1}. {phrase.get('display', 'N/A')}")
137+
141138
if len(result.recognized_phrases) > 5:
142139
console.print(f"... および {len(result.recognized_phrases) - 5} 件の追加フレーズ")
143-
140+
144141
# ファイルに保存
145142
if save_file:
146-
with open(save_file, 'w', encoding='utf-8') as f:
143+
with open(save_file, "w", encoding="utf-8") as f:
147144
json.dump(result.dict(), f, ensure_ascii=False, indent=2, default=str)
148145
console.print(f"✅ 結果を {save_file} に保存しました")
149-
146+
150147
except Exception as e:
151148
console.print(f"❌ [bold red]エラー[/bold red]: {str(e)}")
152149

@@ -157,23 +154,23 @@ def delete_transcription(
157154
force: bool = typer.Option(False, "--force", "-f", help="確認なしで削除"),
158155
):
159156
"""転写ジョブを削除する"""
160-
console.print(f"[bold yellow]転写ジョブを削除します[/bold yellow]")
157+
console.print("[bold yellow]転写ジョブを削除します[/bold yellow]")
161158
console.print(f"ジョブID: {job_id}")
162-
159+
163160
if not force:
164161
confirm = typer.confirm("本当に削除しますか?")
165162
if not confirm:
166163
console.print("削除をキャンセルしました")
167164
return
168-
165+
169166
try:
170167
success = speech_repo.delete_transcription_job(job_id)
171-
168+
172169
if success:
173170
console.print(f"✅ [bold green]転写ジョブ '{job_id}' を正常に削除しました[/bold green]")
174171
else:
175-
console.print(f"❌ [bold red]転写ジョブの削除に失敗しました[/bold red]")
176-
172+
console.print("❌ [bold red]転写ジョブの削除に失敗しました[/bold red]")
173+
177174
except Exception as e:
178175
console.print(f"❌ [bold red]エラー[/bold red]: {str(e)}")
179176

@@ -182,34 +179,34 @@ def delete_transcription(
182179
def list_transcriptions():
183180
"""転写ジョブの一覧を取得する"""
184181
console.print("[bold green]転写ジョブ一覧を取得します[/bold green]")
185-
182+
186183
try:
187184
jobs = speech_repo.list_transcription_jobs()
188-
185+
189186
if not jobs:
190187
console.print("[yellow]転写ジョブが見つかりませんでした[/yellow]")
191188
return
192-
189+
193190
# テーブルで表示
194191
table = Table(title="転写ジョブ一覧")
195192
table.add_column("ID", style="cyan")
196193
table.add_column("名前", style="green")
197194
table.add_column("ステータス", style="yellow")
198195
table.add_column("作成日時", style="magenta")
199196
table.add_column("最終更新日時", style="blue")
200-
197+
201198
for job in jobs:
202199
table.add_row(
203200
job.id,
204201
job.name or "N/A",
205202
job.status.value,
206203
str(job.created_date_time) if job.created_date_time else "N/A",
207-
str(job.last_action_date_time) if job.last_action_date_time else "N/A"
204+
str(job.last_action_date_time) if job.last_action_date_time else "N/A",
208205
)
209-
206+
210207
console.print(table)
211208
console.print(f"[bold blue]合計: {len(jobs)}件[/bold blue]")
212-
209+
213210
except Exception as e:
214211
console.print(f"❌ [bold red]エラー[/bold red]: {str(e)}")
215212

@@ -221,51 +218,51 @@ def wait_for_completion(
221218
interval: int = typer.Option(10, "--interval", "-i", help="チェック間隔(秒)"),
222219
):
223220
"""転写ジョブの完了を待つ"""
224-
console.print(f"[bold green]転写ジョブの完了を待ちます[/bold green]")
221+
console.print("[bold green]転写ジョブの完了を待ちます[/bold green]")
225222
console.print(f"ジョブID: {job_id}")
226223
console.print(f"タイムアウト: {timeout}秒")
227224
console.print(f"チェック間隔: {interval}秒")
228-
225+
229226
start_time = time.time()
230-
227+
231228
with Progress(
232229
SpinnerColumn(),
233230
TextColumn("[progress.description]{task.description}"),
234231
transient=True,
235232
) as progress:
236233
task = progress.add_task(description="転写処理中...", total=None)
237-
234+
238235
while time.time() - start_time < timeout:
239236
try:
240237
job = speech_repo.get_transcription_job(job_id)
241-
238+
242239
if job.status == TranscriptionStatus.SUCCEEDED:
243240
progress.update(task, description="✅ 転写が完了しました")
244-
console.print(f"✅ [bold green]転写ジョブが正常に完了しました[/bold green]")
241+
console.print("✅ [bold green]転写ジョブが正常に完了しました[/bold green]")
245242
console.print(f"ジョブID: {job.id}")
246243
console.print(f"最終更新日時: {job.last_action_date_time}")
247244
return
248245
elif job.status == TranscriptionStatus.FAILED:
249246
progress.update(task, description="❌ 転写が失敗しました")
250-
console.print(f"❌ [bold red]転写ジョブが失敗しました[/bold red]")
247+
console.print("❌ [bold red]転写ジョブが失敗しました[/bold red]")
251248
console.print(f"ジョブID: {job.id}")
252249
return
253250
elif job.status == TranscriptionStatus.RUNNING:
254251
progress.update(task, description="🔄 転写処理中...")
255252
else:
256253
progress.update(task, description=f"⏳ 待機中 ({job.status.value})")
257-
254+
258255
time.sleep(interval)
259-
256+
260257
except Exception as e:
261258
progress.update(task, description=f"❌ エラー: {str(e)}")
262259
console.print(f"❌ [bold red]エラー[/bold red]: {str(e)}")
263260
return
264-
261+
265262
# タイムアウト
266263
console.print(f"⏰ [bold yellow]タイムアウトしました({timeout}秒)[/bold yellow]")
267264
console.print("転写ジョブはまだ処理中の可能性があります")
268265

269266

270267
if __name__ == "__main__":
271-
app()
268+
app()

template_fastapi/models/speech.py

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
from datetime import datetime
22
from enum import Enum
3-
from typing import Any, Dict, List, Optional
3+
from typing import Any
44

55
from pydantic import BaseModel, ConfigDict
66

77

88
class TranscriptionStatus(str, Enum):
99
"""転写処理のステータス"""
10+
1011
NOT_STARTED = "NotStarted"
1112
RUNNING = "Running"
1213
SUCCEEDED = "Succeeded"
@@ -15,7 +16,7 @@ class TranscriptionStatus(str, Enum):
1516

1617
class TranscriptionJob(BaseModel):
1718
"""転写ジョブの情報を表すモデル"""
18-
19+
1920
model_config = ConfigDict(extra="ignore")
2021

2122
id: str
@@ -24,12 +25,12 @@ class TranscriptionJob(BaseModel):
2425
created_date_time: datetime | None = None
2526
last_action_date_time: datetime | None = None
2627
self_url: str | None = None
27-
links: Dict[str, str] | None = None
28+
links: dict[str, str] | None = None
2829

2930

3031
class TranscriptionResult(BaseModel):
3132
"""転写結果を表すモデル"""
32-
33+
3334
model_config = ConfigDict(extra="ignore")
3435

3536
source: str | None = None
@@ -42,33 +43,33 @@ class TranscriptionResult(BaseModel):
4243

4344
class TranscriptionContent(BaseModel):
4445
"""転写内容全体を表すモデル"""
45-
46+
4647
model_config = ConfigDict(extra="ignore")
4748

4849
source: str | None = None
4950
timestamp: datetime | None = None
5051
duration_in_ticks: int | None = None
51-
combined_recognized_phrases: List[Dict[str, Any]] | None = None
52-
recognized_phrases: List[Dict[str, Any]] | None = None
52+
combined_recognized_phrases: list[dict[str, Any]] | None = None
53+
recognized_phrases: list[dict[str, Any]] | None = None
5354

5455

5556
class BatchTranscriptionRequest(BaseModel):
5657
"""バッチ転写リクエストを表すモデル"""
57-
58+
5859
model_config = ConfigDict(extra="ignore")
5960

60-
content_urls: List[str]
61+
content_urls: list[str]
6162
locale: str = "ja-JP"
6263
display_name: str | None = None
6364
model: str | None = None
64-
properties: Dict[str, Any] | None = None
65+
properties: dict[str, Any] | None = None
6566

6667

6768
class BatchTranscriptionResponse(BaseModel):
6869
"""バッチ転写レスポンスを表すモデル"""
69-
70+
7071
model_config = ConfigDict(extra="ignore")
7172

7273
job_id: str
7374
status: TranscriptionStatus
74-
message: str | None = None
75+
message: str | None = None

0 commit comments

Comments
 (0)