Add progress display for S3 upload and transcription polling
- Add real-time progress bar with percentage for S3 upload (file size/MB) - Replace repetitive polling output with single-line refreshing status - Show elapsed time and poll count during transcription polling - Add .claude/ to .gitignore Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
4
.gitignore
vendored
4
.gitignore
vendored
@@ -37,4 +37,6 @@ output/
|
|||||||
Archive/
|
Archive/
|
||||||
|
|
||||||
# Tools
|
# Tools
|
||||||
tools/
|
tools/
|
||||||
|
|
||||||
|
.claude/
|
||||||
@@ -100,8 +100,23 @@ audio_ext = os.path.splitext(audio_file)[1].lstrip(".")
|
|||||||
audio_name = os.path.splitext(os.path.basename(audio_file))[0]
|
audio_name = os.path.splitext(os.path.basename(audio_file))[0]
|
||||||
|
|
||||||
obj_name = f"audio/{uuid.uuid4().hex[:8]}_{os.path.basename(audio_file)}"
|
obj_name = f"audio/{uuid.uuid4().hex[:8]}_{os.path.basename(audio_file)}"
|
||||||
print(f"Uploading {audio_file} ...")
|
file_size = os.path.getsize(audio_file)
|
||||||
s3.upload_file(audio_file, S3_BUCKET, obj_name)
|
uploaded = [0] # Use list to allow modification in callback
|
||||||
|
|
||||||
|
def upload_callback(bytes_transferred):
|
||||||
|
uploaded[0] += bytes_transferred
|
||||||
|
percent = min(100, int(uploaded[0] * 100 / file_size))
|
||||||
|
uploaded_mb = uploaded[0] / (1024 * 1024)
|
||||||
|
total_mb = file_size / (1024 * 1024)
|
||||||
|
bar_width = 30
|
||||||
|
filled = int(bar_width * percent / 100)
|
||||||
|
bar = "█" * filled + "░" * (bar_width - filled)
|
||||||
|
print(f"\rUploading [{bar}] {percent}% ({uploaded_mb:.1f}MB / {total_mb:.1f}MB)", end="", flush=True)
|
||||||
|
|
||||||
|
print(f"Uploading {audio_file} ({file_size / (1024 * 1024):.1f}MB) ...")
|
||||||
|
s3.upload_file(audio_file, S3_BUCKET, obj_name, Callback=upload_callback)
|
||||||
|
print() # New line after upload completes
|
||||||
|
|
||||||
url = s3.generate_presigned_url(
|
url = s3.generate_presigned_url(
|
||||||
"get_object",
|
"get_object",
|
||||||
Params={"Bucket": S3_BUCKET, "Key": obj_name},
|
Params={"Bucket": S3_BUCKET, "Key": obj_name},
|
||||||
@@ -131,6 +146,9 @@ print(f"Submit: {status}")
|
|||||||
if status != "20000000":
|
if status != "20000000":
|
||||||
print(f"FAILED: {resp.headers.get('X-Api-Message', '')}")
|
print(f"FAILED: {resp.headers.get('X-Api-Message', '')}")
|
||||||
else:
|
else:
|
||||||
|
start_time = time.time()
|
||||||
|
poll_count = 0
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
resp = session.post(
|
resp = session.post(
|
||||||
QUERY_URL,
|
QUERY_URL,
|
||||||
@@ -156,14 +174,18 @@ else:
|
|||||||
with open(md_path, "w", encoding="utf-8") as f:
|
with open(md_path, "w", encoding="utf-8") as f:
|
||||||
f.write(build_markdown(data, audio_file))
|
f.write(build_markdown(data, audio_file))
|
||||||
|
|
||||||
print(f"Done ({len(text)} chars, {len(utterances)} utterances)")
|
elapsed = int(time.time() - start_time)
|
||||||
|
print(f"\rDone ({len(text)} chars, {len(utterances)} utterances, elapsed {elapsed}s)")
|
||||||
print(f"Saved: {json_path}, {md_path}")
|
print(f"Saved: {json_path}, {md_path}")
|
||||||
break
|
break
|
||||||
elif code in ("20000001", "20000002"):
|
elif code in ("20000001", "20000002"):
|
||||||
print(f" Processing... ({code})")
|
poll_count += 1
|
||||||
|
elapsed = int(time.time() - start_time)
|
||||||
|
status_msg = "Processing" if code == "20000001" else "Queued"
|
||||||
|
print(f"\r {status_msg}... (poll {poll_count}, elapsed {elapsed}s) ", end="", flush=True)
|
||||||
time.sleep(5)
|
time.sleep(5)
|
||||||
else:
|
else:
|
||||||
print(f"FAILED: {code} {resp.headers.get('X-Api-Message', '')}")
|
print(f"\rFAILED: {code} {resp.headers.get('X-Api-Message', '')}")
|
||||||
break
|
break
|
||||||
|
|
||||||
print("\nAll done.")
|
print("\nAll done.")
|
||||||
|
|||||||
Reference in New Issue
Block a user