Spaces:
Running
Running
File size: 4,029 Bytes
736d327 3c163a9 6903bca 3c163a9 736d327 3eba90e e89f57c 3c163a9 e89f57c 576929d a88794e 4f894e0 e89f57c 576929d a88794e 4f894e0 3c163a9 e89f57c 0324ab5 3c163a9 115a03f 3c163a9 4f894e0 e89f57c 576929d a88794e 4f894e0 3c163a9 0324ab5 3c163a9 3eba90e 4f894e0 e89f57c 576929d a88794e 4f894e0 3c163a9 4f894e0 3c163a9 e89f57c 0324ab5 3c163a9 115a03f 4f894e0 3c163a9 4f894e0 3c163a9 115a03f 3c163a9 a88794e e89f57c 3c163a9 3eba90e e89f57c 736d327 3c163a9 736d327 3c163a9 576929d 3c163a9 576929d 3c163a9 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
import requests
import os
import time
import tempfile
from gradio_client import Client, handle_file
import gradio as gr
def main(url, parameters, progress=gr.Progress()):
try:
font_type, font_size, font_color, service, target, style, subject = parameters.split(',')
progress(0, desc="پردازش شروع شد")
yield "پردازش شروع شد", None
# Transcription Stage - Updated API endpoint
progress(0.35, desc="تبدیل صوت به متن")
yield "تبدیل صوت به متن", None
transcribe_client = Client("rayesh/transcribe")
try:
# Changed to use default API name
job = transcribe_client.submit(url)
while not job.done():
time.sleep(0.5)
progress(0.35, desc="تبدیل صوت به متن")
results = job.outputs()[0]
print(results)
if len(results) != 3:
raise ValueError(f"Expected 3 outputs, got {len(results)}")
srt_file, video, mp3_file = results
finally:
transcribe_client.close()
# Translation Stage - Updated API endpoint
progress(0.55, desc="در حال ترجمه")
yield "در حال ترجمه", None
translate_client = Client("rayesh/translate")
try:
# Changed to use default API name
job = translate_client.submit(results[0], target)
while not job.done():
time.sleep(0.5)
progress(0.55, desc="در حال ترجمه")
translated_text = job.outputs()[0]
finally:
translate_client.close()
# Video Processing Stage - Updated API endpoint
progress(0.75, desc="پردازش ویدئو")
yield "درحال پردازش ویدئو", None
video_client = Client("SPACERUNNER99/video_edite")
try:
# Changed API name to match typical video processing endpoints
job = video_client.submit(
url,
translated_text,
font_type,
font_size,
font_color,
api_name="/process" # Changed to common endpoint name
)
while not job.done():
time.sleep(0.5)
progress(0.75, desc="پردازش ویدئو")
output_video = job.outputs()[0]['video']
# Create temporary file
with tempfile.NamedTemporaryFile(delete=False, suffix=".mp4") as tmp_file:
response = requests.get(output_video)
tmp_file.write(response.content)
tmp_file_path = tmp_file.name
# Generate direct download link
base_url = os.environ.get('GRADIO_SERVER_NAME', 'http://localhost:7860')
download_url = f"{base_url}/file/{tmp_file_path}"
print(download_url)
finally:
video_client.close()
yield "پردازش کامل شد", download_url
except Exception as e:
raise gr.Error(f"خطا در پردازش: {str(e)}")
with gr.Blocks() as demo:
gr.Markdown("ویدئو خود را آپلود کنید و پارامترها را تنظیم نمایید")
with gr.Column():
progress_output = gr.Textbox(label="وضعیت پردازش", visible=False)
video_file_input = gr.Text(label="لینک ویدئو")
parameters = gr.Text(label="پارامترهای زیرنویس (قلم، اندازه، رنگ)")
btn = gr.Button("ایجاد ویدئو جدید")
download_link = gr.HTML(label="لینک دانلود")
btn.click(
fn=main,
inputs=[video_file_input, parameters],
outputs=[progress_output, download_link],
concurrency_limit=4,
)
demo.launch(debug=True)
|