process_miniapp / app.py
SPACERUNNER99's picture
Update app.py
576929d verified
raw
history blame
2.19 kB
import requests
import os
import time
from gradio_client import Client, handle_file
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
progress(0.35, desc="تبدیل صوت به متن")
yield "تبدیل صوت به متن", None
transcribe_client = Client("rayesh/transcribe")
try:
time.sleep(0.5)
results = job.outputs()[0]
print(results)
if len(results) != 3:
raise ValueError(f"Expected 3 outputs, got {len(results)}")
# Translation Stage
progress(0.55, desc="در حال ترجمه")
yield "در حال ترجمه", None
translate_client = Client("rayesh/translate")
try:
# Video Processing Stage
progress(0.75, desc="پردازش ویدئو")
yield "درحال پردازش ویدئو", None
video_client = Client("SPACERUNNER99/video_edite")
try:
time.sleep(0.5)
output_video = job.outputs()[0]['video']
finally:
video_client.close()
yield "پردازش کامل شد", output_video
except Exception as e:
raise gr.Error(f"خطا در پردازش: {str(e)}")
with gr.Blocks() as demo:
gr.Markdown("Start typing below and then click **Run** to see the progress and final output.")
with gr.Column():
progress_output = gr.Textbox(label="Progress", visible=False)
video_file_input = gr.Text(label="Video URL")
parameters = gr.Text(label="Additional Parameters (for subtitles: color,font)")
btn = gr.Button("Create")
video_file_output = gr.Video(label="Result Video")
btn.click(
fn=main,
inputs=[video_file_input, parameters],
outputs=[progress_output, video_file_output],
concurrency_limit=4,
)
demo.launch(debug=True)