Upload 4 files
Browse files- README.md +1 -1
- app.py +5 -12
- app_hf.py +15 -20
- requirements.txt +19 -15
README.md
CHANGED
|
@@ -4,7 +4,7 @@ emoji: 💻
|
|
| 4 |
colorFrom: blue
|
| 5 |
colorTo: green
|
| 6 |
sdk: gradio
|
| 7 |
-
sdk_version:
|
| 8 |
python_version: "3.10"
|
| 9 |
app_file: app_hf.py
|
| 10 |
pinned: false
|
|
|
|
| 4 |
colorFrom: blue
|
| 5 |
colorTo: green
|
| 6 |
sdk: gradio
|
| 7 |
+
sdk_version: 4.29.0
|
| 8 |
python_version: "3.10"
|
| 9 |
app_file: app_hf.py
|
| 10 |
pinned: false
|
app.py
CHANGED
|
@@ -229,14 +229,7 @@ def run_legen(
|
|
| 229 |
input_dir = Path("input")
|
| 230 |
input_dir.mkdir(exist_ok=True)
|
| 231 |
|
| 232 |
-
|
| 233 |
-
# Gradio 4.x/Some modes might return a string path
|
| 234 |
-
if hasattr(input_file, 'name'):
|
| 235 |
-
source_path = input_file.name
|
| 236 |
-
else:
|
| 237 |
-
source_path = input_file
|
| 238 |
-
|
| 239 |
-
original_name = os.path.basename(source_path)
|
| 240 |
|
| 241 |
# Use timestamp to avoid cache/overwrite issues ONLY on HF Spaces
|
| 242 |
if IS_HF:
|
|
@@ -249,7 +242,7 @@ def run_legen(
|
|
| 249 |
|
| 250 |
dest_path = input_dir / new_filename
|
| 251 |
# Copy file to input directory
|
| 252 |
-
shutil.copy2(
|
| 253 |
# Use the new file path as input
|
| 254 |
input_path = str(dest_path)
|
| 255 |
|
|
@@ -419,7 +412,7 @@ with gr.Blocks(theme=theme, css=custom_css) as demo:
|
|
| 419 |
)
|
| 420 |
input_file = gr.File(
|
| 421 |
label=i18n("Upload de Arquivo"),
|
| 422 |
-
type="
|
| 423 |
file_count="single",
|
| 424 |
height=300
|
| 425 |
)
|
|
@@ -448,7 +441,7 @@ with gr.Blocks(theme=theme, css=custom_css) as demo:
|
|
| 448 |
with gr.Row():
|
| 449 |
transcription_model = gr.Dropdown(
|
| 450 |
choices=["tiny", "base", "small", "medium", "large", "large-v1", "large-v2", "large-v3", "large-v3-turbo",],
|
| 451 |
-
value="
|
| 452 |
label=i18n("Modelo"),
|
| 453 |
info=i18n("Modelos maiores (large) são mais precisos, mas exigem mais VRAM.")
|
| 454 |
)
|
|
@@ -647,4 +640,4 @@ if __name__ == "__main__":
|
|
| 647 |
if IS_HF:
|
| 648 |
launch_kwargs["server_name"] = "0.0.0.0"
|
| 649 |
|
| 650 |
-
demo.launch(**launch_kwargs)
|
|
|
|
| 229 |
input_dir = Path("input")
|
| 230 |
input_dir.mkdir(exist_ok=True)
|
| 231 |
|
| 232 |
+
original_name = os.path.basename(input_file)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 233 |
|
| 234 |
# Use timestamp to avoid cache/overwrite issues ONLY on HF Spaces
|
| 235 |
if IS_HF:
|
|
|
|
| 242 |
|
| 243 |
dest_path = input_dir / new_filename
|
| 244 |
# Copy file to input directory
|
| 245 |
+
shutil.copy2(input_file, dest_path)
|
| 246 |
# Use the new file path as input
|
| 247 |
input_path = str(dest_path)
|
| 248 |
|
|
|
|
| 412 |
)
|
| 413 |
input_file = gr.File(
|
| 414 |
label=i18n("Upload de Arquivo"),
|
| 415 |
+
type="filepath",
|
| 416 |
file_count="single",
|
| 417 |
height=300
|
| 418 |
)
|
|
|
|
| 441 |
with gr.Row():
|
| 442 |
transcription_model = gr.Dropdown(
|
| 443 |
choices=["tiny", "base", "small", "medium", "large", "large-v1", "large-v2", "large-v3", "large-v3-turbo",],
|
| 444 |
+
value="tiny",
|
| 445 |
label=i18n("Modelo"),
|
| 446 |
info=i18n("Modelos maiores (large) são mais precisos, mas exigem mais VRAM.")
|
| 447 |
)
|
|
|
|
| 640 |
if IS_HF:
|
| 641 |
launch_kwargs["server_name"] = "0.0.0.0"
|
| 642 |
|
| 643 |
+
demo.launch(**launch_kwargs)
|
app_hf.py
CHANGED
|
@@ -12,15 +12,15 @@ import argparse
|
|
| 12 |
from typing import Optional, List
|
| 13 |
from i18n.i18n import I18nAuto
|
| 14 |
from header import badges, description
|
|
|
|
|
|
|
| 15 |
i18n = I18nAuto()
|
| 16 |
|
| 17 |
# Variável global para armazenar o processo atual
|
| 18 |
current_process: Optional[subprocess.Popen] = None
|
| 19 |
-
# Flag global para ambiente HuggingFace (Sempre True
|
| 20 |
IS_HF = True
|
| 21 |
|
| 22 |
-
# ... (previous code)
|
| 23 |
-
|
| 24 |
# Força o uso de UTF-8 para o Python
|
| 25 |
os.environ["PYTHONIOENCODING"] = "utf-8"
|
| 26 |
|
|
@@ -193,6 +193,7 @@ def refresh_projects():
|
|
| 193 |
return gr.update(choices=get_projects())
|
| 194 |
|
| 195 |
|
|
|
|
| 196 |
def run_legen(
|
| 197 |
input_path,
|
| 198 |
input_file,
|
|
@@ -318,7 +319,8 @@ def run_legen(
|
|
| 318 |
if os.name == 'nt':
|
| 319 |
startupinfo = subprocess.STARTUPINFO()
|
| 320 |
startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW
|
| 321 |
-
|
|
|
|
| 322 |
current_process = subprocess.Popen(
|
| 323 |
cmd,
|
| 324 |
stdout=subprocess.PIPE,
|
|
@@ -421,7 +423,7 @@ with gr.Blocks(theme=theme, css=custom_css) as demo:
|
|
| 421 |
)
|
| 422 |
input_file = gr.File(
|
| 423 |
label=i18n("Upload de Arquivo"),
|
| 424 |
-
type="
|
| 425 |
file_count="single",
|
| 426 |
height=300
|
| 427 |
)
|
|
@@ -445,12 +447,12 @@ with gr.Blocks(theme=theme, css=custom_css) as demo:
|
|
| 445 |
choices=["whisperx", "whisper"],
|
| 446 |
value="whisper",
|
| 447 |
label=i18n("Engine de Transcrição"),
|
| 448 |
-
info=i18n("
|
| 449 |
)
|
| 450 |
with gr.Row():
|
| 451 |
transcription_model = gr.Dropdown(
|
| 452 |
choices=["tiny", "base", "small", "medium", "large", "large-v1", "large-v2", "large-v3", "large-v3-turbo",],
|
| 453 |
-
value="
|
| 454 |
label=i18n("Modelo"),
|
| 455 |
info=i18n("Modelos maiores (large) são mais precisos, mas exigem mais VRAM.")
|
| 456 |
)
|
|
@@ -635,18 +637,11 @@ if __name__ == "__main__":
|
|
| 635 |
parser.add_argument("--hf", action="store_true", help="Optimize for HuggingFace Spaces (timestamp uploads)")
|
| 636 |
args = parser.parse_args()
|
| 637 |
|
| 638 |
-
#
|
| 639 |
-
|
| 640 |
-
IS_HF = True
|
| 641 |
-
|
| 642 |
-
launch_kwargs = {}
|
| 643 |
-
|
| 644 |
-
if args.colab:
|
| 645 |
-
launch_kwargs["share"] = True
|
| 646 |
-
launch_kwargs["server_name"] = "0.0.0.0"
|
| 647 |
|
| 648 |
-
|
| 649 |
-
|
| 650 |
-
|
| 651 |
|
| 652 |
-
demo.launch(**launch_kwargs)
|
|
|
|
| 12 |
from typing import Optional, List
|
| 13 |
from i18n.i18n import I18nAuto
|
| 14 |
from header import badges, description
|
| 15 |
+
import spaces # Import spaces for GPU support
|
| 16 |
+
|
| 17 |
i18n = I18nAuto()
|
| 18 |
|
| 19 |
# Variável global para armazenar o processo atual
|
| 20 |
current_process: Optional[subprocess.Popen] = None
|
| 21 |
+
# Flag global para ambiente HuggingFace (Sempre True para este arquivo)
|
| 22 |
IS_HF = True
|
| 23 |
|
|
|
|
|
|
|
| 24 |
# Força o uso de UTF-8 para o Python
|
| 25 |
os.environ["PYTHONIOENCODING"] = "utf-8"
|
| 26 |
|
|
|
|
| 193 |
return gr.update(choices=get_projects())
|
| 194 |
|
| 195 |
|
| 196 |
+
@spaces.GPU(duration=120) # Reserve GPU for up to 2 minutes per call (adjust as needed)
|
| 197 |
def run_legen(
|
| 198 |
input_path,
|
| 199 |
input_file,
|
|
|
|
| 319 |
if os.name == 'nt':
|
| 320 |
startupinfo = subprocess.STARTUPINFO()
|
| 321 |
startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW
|
| 322 |
+
|
| 323 |
+
# NOTE: On HF, running python subproccess might use the same problematic environment if we don't fix requirements.
|
| 324 |
current_process = subprocess.Popen(
|
| 325 |
cmd,
|
| 326 |
stdout=subprocess.PIPE,
|
|
|
|
| 423 |
)
|
| 424 |
input_file = gr.File(
|
| 425 |
label=i18n("Upload de Arquivo"),
|
| 426 |
+
type="filepath",
|
| 427 |
file_count="single",
|
| 428 |
height=300
|
| 429 |
)
|
|
|
|
| 447 |
choices=["whisperx", "whisper"],
|
| 448 |
value="whisper",
|
| 449 |
label=i18n("Engine de Transcrição"),
|
| 450 |
+
info=i18n("Recomendado 'whisper' para evitar erros de biblioteca no HF.")
|
| 451 |
)
|
| 452 |
with gr.Row():
|
| 453 |
transcription_model = gr.Dropdown(
|
| 454 |
choices=["tiny", "base", "small", "medium", "large", "large-v1", "large-v2", "large-v3", "large-v3-turbo",],
|
| 455 |
+
value="tiny",
|
| 456 |
label=i18n("Modelo"),
|
| 457 |
info=i18n("Modelos maiores (large) são mais precisos, mas exigem mais VRAM.")
|
| 458 |
)
|
|
|
|
| 637 |
parser.add_argument("--hf", action="store_true", help="Optimize for HuggingFace Spaces (timestamp uploads)")
|
| 638 |
args = parser.parse_args()
|
| 639 |
|
| 640 |
+
# FORCE HF MODE since this is app_hf.py
|
| 641 |
+
IS_HF = True
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 642 |
|
| 643 |
+
launch_kwargs = {
|
| 644 |
+
"server_name": "0.0.0.0"
|
| 645 |
+
}
|
| 646 |
|
| 647 |
+
demo.launch(**launch_kwargs)
|
requirements.txt
CHANGED
|
@@ -1,15 +1,19 @@
|
|
| 1 |
-
deep-translator
|
| 2 |
-
ffmpeg-progress-yield
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
deep-translator
|
| 2 |
+
ffmpeg-progress-yield
|
| 3 |
+
# Use direct github links like the working example
|
| 4 |
+
git+https://github.com/openai/whisper.git
|
| 5 |
+
git+https://github.com/matheusbach/whisperX.git
|
| 6 |
+
pysrt
|
| 7 |
+
# Use specific torch CUDA wheels like the working example
|
| 8 |
+
torch --index-url https://download.pytorch.org/whl/cu118
|
| 9 |
+
torchaudio --index-url https://download.pytorch.org/whl/cu118
|
| 10 |
+
torchvision --index-url https://download.pytorch.org/whl/cu118
|
| 11 |
+
tqdm
|
| 12 |
+
vidqa
|
| 13 |
+
gemini-srt-translator
|
| 14 |
+
google-generativeai
|
| 15 |
+
yt-dlp
|
| 16 |
+
huggingface-hub
|
| 17 |
+
ffmpeg-python
|
| 18 |
+
setuptools
|
| 19 |
+
spaces
|