Newest / app.py
Peeble's picture
Create app.py
0b40e67 verified
import os
import requests
import gradio as gr
from moviepy.editor import (ImageClip, TextClip, CompositeVideoClip,
concatenate_videoclips, AudioFileClip)
# Function to download a file from a URL and save it locally.
def download_file(url, filename):
response = requests.get(url)
with open(filename, 'wb') as f:
f.write(response.content)
return filename
def generate_video():
# URLs for the scene prompt images (representing your texts)
scene1_url = "https://api.deepai.org/job-view-file/1584dd41-22dc-42af-a53a-921cf005842d/outputs/output.jpg"
scene2_url = "https://api.deepai.org/job-view-file/d211f739-cfc3-4605-8991-1812621ca20a/outputs/output.jpg"
scene3_url = "https://api.deepai.org/job-view-file/e1f56cf2-906d-4e29-a76b-07a321892f11/outputs/output.jpg"
# URL for the glitch effect (on Imgur)
glitch_url = "https://i.giphy.com/l378vMZ1IbLcmj3H2.webp"
# URL for the jumpscare sound effect
sound_url = "https://www.myinstants.com/media/sounds/five-nights-at-freddys-2-full-scream-sound.mp3"
# Download files and save locally.
scene1_file = download_file(scene1_url, "scene1.jpg")
scene2_file = download_file(scene2_url, "scene2.jpg")
scene3_file = download_file(scene3_url, "scene3.jpg")
glitch_file = download_file(glitch_url, "glitch.webp")
sound_file = download_file(sound_url, "jumpscare.mp3")
# Define durations for each scene (in seconds)
duration1 = 10
duration2 = 10
duration3 = 10
# Create image clips for each scene, resizing them to 640x480.
clip1 = ImageClip(scene1_file).set_duration(duration1).resize((640, 480))
clip2 = ImageClip(scene2_file).set_duration(duration2).resize((640, 480))
clip3 = ImageClip(scene3_file).set_duration(duration3).resize((640, 480))
# Create text overlays for each scene (optional).
text1 = TextClip("Scene 1", fontsize=40, color='white', bg_color='black')\
.set_duration(duration1).set_position('bottom')
text2 = TextClip("Scene 2", fontsize=40, color='white', bg_color='black')\
.set_duration(duration2).set_position('bottom')
text3 = TextClip("Scene 3", fontsize=40, color='white', bg_color='black')\
.set_duration(duration3).set_position('bottom')
# Overlay text on the image clips using CompositeVideoClip.
scene1 = CompositeVideoClip([clip1, text1])
scene2 = CompositeVideoClip([clip2, text2])
scene3 = CompositeVideoClip([clip3, text3])
# Concatenate the scene clips to form the base video.
base_video = concatenate_videoclips([scene1, scene2, scene3], method="compose")
# Load the glitch effect image as a clip and overlay it on the entire video.
glitch_clip = ImageClip(glitch_file).set_duration(base_video.duration)\
.resize((640, 480)).set_opacity(0.3)
video_with_glitch = CompositeVideoClip([base_video, glitch_clip])
# Load the jumpscare sound and set it as the video's audio.
audio_clip = AudioFileClip(sound_file)
final_video = video_with_glitch.set_audio(audio_clip)
# Export the final video to a file.
output_filename = "analog_horror_video.mp4"
final_video.write_videofile(output_filename, codec="libx264", fps=24)
# Return the generated video file.
return output_filename
# Define a Gradio interface with no input parameters and a video output.
iface = gr.Interface(
fn=generate_video,
inputs=[],
outputs=gr.Video(label="Analog Horror Video"),
title="Analog Horror Video Generator",
description="Generates an analog horror video with glitch effects and jumpscare sound."
)
if __name__ == "__main__":
iface.launch()