ThorAILabs commited on
Commit
3792d18
Β·
verified Β·
1 Parent(s): 044db5e

fix build error

Browse files
Files changed (1) hide show
  1. app.py +99 -70
app.py CHANGED
@@ -1,87 +1,116 @@
1
  import gradio as gr
2
- from converter import Converter
3
  import random
4
- import time
5
-
6
- css = """
7
- @keyframes gradient {
8
- 0% { background-position: 0% 50%; }
9
- 50% { background-position: 100% 50%; }
10
- 100% { background-position: 0% 50%; }
11
- }
12
-
13
- body {
14
- background: linear-gradient(-45deg, #ee7752, #e73c7e, #23a6d5, #23d5ab);
15
- background-size: 400% 400%;
16
- animation: gradient 15s ease infinite;
17
- min-height: 100vh;
18
- }
19
-
20
- .header {
21
- color: white;
22
- text-shadow: 2px 2px 4px rgba(0,0,0,0.5);
23
- font-family: 'Arial Rounded MT Bold';
24
- background: linear-gradient(90deg, #ff6b6b, #4ecdc4);
25
- -webkit-background-clip: text;
26
- -webkit-text-fill-color: transparent;
27
- }
28
-
29
- .funny-message {
30
- font-style: italic;
31
- color: #fff;
32
- text-align: center;
33
- margin: 10px 0;
34
- }
35
- """
36
 
37
  funny_messages = [
38
  "Converting your video with pure magic... ✨",
39
  "Baking digital cookies for the conversion elves... πŸͺ",
40
  "Teaching pixels to do the cha-cha slide... πŸ’ƒ",
41
  "Convincing bits to switch teams... ⚽",
42
- "Defragmenting your video's existential crisis... πŸ€”"
 
 
 
 
 
43
  ]
44
 
45
- def convert_video(input_video, output_format, progress=gr.Progress()):
 
 
46
  progress(0, random.choice(funny_messages))
47
-
48
- c = Converter()
49
- info = c.probe(input_video)
50
-
51
- output_file = f"output.{output_format}"
52
- params = {
53
- 'format': output_format,
54
- 'video': {'codec': 'libx264', 'fps': info.video.video_fps},
55
- 'audio': {'codec': 'aac'}
56
- }
57
-
58
- conv = c.convert(input_video, output_file, params)
59
- for i, timecode in enumerate(conv):
60
- progress(i/100, random.choice(funny_messages))
61
- time.sleep(0.1)
62
-
 
 
 
 
 
 
63
  return output_file
64
 
65
- with gr.Blocks(theme=gr.themes.Glass(), css=css) as demo:
66
- gr.Markdown("""# πŸš€ **ULTIMATE Super-Fast Video Converter**
67
- πŸ”’ *Your files are never stored or shared - conversion happens in your browser!*""",
68
- elem_classes="header")
69
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
70
  with gr.Row():
71
- input_vid = gr.Video(label="Upload Video")
72
- output_vid = gr.Video(label="Converted Video")
73
-
74
- format_dd = gr.Dropdown(["mp4", "mov", "avi", "wmv", "mkv"], label="Output Format", value="mp4")
75
- convert_btn = gr.Button("✨ Convert Now!", variant="primary")
76
-
77
- progress_text = gr.Markdown(elem_classes="funny-message")
78
- progress_bar = gr.Progress()
79
-
80
- convert_btn.click(
81
- convert_video,
82
- [input_vid, format_dd],
83
- output_vid,
84
- show_progress="minimal"
85
  )
 
 
86
 
87
  demo.launch()
 
1
  import gradio as gr
2
+ from moviepy.editor import VideoFileClip
3
  import random
4
+ import os
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5
 
6
  funny_messages = [
7
  "Converting your video with pure magic... ✨",
8
  "Baking digital cookies for the conversion elves... πŸͺ",
9
  "Teaching pixels to do the cha-cha slide... πŸ’ƒ",
10
  "Convincing bits to switch teams... ⚽",
11
+ "Defragmenting your video's existential crisis... πŸ€”",
12
+ "Polishing every pixel for maximum shine... πŸ’Ž",
13
+ "Making your video do a quick wardrobe change... πŸ‘—",
14
+ "Negotiating with the codec goblins... πŸ§™",
15
+ "Telling your video to hold still... πŸ“Έ",
16
+ "Whispering sweet nothings to the file system... πŸ’Œ"
17
  ]
18
 
19
+ def convert_video(input_video, output_format, progress=gr.Progress(track_tqdm=True)):
20
+ if input_video is None:
21
+ raise gr.Error("Please upload a video first!")
22
  progress(0, random.choice(funny_messages))
