AsifBridge's picture
Update app.py
e6e9295 verified
import gradio as gr
import openai # Ensure OpenAI API is accessible and configured
import random
# Predefined lists for variety and efficiency
visual_options = [
"A vibrant morning scene in a bustling {location}. The camera pans across a warm, golden-lit environment with people interacting joyfully. The protagonist, styled in contemporary business casual attire, confidently uses {product} against a backdrop of sleek urban architecture and lush greenery.",
"An indoor setup with soft natural light streaming through large windows. The protagonist, dressed in pastel-colored formal wear, interacts with {product} placed on a polished wooden table. Minimalistic decor enhances the scene's sophistication.",
"A cinematic close-up of {product}, placed elegantly on a textured surface. The backdrop features a blurred skyline with subtle movement, emphasizing depth. Vibrant colors like deep blues and gold highlight the product's premium appeal.",
"A playful outdoor park setting with children laughing and playing in the background. The protagonist, casually dressed in bright colors, uses {product} to solve a relatable problem. Flowers and greenery add to the cheerful mood.",
"A high-energy party scene with colorful lighting and dynamic camera angles. The protagonist, styled in trendy evening wear, showcases {product} as the center of attention. The vibrant environment reflects excitement and modernity."
]
# Additional predefined lists for dropdown menus
music_genres = [
"Classical", "Jazz", "Pop", "Rock", "Hip-Hop", "Electronic", "Ambient", "Folk", "Blues", "Reggae", "Country", "Latin", "R&B", "Soul", "Indie", "Dance", "World", "Acoustic", "Instrumental", "Orchestral", "Techno", "House", "Dubstep", "Lo-fi", "Chillwave"
]
ai_visual_styles = [
"Minimalistic", "Vibrant", "Monochromatic", "Surreal", "Photorealistic", "Vintage", "Futuristic", "Cartoonish", "Abstract", "Elegant", "Playful", "Rustic", "Bold", "Edgy", "Soft", "Whimsical", "Industrial", "Luxurious", "Dynamic", "Art Deco", "Flat Design", "3D Rendered", "Organic", "Textured", "High Contrast"
]
video_qualities = [
"720p", "1080p", "4K", "8K", "HDR", "SD", "High Frame Rate", "Cinematic", "Mobile Optimized", "Vertical Format", "Square Format", "Wide Format", "IMAX", "Low Light", "Studio Quality", "Dynamic Lighting", "Natural Lighting", "Experimental", "Stop Motion", "Timelapse", "Drone Shot", "Underwater", "Night Mode", "Portrait Mode", "Landscape Mode"
]
color_themes = [
"Warm Tones", "Cool Tones", "Neutral", "Pastel", "Bright and Bold", "Earthy", "Black and White", "Sepia", "Gradient", "Complementary", "Analogous", "Triadic", "Monochromatic", "Neon", "Muted", "Jewel Tones", "Desaturated", "Pop Art", "Futuristic Neon", "Sunset", "Forest", "Ocean", "Desert", "Urban", "Vintage Film"
]
camera_options = [
"Close-Up", "Wide Angle", "Medium Shot", "Over-the-Shoulder", "POV", "Tracking Shot", "Dolly Zoom", "Crane Shot", "Bird's Eye View", "Low Angle", "High Angle", "Handheld", "Steadicam", "Slow Motion", "Time-Lapse", "Zoom-In", "Zoom-Out", "Pan", "Tilt", "Rack Focus", "360 Shot", "Underwater Shot", "Aerial Shot", "Split Screen", "Reverse Motion"
]
# Function to generate detailed and unique video screenplay with AI-enhanced creativity
def generate_screenplay(client, product, brief, duration, frame_count, emotional_appeal, key_features, cta, location, music_genre, shot_type, visual_style, video_quality, color_theme, camera, additional_input):
try:
# Validate inputs
key_features = key_features if key_features else "highlighting its unique attributes"
duration = float(duration) if duration else 30
frame_count = int(frame_count) if frame_count else 10
# Divide total video duration by frame count to get approximate time per frame
duration_per_frame = duration / frame_count
screenplay = f"**Creative Strategy:** {client} - {product}\n\n"
screenplay += f"**Creative Brief:** {brief}\n\n"
screenplay += f"**Emotional Appeal:** {emotional_appeal}\n\n"
screenplay += f"**Call to Action:** {cta}\n\n"
screenplay += "**Video Screenplay Breakdown:**\n"
# Generate unique details for each frame
for i in range(1, frame_count + 1):
start_time = round((i - 1) * duration_per_frame, 2)
end_time = round(i * duration_per_frame, 2)
# Generate visuals using AI if OpenAI API key is available
visual_prompt = f"Generate a highly creative scene with {product} in {location}, focusing on {key_features}. Style: {visual_style}. Quality: {video_quality}. Colors: {color_theme}. Camera: {camera}."
try:
ai_visual = openai.Completion.create(
engine="text-davinci-003",
prompt=visual_prompt,
max_tokens=100
).choices[0].text.strip()
except Exception:
ai_visual = random.choice(visual_options).format(location=location, product=product)
screenplay += f"**Frame {i}:**\n"
screenplay += f"- **Time:** {start_time}s to {end_time}s\n"
screenplay += f"- **Visual:** {ai_visual}\n"
screenplay += f"- **Voiceover:** A tailored voiceover emphasizing {emotional_appeal} and {key_features}.\n"
screenplay += f"- **Music:** {music_genre} track to enhance the emotional appeal.\n"
screenplay += f"- **AI Prompt for Storyboard:** A vivid description of {product} in {visual_style} style, filmed with {camera}.\n\n"
screenplay += f"**Additional Input:** {additional_input}\n"
return screenplay
except Exception as e:
return f"Error: {e}"
# Gradio interface
iface = gr.Interface(
fn=generate_screenplay,
inputs=[
gr.Textbox(label="Client", placeholder="Enter the client's name (e.g., Elegant Shoes)"),
gr.Textbox(label="Product", placeholder="Enter the product name (e.g., Ladies High Heels)"),
gr.Textbox(label="Creative Brief", placeholder="Describe the creative brief (e.g., Elegance for working-class women)."),
gr.Textbox(label="Video Duration (in seconds)", placeholder="Enter the total video duration (e.g., 30)."),
gr.Textbox(label="Number of Frames", placeholder="Enter the number of storyboard frames (e.g., 10)."),
gr.Textbox(label="Emotional Appeal", placeholder="E.g., Elegance, Trust, Joy"),
gr.Textbox(label="Key Features", placeholder="Key product features (e.g., ergonomic design, durable material)."),
gr.Dropdown(label="Call to Action", choices=[
"Buy Now", "Sign Up Today", "Learn More", "Order Now", "Try for Free", "Discover More", "Subscribe Today", "Get Started", "Book Your Spot", "Contact Us", "Download Now", "Join Now", "Explore More", "Shop Now", "Request a Demo", "Get Your Free Sample", "Claim Your Offer", "Unlock Your Potential", "Start Your Journey", "Register Now", "Watch Now", "Apply Today", "Find Out More", "Upgrade Now", "Get Access"
]),
gr.Textbox(label="Location", placeholder="E.g., Urban park, Cozy living room"),
gr.Dropdown(label="Music Genre", choices=music_genres),
gr.Dropdown(label="Shot Type", choices=camera_options),
gr.Dropdown(label="AI Visual Style", choices=ai_visual_styles),
gr.Dropdown(label="Video Quality", choices=video_qualities),
gr.Dropdown(label="Color Theme", choices=color_themes),
gr.Dropdown(label="Camera", choices=camera_options),
gr.Textbox(label="Additional Input", placeholder="Any other specifics or instructions."),
],
outputs=gr.Textbox(label="Generated Screenplay")
)
iface.launch()