Spaces:
Runtime error
Runtime error
Kvikontent
commited on
Commit
•
1b05743
1
Parent(s):
749e707
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,59 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from moviepy.editor import *
|
3 |
+
from PIL import ImageFont, ImageDraw, Image
|
4 |
+
|
5 |
+
def edit_video(video_file, name, author, font, filter):
|
6 |
+
# Load the video
|
7 |
+
clip = VideoFileClip(video_file)
|
8 |
+
|
9 |
+
# Apply the chosen filter
|
10 |
+
clip = eval(f"clip.{filter}()")
|
11 |
+
|
12 |
+
# Load the font based on user input
|
13 |
+
font_path = f"{font}.ttf"
|
14 |
+
font_size = clip.size[0] // 10
|
15 |
+
font = ImageFont.truetype(font_path, font_size)
|
16 |
+
|
17 |
+
# Create an image with the author text
|
18 |
+
author_text = f"Author: {author}"
|
19 |
+
author_image = Image.new('RGB', (clip.w//2, clip.h//8), (0, 0, 0))
|
20 |
+
author_draw = ImageDraw.Draw(author_image)
|
21 |
+
author_draw.text((10, 10), author_text, font=font, fill=(255, 255, 255))
|
22 |
+
|
23 |
+
# Create an image with the bigger text
|
24 |
+
bigger_text = f"Author: {author}"
|
25 |
+
bigger_image = Image.new('RGB', (clip.w//2, clip.h//4), (0, 0, 0))
|
26 |
+
bigger_draw = ImageDraw.Draw(bigger_image)
|
27 |
+
bigger_draw.text((10, 10), bigger_text, font=font, fill=(255, 255, 255))
|
28 |
+
|
29 |
+
# Create a composite video with the texts
|
30 |
+
text_clip1 = ImageClip(author_image).set_duration(4).set_position(("right", "bottom"))
|
31 |
+
text_clip2 = ImageClip(bigger_image).set_duration(4).set_position(("right", "bottom"))
|
32 |
+
composite_clip = CompositeVideoClip([clip, text_clip1, text_clip2])
|
33 |
+
|
34 |
+
# Save the edited video
|
35 |
+
output_file = f"{name}_edited.mp4"
|
36 |
+
composite_clip.write_videofile(output_file, codec='libx264')
|
37 |
+
|
38 |
+
return output_file
|
39 |
+
|
40 |
+
def video_editor(name, author, font, filter, video_file):
|
41 |
+
edited_video = edit_video(video_file, name, author, font, filter)
|
42 |
+
return edited_video
|
43 |
+
|
44 |
+
# Define the inputs and outputs for Gradio app
|
45 |
+
inputs = [
|
46 |
+
gr.inputs.Textbox(label="Video Name"),
|
47 |
+
gr.inputs.Textbox(label="Author Name"),
|
48 |
+
gr.inputs.Radio(["Arial", "Barbie", "MrBeast", "OptiAgle"], label="Font"),
|
49 |
+
gr.inputs.Radio(["blur", "rotate", "resize", "mirror"], label="Filter"),
|
50 |
+
gr.inputs.File(label="Video File")
|
51 |
+
]
|
52 |
+
|
53 |
+
outputs = gr.outputs.File(label="Edited Video")
|
54 |
+
|
55 |
+
# Create a Gradio app interface
|
56 |
+
grapp = gr.Interface(fn=video_editor, inputs=inputs, outputs=outputs, capture_session=True)
|
57 |
+
|
58 |
+
# Run the Gradio app
|
59 |
+
grapp.launch()
|