Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import requests
|
| 3 |
+
import gradio as gr
|
| 4 |
+
from moviepy.editor import (ImageClip, TextClip, CompositeVideoClip,
|
| 5 |
+
concatenate_videoclips, AudioFileClip)
|
| 6 |
+
|
| 7 |
+
# Function to download a file from a URL and save it locally.
|
| 8 |
+
def download_file(url, filename):
|
| 9 |
+
response = requests.get(url)
|
| 10 |
+
with open(filename, 'wb') as f:
|
| 11 |
+
f.write(response.content)
|
| 12 |
+
return filename
|
| 13 |
+
|
| 14 |
+
def generate_video():
|
| 15 |
+
# URLs for the scene prompt images (representing your texts)
|
| 16 |
+
scene1_url = "https://api.deepai.org/job-view-file/1584dd41-22dc-42af-a53a-921cf005842d/outputs/output.jpg"
|
| 17 |
+
scene2_url = "https://api.deepai.org/job-view-file/d211f739-cfc3-4605-8991-1812621ca20a/outputs/output.jpg"
|
| 18 |
+
scene3_url = "https://api.deepai.org/job-view-file/e1f56cf2-906d-4e29-a76b-07a321892f11/outputs/output.jpg"
|
| 19 |
+
|
| 20 |
+
# URL for the glitch effect (on Imgur)
|
| 21 |
+
glitch_url = "https://i.giphy.com/l378vMZ1IbLcmj3H2.webp"
|
| 22 |
+
|
| 23 |
+
# URL for the jumpscare sound effect
|
| 24 |
+
sound_url = "https://www.myinstants.com/media/sounds/five-nights-at-freddys-2-full-scream-sound.mp3"
|
| 25 |
+
|
| 26 |
+
# Download files and save locally.
|
| 27 |
+
scene1_file = download_file(scene1_url, "scene1.jpg")
|
| 28 |
+
scene2_file = download_file(scene2_url, "scene2.jpg")
|
| 29 |
+
scene3_file = download_file(scene3_url, "scene3.jpg")
|
| 30 |
+
glitch_file = download_file(glitch_url, "glitch.webp")
|
| 31 |
+
sound_file = download_file(sound_url, "jumpscare.mp3")
|
| 32 |
+
|
| 33 |
+
# Define durations for each scene (in seconds)
|
| 34 |
+
duration1 = 10
|
| 35 |
+
duration2 = 10
|
| 36 |
+
duration3 = 10
|
| 37 |
+
|
| 38 |
+
# Create image clips for each scene, resizing them to 640x480.
|
| 39 |
+
clip1 = ImageClip(scene1_file).set_duration(duration1).resize((640, 480))
|
| 40 |
+
clip2 = ImageClip(scene2_file).set_duration(duration2).resize((640, 480))
|
| 41 |
+
clip3 = ImageClip(scene3_file).set_duration(duration3).resize((640, 480))
|
| 42 |
+
|
| 43 |
+
# Create text overlays for each scene (optional).
|
| 44 |
+
text1 = TextClip("Scene 1", fontsize=40, color='white', bg_color='black')\
|
| 45 |
+
.set_duration(duration1).set_position('bottom')
|
| 46 |
+
text2 = TextClip("Scene 2", fontsize=40, color='white', bg_color='black')\
|
| 47 |
+
.set_duration(duration2).set_position('bottom')
|
| 48 |
+
text3 = TextClip("Scene 3", fontsize=40, color='white', bg_color='black')\
|
| 49 |
+
.set_duration(duration3).set_position('bottom')
|
| 50 |
+
|
| 51 |
+
# Overlay text on the image clips using CompositeVideoClip.
|
| 52 |
+
scene1 = CompositeVideoClip([clip1, text1])
|
| 53 |
+
scene2 = CompositeVideoClip([clip2, text2])
|
| 54 |
+
scene3 = CompositeVideoClip([clip3, text3])
|
| 55 |
+
|
| 56 |
+
# Concatenate the scene clips to form the base video.
|
| 57 |
+
base_video = concatenate_videoclips([scene1, scene2, scene3], method="compose")
|
| 58 |
+
|
| 59 |
+
# Load the glitch effect image as a clip and overlay it on the entire video.
|
| 60 |
+
glitch_clip = ImageClip(glitch_file).set_duration(base_video.duration)\
|
| 61 |
+
.resize((640, 480)).set_opacity(0.3)
|
| 62 |
+
video_with_glitch = CompositeVideoClip([base_video, glitch_clip])
|
| 63 |
+
|
| 64 |
+
# Load the jumpscare sound and set it as the video's audio.
|
| 65 |
+
audio_clip = AudioFileClip(sound_file)
|
| 66 |
+
final_video = video_with_glitch.set_audio(audio_clip)
|
| 67 |
+
|
| 68 |
+
# Export the final video to a file.
|
| 69 |
+
output_filename = "analog_horror_video.mp4"
|
| 70 |
+
final_video.write_videofile(output_filename, codec="libx264", fps=24)
|
| 71 |
+
|
| 72 |
+
# Return the generated video file.
|
| 73 |
+
return output_filename
|
| 74 |
+
|
| 75 |
+
# Define a Gradio interface with no input parameters and a video output.
|
| 76 |
+
iface = gr.Interface(
|
| 77 |
+
fn=generate_video,
|
| 78 |
+
inputs=[],
|
| 79 |
+
outputs=gr.Video(label="Analog Horror Video"),
|
| 80 |
+
title="Analog Horror Video Generator",
|
| 81 |
+
description="Generates an analog horror video with glitch effects and jumpscare sound."
|
| 82 |
+
)
|
| 83 |
+
|
| 84 |
+
if __name__ == "__main__":
|
| 85 |
+
iface.launch()
|