Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -9,6 +9,12 @@ from pathlib import Path
|
|
| 9 |
def download_file():
|
| 10 |
return gr.DownloadButton(visible=False)
|
| 11 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
def main(url, parameters, progress=gr.Progress()):
|
| 13 |
try:
|
| 14 |
font_type, font_size, font_color, service, target, style, subject = parameters.split(',')
|
|
@@ -80,22 +86,42 @@ def main(url, parameters, progress=gr.Progress()):
|
|
| 80 |
except Exception as e:
|
| 81 |
raise gr.Error(f"خطا در پردازش: {str(e)}")
|
| 82 |
|
|
|
|
| 83 |
with gr.Blocks() as demo:
|
| 84 |
-
gr.Markdown("
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 100 |
demo.launch(debug=True)
|
| 101 |
|
|
|
|
| 9 |
def download_file():
|
| 10 |
return gr.DownloadButton(visible=False)
|
| 11 |
|
| 12 |
+
# Connect the output video to both components
|
| 13 |
+
def update_download(output_video):
|
| 14 |
+
return [
|
| 15 |
+
gr.DownloadButton(visible=True, value=output_video),
|
| 16 |
+
gr.File(value=output_video)
|
| 17 |
+
]
|
| 18 |
def main(url, parameters, progress=gr.Progress()):
|
| 19 |
try:
|
| 20 |
font_type, font_size, font_color, service, target, style, subject = parameters.split(',')
|
|
|
|
| 86 |
except Exception as e:
|
| 87 |
raise gr.Error(f"خطا در پردازش: {str(e)}")
|
| 88 |
|
| 89 |
+
|
| 90 |
with gr.Blocks() as demo:
|
| 91 |
+
gr.Markdown("## سیستم پردازش ویدئو")
|
| 92 |
+
|
| 93 |
+
with gr.Row():
|
| 94 |
+
video_input = gr.Textbox(label="لینک ویدئو")
|
| 95 |
+
params = gr.Textbox(label="پارامترها (قلم,اندازه,رنگ)")
|
| 96 |
+
submit_btn = gr.Button("شروع پردازش", variant="primary")
|
| 97 |
+
|
| 98 |
+
progress_report = gr.Textbox(label="وضعیت", interactive=False)
|
| 99 |
+
download_btn = gr.DownloadButton(
|
| 100 |
+
label="دانلود ویدئو",
|
| 101 |
+
visible=False,
|
| 102 |
+
)
|
| 103 |
+
hidden_file = gr.File(visible=False)
|
| 104 |
+
|
| 105 |
+
# First chain: Process data and update hidden file
|
| 106 |
+
submit_btn.click(
|
| 107 |
+
fn=main,
|
| 108 |
+
inputs=[video_input, params],
|
| 109 |
+
outputs=[progress_report, hidden_file],
|
| 110 |
+
concurrency_limit=4,
|
| 111 |
+
)
|
| 112 |
+
|
| 113 |
+
# Second chain: Update download button when file is ready
|
| 114 |
+
def toggle_download(file_path):
|
| 115 |
+
if file_path:
|
| 116 |
+
return gr.DownloadButton(visible=True, value=file_path)
|
| 117 |
+
return gr.DownloadButton(visible=False)
|
| 118 |
+
|
| 119 |
+
hidden_file.change(
|
| 120 |
+
fn=toggle_download,
|
| 121 |
+
inputs=hidden_file,
|
| 122 |
+
outputs=download_btn,
|
| 123 |
+
queue=False
|
| 124 |
+
)
|
| 125 |
+
|
| 126 |
demo.launch(debug=True)
|
| 127 |
|