SPACERUNNER99 commited on
Commit
b6ea9e6
·
verified ·
1 Parent(s): 1bd792b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +42 -16
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
- with gr.Column():
86
- progress_output = gr.Textbox(label="وضعیت پردازش", visible=False)
87
- video_file_input = gr.Text(label="لینک ویدئو")
88
- parameters = gr.Text(label="پارامترهای زیرنویس (قلم، اندازه، رنگ)")
89
- btn = gr.Button("ایجاد ویدئو جدید")
90
- download_link = gr.Text(label="لینک دانلود")
91
-
92
- btn.click(
93
- fn=main,
94
- inputs=[video_file_input, parameters],
95
- outputs=[progress_output, download_link],
96
- concurrency_limit=4,
97
- )
98
- d = gr.DownloadButton(value=download_link.value, visible=True)
99
- d.click(download_file, None, d)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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