23
+ clip = VideoFileClip(input_video)
24
+ output_file = f"converted_output.{output_format}"
25
+ # Simulate progress with funny messages
26
+ for i in range(1, 5):
27
+ progress(i/5, random.choice(funny_messages))
28
+ # Set codec based on format
29
+ codec = None
30
+ if output_format == "mp4":
31
+ codec = "libx264"
32
+ elif output_format == "webm":
33
+ codec = "libvpx"
34
+ elif output_format == "avi":
35
+ codec = "png"
36
+ elif output_format == "mov":
37
+ codec = "libx264"
38
+ elif output_format == "wmv":
39
+ codec = "libx264" # WMV support is limited; fallback to mp4 codec for demo
40
+ try:
41
+ clip.write_videofile(output_file, codec=codec, audio_codec="aac" if output_format in ["mp4", "mov"] else None, verbose=False, logger=None)
42
+ except Exception as e:
43
+ raise gr.Error(f"Conversion failed: {e}")
44
+ progress(1, "Done! Enjoy your freshly converted video πŸŽ‰")
45
  return output_file
46
 
47
+ css = """
48
+ body {
49
+ background: linear-gradient(120deg, #23a6d5 0%, #e73c7e 100%);
50
+ background-size: 200% 200%;
51
+ animation: gradientBG 10s ease-in-out infinite;
52
+ }
53
+ @keyframes gradientBG {
54
+ 0% {background-position: 0% 50%;}
55
+ 50% {background-position: 100% 50%;}
56
+ 100% {background-position: 0% 50%;}
57
+ }
58
+ .gradio-container {
59
+ border-radius: 18px !important;
60
+ box-shadow: 0 8px 32px 0 rgba(31, 38, 135, 0.37) !important;
61
+ background: rgba(255,255,255,0.15) !important;
62
+ backdrop-filter: blur(8px) !important;
63
+ border: 1px solid rgba(255,255,255,0.18) !important;
64
+ }
65
+ h1, .gr-markdown {
66
+ color: #fff !important;
67
+ text-shadow: 2px 2px 8px rgba(0,0,0,0.3);
68
+ font-family: 'Segoe UI', 'Arial Rounded MT Bold', Arial, sans-serif;
69
+ }
70
+ .gr-button {
71
+ background: linear-gradient(90deg, #ff6b6b 0%, #4ecdc4 100%) !important;
72
+ color: #fff !important;
73
+ border: none !important;
74
+ border-radius: 8px !important;
75
+ font-size: 1.1em !important;
76
+ transition: transform 0.2s;
77
+ }
78
+ .gr-button:hover {
79
+ transform: scale(1.05) rotate(-2deg);
80
+ box-shadow: 0 4px 12px rgba(78,205,196,0.25);
81
+ }
82
+ .gr-video {
83
+ border-radius: 12px !important;
84
+ box-shadow: 0 2px 12px rgba(35,166,213,0.12);
85
+ background: rgba(255,255,255,0.1) !important;
86
+ }
87
+ .gr-dropdown {
88
+ border-radius: 8px !important;
89
+ background: rgba(255,255,255,0.2) !important;
90
+ color: #333 !important;
91
+ }
92
+ """
93
+
94
+ with gr.Blocks(css=css, theme=gr.themes.Glass()) as demo:
95
+ gr.Markdown(
96
+ """
97
+ <h1 style="font-size:2.5em; margin-bottom: 0.2em;">πŸš€ ULTIMATE Super-Fast Video Converter</h1>
98
+ <div style="font-size:1.2em; color:#fff; margin-bottom:1em;">
99
+ πŸ”’ <b>Secure:</b> We never share your files. Everything happens right here in your browser!
100
+ <br>🎬 <b>Convert any common video format to any other:</b> mp4, avi, mov, wmv, webm
101
+ </div>
102
+ """,
103
+ elem_id="main-header"
104
+ )
105
  with gr.Row():
106
+ inp = gr.Video(label="Upload Video", interactive=True)
107
+ out = gr.Video(label="Converted Video", interactive=False)
108
+ fmt = gr.Dropdown(
109
+ ["mp4", "avi", "mov", "wmv", "webm"],
110
+ value="mp4",
111
+ label="Choose Output Format"
 
 
 
 
 
 
 
 
112
  )
113
+ btn = gr.Button("✨ Convert Now!")
114
+ btn.click(convert_video, [inp, fmt], out)
115
 
116
  demo.launch()