Spaces:
Runtime error
Runtime error
fix app.py access token error
Browse files
app.py
CHANGED
|
@@ -2,21 +2,34 @@ import re
|
|
| 2 |
import io
|
| 3 |
import zipfile
|
| 4 |
from pathlib import Path
|
|
|
|
| 5 |
|
| 6 |
import gradio as gr
|
| 7 |
from docx import Document
|
| 8 |
from docx.oxml import OxmlElement
|
| 9 |
from docx.oxml.ns import qn
|
| 10 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
|
| 12 |
|
| 13 |
# ----------------------------------------------------
|
| 14 |
-
# 1) ÇEVİRİ MODELİ (Helsinki-NLP / opus-mt-en-tr)
|
| 15 |
# ----------------------------------------------------
|
| 16 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
translator = pipeline(
|
| 18 |
"translation",
|
| 19 |
-
model=
|
|
|
|
| 20 |
)
|
| 21 |
|
| 22 |
|
|
@@ -182,7 +195,7 @@ def style_header_cell(cell, text: str):
|
|
| 182 |
shd.set(qn("w:fill"), "D9D9D9") # light grey
|
| 183 |
|
| 184 |
|
| 185 |
-
def srt_to_docx_bytes(srt_path: Path, translate_to_tr: bool) ->
|
| 186 |
"""
|
| 187 |
Tek SRT -> styled DOCX (bytes, filename)
|
| 188 |
"""
|
|
@@ -244,7 +257,8 @@ def process_srt_files(files, translate_to_tr: bool):
|
|
| 244 |
if not files:
|
| 245 |
return None
|
| 246 |
|
| 247 |
-
|
|
|
|
| 248 |
|
| 249 |
zip_buffer = io.BytesIO()
|
| 250 |
with zipfile.ZipFile(zip_buffer, "w", zipfile.ZIP_DEFLATED) as zf:
|
|
@@ -271,10 +285,10 @@ with gr.Blocks() as demo:
|
|
| 271 |
|
| 272 |
- Bir veya birden fazla **.srt** yükle.
|
| 273 |
- Her satır için:
|
| 274 |
-
- **Character**: `WOMAN:`, `LEWIS:`, `NURSE:` gibi isimler çıkarılır.
|
| 275 |
- **TC**: sadece **MM.SS** (start time'dan).
|
| 276 |
- **TEXT**: `NAME:` prefix'leri atılmış metin.
|
| 277 |
-
- İstersen TEXT'i **Helsinki-NLP/opus-mt-en-tr** ile Türkçe'ye çevir.
|
| 278 |
- Çıktı: Tüm DOCX'leri içeren tek bir **ZIP**.
|
| 279 |
"""
|
| 280 |
)
|
|
@@ -284,7 +298,7 @@ with gr.Blocks() as demo:
|
|
| 284 |
label="Upload .srt files",
|
| 285 |
file_types=[".srt"],
|
| 286 |
file_count="multiple",
|
| 287 |
-
type="filepath", # Gradio ->
|
| 288 |
)
|
| 289 |
|
| 290 |
translate_chk = gr.Checkbox(
|
|
|
|
| 2 |
import io
|
| 3 |
import zipfile
|
| 4 |
from pathlib import Path
|
| 5 |
+
from typing import Tuple
|
| 6 |
|
| 7 |
import gradio as gr
|
| 8 |
from docx import Document
|
| 9 |
from docx.oxml import OxmlElement
|
| 10 |
from docx.oxml.ns import qn
|
| 11 |
+
|
| 12 |
+
from transformers import (
|
| 13 |
+
AutoTokenizer,
|
| 14 |
+
AutoModelForSeq2SeqLM,
|
| 15 |
+
pipeline,
|
| 16 |
+
)
|
| 17 |
|
| 18 |
|
| 19 |
# ----------------------------------------------------
|
| 20 |
+
# 1) ÇEVİRİ MODELİ (Helsinki-NLP / opus-mt-en-tr) - token=None
|
| 21 |
# ----------------------------------------------------
|
| 22 |
|
| 23 |
+
MODEL_NAME = "Helsinki-NLP/opus-mt-en-tr"
|
| 24 |
+
|
| 25 |
+
# token=None => hiçbir HF token kullanılmasın, anonim indir.
|
| 26 |
+
tokenizer = AutoTokenizer.from_pretrained(MODEL_NAME, token=None)
|
| 27 |
+
model = AutoModelForSeq2SeqLM.from_pretrained(MODEL_NAME, token=None)
|
| 28 |
+
|
| 29 |
translator = pipeline(
|
| 30 |
"translation",
|
| 31 |
+
model=model,
|
| 32 |
+
tokenizer=tokenizer,
|
| 33 |
)
|
| 34 |
|
| 35 |
|
|
|
|
| 195 |
shd.set(qn("w:fill"), "D9D9D9") # light grey
|
| 196 |
|
| 197 |
|
| 198 |
+
def srt_to_docx_bytes(srt_path: Path, translate_to_tr: bool) -> Tuple[bytes, str]:
|
| 199 |
"""
|
| 200 |
Tek SRT -> styled DOCX (bytes, filename)
|
| 201 |
"""
|
|
|
|
| 257 |
if not files:
|
| 258 |
return None
|
| 259 |
|
| 260 |
+
# Gradio type="filepath" -> direkt string path listesi
|
| 261 |
+
paths = [Path(p) for p in files]
|
| 262 |
|
| 263 |
zip_buffer = io.BytesIO()
|
| 264 |
with zipfile.ZipFile(zip_buffer, "w", zipfile.ZIP_DEFLATED) as zf:
|
|
|
|
| 285 |
|
| 286 |
- Bir veya birden fazla **.srt** yükle.
|
| 287 |
- Her satır için:
|
| 288 |
+
- **Character**: `WOMAN:`, `LEWIS:`, `NURSE:` gibi isimler çıkarılır (çeviri yok).
|
| 289 |
- **TC**: sadece **MM.SS** (start time'dan).
|
| 290 |
- **TEXT**: `NAME:` prefix'leri atılmış metin.
|
| 291 |
+
- İstersen TEXT'i **Helsinki-NLP/opus-mt-en-tr** ile Türkçe'ye çevir (Character asla çevrilmez).
|
| 292 |
- Çıktı: Tüm DOCX'leri içeren tek bir **ZIP**.
|
| 293 |
"""
|
| 294 |
)
|
|
|
|
| 298 |
label="Upload .srt files",
|
| 299 |
file_types=[".srt"],
|
| 300 |
file_count="multiple",
|
| 301 |
+
type="filepath", # Gradio -> string path list
|
| 302 |
)
|
| 303 |
|
| 304 |
translate_chk = gr.Checkbox(
|