Rockali commited on
Commit
e2679f8
·
verified ·
1 Parent(s): 1a36a00

Upload folder using huggingface_hub

Browse files
Files changed (2) hide show
  1. app.py +138 -0
  2. requirements.txt +2 -0
app.py ADDED
@@ -0,0 +1,138 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import os
3
+ import tempfile
4
+ from moviepy.editor import VideoFileClip, concatenate_videoclips
5
+ import shutil
6
+
7
+ def concatenate_videos(video_files):
8
+ """
9
+ Concatenate multiple video clips seamlessly without gaps.
10
+
11
+ Args:
12
+ video_files: List of video file paths
13
+
14
+ Returns:
15
+ Path to the concatenated video file
16
+ """
17
+ if not video_files or len(video_files) < 2:
18
+ return "Please upload at least 2 video clips to concatenate."
19
+
20
+ try:
21
+ # Create a temporary directory for processing
22
+ with tempfile.TemporaryDirectory() as temp_dir:
23
+ # Load all video clips
24
+ clips = []
25
+ for video_file in video_files:
26
+ clip = VideoFileClip(video_file.name)
27
+ clips.append(clip)
28
+
29
+ # Concatenate clips without gaps
30
+ # The key is to use method="compose" for seamless transitions
31
+ final_clip = concatenate_videoclips(clips, method="compose")
32
+
33
+ # Create output file path
34
+ output_path = os.path.join(temp_dir, "merged_video.mp4")
35
+
36
+ # Write the final video with audio
37
+ final_clip.write_videofile(
38
+ output_path,
39
+ codec="libx264",
40
+ audio_codec="aac",
41
+ fps=24,
42
+ preset="fast",
43
+ logger="bar"
44
+ )
45
+
46
+ # Clean up clips
47
+ for clip in clips:
48
+ clip.close()
49
+ final_clip.close()
50
+
51
+ return output_path
52
+
53
+ except Exception as e:
54
+ return f"Error: {str(e)}"
55
+
56
+ def create_gradio_app():
57
+ """
58
+ Create and launch the Gradio application for video concatenation.
59
+ """
60
+ with gr.Blocks(title="Wan2.2 Video Merger - ادغام کلیپ‌های وان2.2", theme=gr.themes.Soft()) as demo:
61
+ gr.Markdown("# 🎬 Wan2.2 Video Merger")
62
+ gr.Markdown("### ادغام روان و بدون فاصله میان کلیپ‌های تولید شده با مدل wan2.2")
63
+ gr.Markdown("این ابزار به شما کمک می‌کند تا چند کلیپ وان2.2 را بدون مکس بین آن‌ها و با پخش روان و پشت سر هم ادغام کنید.")
64
+
65
+ with gr.Row():
66
+ with gr.Column():
67
+ gr.Markdown("### 📤 ورودی کلیپ‌ها")
68
+ video_input = gr.File(
69
+ file_count="multiple",
70
+ label="انتخاب کلیپ‌های وان2.2 (mp4, mov, avi)",
71
+ file_types=[".mp4", ".mov", ".avi"]
72
+ )
73
+
74
+ gr.Markdown("### ⚙️ تنظیمات")
75
+ quality_select = gr.Radio(
76
+ choices=["Fast", "Balanced", "High Quality"],
77
+ value="Balanced",
78
+ label="کیفیت پردازش",
79
+ info="انتخاب سرعت و کیفیت پردازش"
80
+ )
81
+
82
+ process_btn = gr.Button("🔄 ادغام کلیپ‌ها", variant="primary", size="lg")
83
+
84
+ with gr.Accordion("راهنما", open=False):
85
+ gr.Markdown("""
86
+ ### 📝 نحوه استفاده:
87
+ 1. چند کلیپ وان2.2 را انتخاب کنید (حداقل 2 کلیپ)
88
+ 2. کیفیت پردازش را انتخاب کنید
89
+ 3. دکمه ادغام را بزنید
90
+ 4. فیلم ادغام شده را دانلود کنید
91
+ """)
92
+
93
+ with gr.Column():
94
+ gr.Markdown("### 📊 خروجی")
95
+ output_video = gr.Video(label="فیلم ادغام شده (بدون مکس)")
96
+
97
+ status_text = gr.Textbox(
98
+ label="وضعیت پردازش",
99
+ placeholder="کلیپ‌ها را آپلود کنید و دکمه ادغام را بزنید..."
100
+ )
101
+
102
+ download_btn = gr.Button("⬇️ دانلود فیلم ادغام شده", variant="secondary")
103
+
104
+ # Event handlers
105
+ process_btn.click(
106
+ fn=concatenate_videos,
107
+ inputs=video_input,
108
+ outputs=[output_video, status_text],
109
+ api_visibility="public"
110
+ ).then(
111
+ fn=lambda: "✅ پردازش کامل شد! فیلم ادغام شده را مشاهده کنید.",
112
+ inputs=None,
113
+ outputs=status_text
114
+ )
115
+
116
+ download_btn.click(
117
+ fn=lambda: output_video,
118
+ inputs=None,
119
+ outputs=None
120
+ )
121
+
122
+ # Add footer with "Built with anycoder" link
123
+ gr.Markdown(
124
+ '<div style="text-align: center; margin-top: 20px; padding: 10px; background-color: #f5f5f5; border-radius: 10px;">'
125
+ 'ساخته شده با <a href="https://huggingface.co/spaces/akhaliq/anycoder" target="_blank" style="color: #1a73e8; text-decoration: none;">anycoder</a>'
126
+ '</div>'
127
+ )
128
+
129
+ return demo
130
+
131
+ if __name__ == "__main__":
132
+ app = create_gradio_app()
133
+ app.launch(
134
+ theme=gr.themes.Soft(primary_hue="blue"),
135
+ footer_links=[
136
+ {"label": "Built with anycoder", "url": "https://huggingface.co/spaces/akhaliq/anycoder"}
137
+ ]
138
+ )
requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ gradio>=6.0.2
2
+ moviepy