Spaces:
Runtime error
Runtime error
File size: 4,117 Bytes
0cd2f18 3792d18 0cd2f18 3792d18 0cd2f18 3792d18 0cd2f18 3792d18 0cd2f18 3792d18 0cd2f18 3792d18 0cd2f18 3792d18 0cd2f18 3792d18 0cd2f18 |
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 |
import gradio as gr
from moviepy.editor import VideoFileClip
import random
import os
funny_messages = [
"Converting your video with pure magic... β¨",
"Baking digital cookies for the conversion elves... πͺ",
"Teaching pixels to do the cha-cha slide... π",
"Convincing bits to switch teams... β½",
"Defragmenting your video's existential crisis... π€",
"Polishing every pixel for maximum shine... π",
"Making your video do a quick wardrobe change... π",
"Negotiating with the codec goblins... π§",
"Telling your video to hold still... πΈ",
"Whispering sweet nothings to the file system... π"
]
def convert_video(input_video, output_format, progress=gr.Progress(track_tqdm=True)):
if input_video is None:
raise gr.Error("Please upload a video first!")
progress(0, random.choice(funny_messages))
clip = VideoFileClip(input_video)
output_file = f"converted_output.{output_format}"
# Simulate progress with funny messages
for i in range(1, 5):
progress(i/5, random.choice(funny_messages))
# Set codec based on format
codec = None
if output_format == "mp4":
codec = "libx264"
elif output_format == "webm":
codec = "libvpx"
elif output_format == "avi":
codec = "png"
elif output_format == "mov":
codec = "libx264"
elif output_format == "wmv":
codec = "libx264" # WMV support is limited; fallback to mp4 codec for demo
try:
clip.write_videofile(output_file, codec=codec, audio_codec="aac" if output_format in ["mp4", "mov"] else None, verbose=False, logger=None)
except Exception as e:
raise gr.Error(f"Conversion failed: {e}")
progress(1, "Done! Enjoy your freshly converted video π")
return output_file
css = """
body {
background: linear-gradient(120deg, #23a6d5 0%, #e73c7e 100%);
background-size: 200% 200%;
animation: gradientBG 10s ease-in-out infinite;
}
@keyframes gradientBG {
0% {background-position: 0% 50%;}
50% {background-position: 100% 50%;}
100% {background-position: 0% 50%;}
}
.gradio-container {
border-radius: 18px !important;
box-shadow: 0 8px 32px 0 rgba(31, 38, 135, 0.37) !important;
background: rgba(255,255,255,0.15) !important;
backdrop-filter: blur(8px) !important;
border: 1px solid rgba(255,255,255,0.18) !important;
}
h1, .gr-markdown {
color: #fff !important;
text-shadow: 2px 2px 8px rgba(0,0,0,0.3);
font-family: 'Segoe UI', 'Arial Rounded MT Bold', Arial, sans-serif;
}
.gr-button {
background: linear-gradient(90deg, #ff6b6b 0%, #4ecdc4 100%) !important;
color: #fff !important;
border: none !important;
border-radius: 8px !important;
font-size: 1.1em !important;
transition: transform 0.2s;
}
.gr-button:hover {
transform: scale(1.05) rotate(-2deg);
box-shadow: 0 4px 12px rgba(78,205,196,0.25);
}
.gr-video {
border-radius: 12px !important;
box-shadow: 0 2px 12px rgba(35,166,213,0.12);
background: rgba(255,255,255,0.1) !important;
}
.gr-dropdown {
border-radius: 8px !important;
background: rgba(255,255,255,0.2) !important;
color: #333 !important;
}
"""
with gr.Blocks(css=css, theme=gr.themes.Glass()) as demo:
gr.Markdown(
"""
<h1 style="font-size:2.5em; margin-bottom: 0.2em;">π ULTIMATE Super-Fast Video Converter</h1>
<div style="font-size:1.2em; color:#fff; margin-bottom:1em;">
π <b>Secure:</b> We never share your files. Everything happens right here in your browser!
<br>π¬ <b>Convert any common video format to any other:</b> mp4, avi, mov, wmv, webm
</div>
""",
elem_id="main-header"
)
with gr.Row():
inp = gr.Video(label="Upload Video", interactive=True)
out = gr.Video(label="Converted Video", interactive=False)
fmt = gr.Dropdown(
["mp4", "avi", "mov", "wmv", "webm"],
value="mp4",
label="Choose Output Format"
)
btn = gr.Button("β¨ Convert Now!")
btn.click(convert_video, [inp, fmt], out)
demo.launch() |