Update app.py
Browse files
app.py
CHANGED
|
@@ -260,25 +260,44 @@ with gr.Blocks(
|
|
| 260 |
/* 手機優化樣式 */
|
| 261 |
@media (max-width: 768px) {
|
| 262 |
.gradio-container {
|
| 263 |
-
padding:
|
| 264 |
}
|
| 265 |
-
/*
|
| 266 |
-
.
|
| 267 |
-
|
| 268 |
}
|
| 269 |
-
/*
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 270 |
button {
|
| 271 |
font-size: 16px !important;
|
| 272 |
-
padding:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 273 |
}
|
| 274 |
-
/*
|
| 275 |
input, textarea {
|
| 276 |
font-size: 16px !important;
|
| 277 |
}
|
| 278 |
-
/*
|
| 279 |
-
.
|
| 280 |
-
padding:
|
| 281 |
-
font-size: 15px !important;
|
| 282 |
}
|
| 283 |
}
|
| 284 |
"""
|
|
@@ -286,40 +305,46 @@ with gr.Blocks(
|
|
| 286 |
gr.Markdown("# 🎧 LINE Audio Transcription")
|
| 287 |
|
| 288 |
with gr.Tab("🌐 Web Upload"):
|
| 289 |
-
gr.Markdown("### Upload audio
|
| 290 |
|
| 291 |
-
# 手機版:改用單欄布局
|
| 292 |
pw_ui = gr.Textbox(
|
| 293 |
label="Password",
|
| 294 |
type="password",
|
| 295 |
-
placeholder="Enter password"
|
|
|
|
| 296 |
)
|
| 297 |
file_ui = gr.File(
|
| 298 |
label="Upload Audio File",
|
| 299 |
-
file_types=["audio"]
|
|
|
|
|
|
|
|
|
|
| 300 |
)
|
| 301 |
btn_ui = gr.Button(
|
| 302 |
-
"Start Transcription
|
| 303 |
variant="primary",
|
| 304 |
-
size="lg"
|
|
|
|
| 305 |
)
|
| 306 |
|
| 307 |
status_ui = gr.Textbox(
|
| 308 |
label="Status",
|
| 309 |
interactive=False,
|
| 310 |
-
|
| 311 |
)
|
| 312 |
transcript_ui = gr.Textbox(
|
| 313 |
-
label="Transcription
|
| 314 |
-
lines=
|
| 315 |
placeholder="Transcription will appear here...",
|
| 316 |
-
show_copy_button=True
|
|
|
|
| 317 |
)
|
| 318 |
summary_ui = gr.Textbox(
|
| 319 |
-
label="
|
| 320 |
-
lines=
|
| 321 |
placeholder="Summary will appear here...",
|
| 322 |
-
show_copy_button=True
|
|
|
|
| 323 |
)
|
| 324 |
|
| 325 |
btn_ui.click(
|
|
@@ -328,16 +353,13 @@ with gr.Blocks(
|
|
| 328 |
outputs=[status_ui, transcript_ui, summary_ui]
|
| 329 |
)
|
| 330 |
|
| 331 |
-
with gr.Tab("📱 API
|
| 332 |
gr.Markdown("""
|
| 333 |
-
### iPhone Shortcuts
|
| 334 |
|
| 335 |
-
**Endpoint:**
|
| 336 |
-
```
|
| 337 |
-
POST /api/transcribe
|
| 338 |
-
```
|
| 339 |
|
| 340 |
-
**Request
|
| 341 |
```json
|
| 342 |
{
|
| 343 |
"password": "your_password",
|
|
@@ -357,36 +379,32 @@ with gr.Blocks(
|
|
| 357 |
|
| 358 |
---
|
| 359 |
|
| 360 |
-
|
| 361 |
-
|
| 362 |
-
✅
|
| 363 |
-
|
| 364 |
-
✅ **No polling needed** - Waits until completion
|
| 365 |
-
|
| 366 |
-
✅ **Works with any audio length** - Auto-handles long files
|
| 367 |
|
| 368 |
---
|
| 369 |
|
| 370 |
-
|
| 371 |
|
| 372 |
-
1. Get file →
|
| 373 |
2. Base64 encode
|
| 374 |
3. Text: `data:audio/m4a;base64,[encoded]`
|
| 375 |
-
4. Dictionary:
|
| 376 |
- `password`: `chou`
|
| 377 |
-
- `file_data`: Step 3
|
| 378 |
- `file_name`: `recording.m4a`
|
| 379 |
5. Get URL contents:
|
| 380 |
- URL: `/api/transcribe`
|
| 381 |
- Method: POST
|
| 382 |
- Header: `Content-Type: application/json`
|
| 383 |
-
- Body: Step 4
|
| 384 |
-
6. Get `transcription`
|
| 385 |
""")
|
| 386 |
|
| 387 |
gr.Markdown("""
|
| 388 |
---
|
| 389 |
-
💡 **Formats
|
| 390 |
""")
|
| 391 |
|
| 392 |
# ====== 掛載 Gradio 到 FastAPI ======
|
|
|
|
| 260 |
/* 手機優化樣式 */
|
| 261 |
@media (max-width: 768px) {
|
| 262 |
.gradio-container {
|
| 263 |
+
padding: 8px !important;
|
| 264 |
}
|
| 265 |
+
/* 限制檔案上傳區塊高度 */
|
| 266 |
+
.file-upload {
|
| 267 |
+
max-height: 180px !important;
|
| 268 |
}
|
| 269 |
+
/* 限制圖示大小 */
|
| 270 |
+
.file-upload svg, .file-upload img {
|
| 271 |
+
max-width: 80px !important;
|
| 272 |
+
max-height: 80px !important;
|
| 273 |
+
}
|
| 274 |
+
/* 調整按鈕 */
|
| 275 |
button {
|
| 276 |
font-size: 16px !important;
|
| 277 |
+
padding: 14px !important;
|
| 278 |
+
margin: 8px 0 !important;
|
| 279 |
+
}
|
| 280 |
+
/* Tab 標籤 */
|
| 281 |
+
.tabs button {
|
| 282 |
+
padding: 10px 14px !important;
|
| 283 |
+
font-size: 14px !important;
|
| 284 |
+
}
|
| 285 |
+
/* 標題更緊湊 */
|
| 286 |
+
h1 {
|
| 287 |
+
font-size: 24px !important;
|
| 288 |
+
margin: 10px 0 !important;
|
| 289 |
+
}
|
| 290 |
+
h3 {
|
| 291 |
+
font-size: 16px !important;
|
| 292 |
+
margin: 8px 0 !important;
|
| 293 |
}
|
| 294 |
+
/* 輸入框 */
|
| 295 |
input, textarea {
|
| 296 |
font-size: 16px !important;
|
| 297 |
}
|
| 298 |
+
/* 減少內邊距 */
|
| 299 |
+
.block {
|
| 300 |
+
padding: 8px !important;
|
|
|
|
| 301 |
}
|
| 302 |
}
|
| 303 |
"""
|
|
|
|
| 305 |
gr.Markdown("# 🎧 LINE Audio Transcription")
|
| 306 |
|
| 307 |
with gr.Tab("🌐 Web Upload"):
|
| 308 |
+
gr.Markdown("### Upload audio from browser")
|
| 309 |
|
|
|
|
| 310 |
pw_ui = gr.Textbox(
|
| 311 |
label="Password",
|
| 312 |
type="password",
|
| 313 |
+
placeholder="Enter password",
|
| 314 |
+
scale=1
|
| 315 |
)
|
| 316 |
file_ui = gr.File(
|
| 317 |
label="Upload Audio File",
|
| 318 |
+
file_types=["audio"],
|
| 319 |
+
file_count="single",
|
| 320 |
+
scale=1,
|
| 321 |
+
elem_classes=["file-upload"]
|
| 322 |
)
|
| 323 |
btn_ui = gr.Button(
|
| 324 |
+
"🚀 Start Transcription",
|
| 325 |
variant="primary",
|
| 326 |
+
size="lg",
|
| 327 |
+
scale=1
|
| 328 |
)
|
| 329 |
|
| 330 |
status_ui = gr.Textbox(
|
| 331 |
label="Status",
|
| 332 |
interactive=False,
|
| 333 |
+
scale=1
|
| 334 |
)
|
| 335 |
transcript_ui = gr.Textbox(
|
| 336 |
+
label="Transcription",
|
| 337 |
+
lines=6,
|
| 338 |
placeholder="Transcription will appear here...",
|
| 339 |
+
show_copy_button=True,
|
| 340 |
+
scale=1
|
| 341 |
)
|
| 342 |
summary_ui = gr.Textbox(
|
| 343 |
+
label="Summary",
|
| 344 |
+
lines=4,
|
| 345 |
placeholder="Summary will appear here...",
|
| 346 |
+
show_copy_button=True,
|
| 347 |
+
scale=1
|
| 348 |
)
|
| 349 |
|
| 350 |
btn_ui.click(
|
|
|
|
| 353 |
outputs=[status_ui, transcript_ui, summary_ui]
|
| 354 |
)
|
| 355 |
|
| 356 |
+
with gr.Tab("📱 API"):
|
| 357 |
gr.Markdown("""
|
| 358 |
+
### iPhone Shortcuts
|
| 359 |
|
| 360 |
+
**Endpoint:** `POST /api/transcribe`
|
|
|
|
|
|
|
|
|
|
| 361 |
|
| 362 |
+
**Request:**
|
| 363 |
```json
|
| 364 |
{
|
| 365 |
"password": "your_password",
|
|
|
|
| 379 |
|
| 380 |
---
|
| 381 |
|
| 382 |
+
✅ Fully synchronous
|
| 383 |
+
✅ No polling needed
|
| 384 |
+
✅ Works with any audio length
|
|
|
|
|
|
|
|
|
|
|
|
|
| 385 |
|
| 386 |
---
|
| 387 |
|
| 388 |
+
**Setup Steps:**
|
| 389 |
|
| 390 |
+
1. Get file → Audio
|
| 391 |
2. Base64 encode
|
| 392 |
3. Text: `data:audio/m4a;base64,[encoded]`
|
| 393 |
+
4. Dictionary with 3 text fields:
|
| 394 |
- `password`: `chou`
|
| 395 |
+
- `file_data`: Step 3
|
| 396 |
- `file_name`: `recording.m4a`
|
| 397 |
5. Get URL contents:
|
| 398 |
- URL: `/api/transcribe`
|
| 399 |
- Method: POST
|
| 400 |
- Header: `Content-Type: application/json`
|
| 401 |
+
- Body: Step 4 (JSON)
|
| 402 |
+
6. Get `transcription` & `summary`
|
| 403 |
""")
|
| 404 |
|
| 405 |
gr.Markdown("""
|
| 406 |
---
|
| 407 |
+
💡 **Formats:** MP4, M4A, MP3, WAV, OGG, WEBM | **Max:** 25MB/chunk | 🔒 Password-protected
|
| 408 |
""")
|
| 409 |
|
| 410 |
# ====== 掛載 Gradio 到 FastAPI ======
|