File size: 7,820 Bytes
47b4017
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
064c1eb
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
import gradio as gr
import shutil
import os

from dotenv import load_dotenv
load_dotenv()

from modules.summarizer import summarize_text
from modules.frame_extractor import extract_frame
from modules.thumbnail import generate_thumbnail
from modules.composer import compose_videos
from modules.subtitles import generate_subtitles
from modules.subtitle_burner import burn_subtitles


UPLOAD_DIR = "assets/uploads"
os.makedirs(UPLOAD_DIR, exist_ok=True)


# ---------------- FUNCTIONS ----------------

def save_uploaded_video(video_file):
    if video_file is None:
        return "❌ No video uploaded."

    filename = os.path.basename(video_file)
    destination = os.path.join(UPLOAD_DIR, filename)
    shutil.copy(video_file, destination)

    return f"βœ… Video uploaded: {filename}"


def summarize_ui(text):
    if not text.strip():
        return "Please enter text."
    return summarize_text(text)


def create_thumbnail(video_file, title_text):
    if video_file is None:
        return None
    frame = extract_frame(video_file)
    return generate_thumbnail(frame, title_text)


def compose_ui(video_files):
    if not video_files:
        return None
    return compose_videos(video_files)


def subtitle_ui(video):
    if video is None:
        return None
    return generate_subtitles(video)


def burn_subtitles_ui(video, subtitle_file):
    if video is None or subtitle_file is None:
        return None
    return burn_subtitles(video, subtitle_file)


# ---------------- CSS ----------------

custom_css = """
body{
background:linear-gradient(135deg,#020617,#0f172a);
font-family:Inter;
}

.hero{
text-align:center;
padding:50px;
}

.hero-title{
font-size:44px;
font-weight:800;
background:linear-gradient(90deg,#60a5fa,#a78bfa,#c084fc);
-webkit-background-clip:text;
-webkit-text-fill-color:transparent;
}

.navbar{
display:flex;
gap:20px;
justify-content:center;
margin-bottom:25px;
}

.card{
background:#0f172a;
padding:25px;
border-radius:14px;
box-shadow:0 8px 20px rgba(0,0,0,0.4);
}
"""


# ---------------- UI ----------------

with gr.Blocks(css=custom_css, theme=gr.themes.Soft()) as app:

    with gr.Column(elem_classes="hero"):
        gr.Markdown("""
<div class="hero-title">🎬 ClipForge AI</div>
Create viral short-form content using AI
""")

    # NAVIGATION BAR
    with gr.Row():
        btn_upload = gr.Button("πŸ“₯ Upload")
        btn_summary = gr.Button("πŸ“ Summary")
        btn_thumbnail = gr.Button("πŸ–Ό Thumbnail")
        btn_subtitle = gr.Button("🎀 Subtitles")
        btn_composer = gr.Button("🎞 Composer")
        btn_burn = gr.Button("πŸ”₯ Burn")

    # SECTIONS

    with gr.Column(visible=True) as upload_section:
        with gr.Column(elem_classes="card"):
            video_input = gr.Video()
            upload_btn = gr.Button("Upload Video")
            upload_status = gr.Textbox(label="Status")

            upload_btn.click(
                save_uploaded_video,
                inputs=video_input,
                outputs=upload_status
            )


    with gr.Column(visible=False) as summary_section:
        with gr.Column(elem_classes="card"):
            input_text = gr.Textbox(lines=5)
            summarize_btn = gr.Button("Generate Summary")
            output_text = gr.Textbox()

            summarize_btn.click(
                summarize_ui,
                inputs=input_text,
                outputs=output_text
            )


    with gr.Column(visible=False) as thumb_section:
        with gr.Column(elem_classes="card"):
            video_for_thumb = gr.Video()
            title_text = gr.Textbox()
            thumb_btn = gr.Button("Generate Thumbnail")
            thumbnail_output = gr.Image()

            thumb_btn.click(
                create_thumbnail,
                inputs=[video_for_thumb, title_text],
                outputs=thumbnail_output
            )


    with gr.Column(visible=False) as subtitle_section:
        with gr.Column(elem_classes="card"):
            video_input_sub = gr.Video()
            subtitle_btn = gr.Button("Generate Subtitles")
            subtitle_file = gr.File()

            subtitle_btn.click(
                subtitle_ui,
                inputs=video_input_sub,
                outputs=subtitle_file
            )


    with gr.Column(visible=False) as composer_section:
        with gr.Column(elem_classes="card"):
            video_inputs = gr.File(file_types=[".mp4"], file_count="multiple")
            compose_btn = gr.Button("Compose Video")
            final_video = gr.Video()

            compose_btn.click(
                compose_ui,
                inputs=video_inputs,
                outputs=final_video
            )


    with gr.Column(visible=False) as burn_section:
        with gr.Column(elem_classes="card"):
            video_input_burn = gr.Video()
            subtitle_input = gr.File()
            burn_btn = gr.Button("Burn Subtitles")
            output_video = gr.Video()

            burn_btn.click(
                burn_subtitles_ui,
                inputs=[video_input_burn, subtitle_input],
                outputs=output_video
            )


    # ---------- NAVIGATION FUNCTIONS (FIXED) ----------

    def show_upload():
        return (
            gr.update(visible=True),
            gr.update(visible=False),
            gr.update(visible=False),
            gr.update(visible=False),
            gr.update(visible=False),
            gr.update(visible=False),
        )


    def show_summary():
        return (
            gr.update(visible=False),
            gr.update(visible=True),
            gr.update(visible=False),
            gr.update(visible=False),
            gr.update(visible=False),
            gr.update(visible=False),
        )


    def show_thumb():
        return (
            gr.update(visible=False),
            gr.update(visible=False),
            gr.update(visible=True),
            gr.update(visible=False),
            gr.update(visible=False),
            gr.update(visible=False),
        )


    def show_subtitle():
        return (
            gr.update(visible=False),
            gr.update(visible=False),
            gr.update(visible=False),
            gr.update(visible=True),
            gr.update(visible=False),
            gr.update(visible=False),
        )


    def show_composer():
        return (
            gr.update(visible=False),
            gr.update(visible=False),
            gr.update(visible=False),
            gr.update(visible=False),
            gr.update(visible=True),
            gr.update(visible=False),
        )


    def show_burn():
        return (
            gr.update(visible=False),
            gr.update(visible=False),
            gr.update(visible=False),
            gr.update(visible=False),
            gr.update(visible=False),
            gr.update(visible=True),
        )


    btn_upload.click(show_upload,
        outputs=[upload_section, summary_section, thumb_section, subtitle_section, composer_section, burn_section])

    btn_summary.click(show_summary,
        outputs=[upload_section, summary_section, thumb_section, subtitle_section, composer_section, burn_section])

    btn_thumbnail.click(show_thumb,
        outputs=[upload_section, summary_section, thumb_section, subtitle_section, composer_section, burn_section])

    btn_subtitle.click(show_subtitle,
        outputs=[upload_section, summary_section, thumb_section, subtitle_section, composer_section, burn_section])

    btn_composer.click(show_composer,
        outputs=[upload_section, summary_section, thumb_section, subtitle_section, composer_section, burn_section])

    btn_burn.click(show_burn,
        outputs=[upload_section, summary_section, thumb_section, subtitle_section, composer_section, burn_section])


app.launch(server_name="0.0.0.0", server_port=7860)