Update app.py
Browse files
app.py
CHANGED
@@ -1,76 +1,163 @@
|
|
1 |
-
#@title π¬ AI
|
2 |
import gradio as gr
|
|
|
3 |
import random
|
|
|
|
|
|
|
4 |
|
5 |
-
# =====
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
"romance": f"A {random.choice(['barista', 'writer', 'robot'])} and {random.choice(['artist', 'detective', 'alien'])} discover {random.choice(['love', 'a secret'])} in {random.choice(['Tokyo', 'a virtual world'])}.",
|
19 |
-
"horror": f"A {random.choice(['streamer', 'programmer', 'student'])} uncovers {random.choice(['a dark web secret', 'haunted code'])} that {random.choice(['follows them', 'changes reality'])}."
|
20 |
-
}
|
21 |
-
logline = loglines.get(genre, "A story about the unthinkable.")
|
22 |
-
|
23 |
-
# Generate style mashup
|
24 |
-
styles = {
|
25 |
-
"sci-fi": "Blade Runner meets Black Mirror",
|
26 |
-
"romance": "Before Sunrise meets Her",
|
27 |
-
"horror": "The Ring meets Ex Machina"
|
28 |
-
}
|
29 |
-
style_mashup = styles.get(genre, "Cinematic masterpiece")
|
30 |
-
|
31 |
-
# Generate scene breakdown
|
32 |
-
scenes = {
|
33 |
-
"sci-fi": ["Opening: Cybercity flyover", "Act 1: Hack sequence", "Act 2: AI reveal", "Climax: System crash"],
|
34 |
-
"romance": ["Meet-cute: Rainy cafΓ©", "First kiss: Rooftop sunset", "Conflict: Missed connection", "End: Reunion at train station"],
|
35 |
-
"horror": ["Creepy livestream", "First death glitch", "Investigation gone wrong", "Twist ending"]
|
36 |
-
}
|
37 |
-
scene_breakdown = "\n".join(scenes.get(genre, ["Scene 1: Intriguing setup"]))
|
38 |
-
|
39 |
-
# AI tool recommendations
|
40 |
-
tools = {
|
41 |
-
"sci-fi": "Veo3 (for CGI), Runway (for cyber effects)",
|
42 |
-
"romance": "Pika (for soft lighting), Kling (for dialogue)",
|
43 |
-
"horror": "Stable Diffusion (for creepy imagery), D-ID (for unsettling faces)"
|
44 |
-
}
|
45 |
-
|
46 |
-
return f"""
|
47 |
-
π₯ **{title}**
|
48 |
-
π *{logline}*
|
49 |
-
π¨ **Style**: {style_mashup} with {vibe} vibes
|
50 |
-
ποΈ **Key Scenes**:
|
51 |
-
{scene_breakdown}
|
52 |
-
π€ **Best AI Tools**: {tools.get(genre, "Veo3 + Runway")}
|
53 |
-
"""
|
54 |
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
59 |
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
64 |
|
65 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
66 |
|
67 |
-
|
|
|
68 |
|
|
|
69 |
generate_btn.click(
|
70 |
-
fn=
|
71 |
-
inputs=[
|
72 |
-
outputs=
|
|
|
|
|
|
|
73 |
)
|
74 |
|
75 |
-
# =====
|
76 |
-
|
|
|
|
1 |
+
#@title π¬ AI Film Studio Pro (Advanced Watermark + Analytics)
|
2 |
import gradio as gr
|
3 |
+
import numpy as np
|
4 |
import random
|
5 |
+
from diffusers import DiffusionPipeline
|
6 |
+
from PIL import Image, ImageDraw, ImageFont
|
7 |
+
import base64
|
8 |
|
9 |
+
# ===== CONFIG =====
|
10 |
+
SUPPORTERS = random.randint(50, 200)
|
11 |
+
KO_FI_LINK = "https://ko-fi.com/fecolywill"
|
12 |
+
GA_TRACKING_ID = "G-XXXXXXXXXX" # Replace with your Google Analytics ID
|
13 |
+
|
14 |
+
# ===== CUSTOM WATERMARK =====
|
15 |
+
class Watermarker:
|
16 |
+
def __init__(self):
|
17 |
+
self.font = ImageFont.truetype("arial.ttf", 24) # Larger font
|
18 |
+
self.color = (255, 255, 255, 128) # Semi-transparent white
|
19 |
+
self.position = "bottom-right" # Options: bottom-right, top-left, center
|
20 |
+
self.text = "Made with AI Film Studio"
|
21 |
+
self.logo = None # Set path to logo image if desired
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
22 |
|
23 |
+
def apply(self, frames):
|
24 |
+
watermarked_frames = []
|
25 |
+
for frame in frames:
|
26 |
+
img = Image.fromarray(frame)
|
27 |
+
draw = ImageDraw.Draw(img, "RGBA")
|
28 |
+
|
29 |
+
if self.position == "bottom-right":
|
30 |
+
x = img.width - draw.textlength(self.text, self.font) - 20
|
31 |
+
y = img.height - 30
|
32 |
+
elif self.position == "top-left":
|
33 |
+
x, y = 20, 20
|
34 |
+
else: # center
|
35 |
+
x = (img.width - draw.textlength(self.text, self.font)) // 2
|
36 |
+
y = (img.height - 30) // 2
|
37 |
+
|
38 |
+
draw.text((x, y), self.text, fill=self.color, font=self.font)
|
39 |
+
|
40 |
+
if self.logo:
|
41 |
+
logo_img = Image.open(self.logo).resize((50, 50))
|
42 |
+
img.paste(logo_img, (x-60, y-5), logo_img)
|
43 |
+
|
44 |
+
watermarked_frames.append(np.array(img))
|
45 |
+
return np.stack(watermarked_frames)
|
46 |
+
|
47 |
+
watermarker = Watermarker()
|
48 |
+
|
49 |
+
# ===== VIDEO GENERATION =====
|
50 |
+
def generate_video(prompt):
|
51 |
+
pipe = DiffusionPipeline.from_pretrained("cerspense/zeroscope_v2_576w")
|
52 |
+
frames = pipe(prompt, num_frames=24).frames
|
53 |
+
return watermarker.apply(frames), 12 # (watermarked_frames, fps)
|
54 |
+
|
55 |
+
# ===== ENHANCED ANALYTICS =====
|
56 |
+
analytics_js = f"""
|
57 |
+
<script async src="https://www.googletagmanager.com/gtag/js?id={GA_TRACKING_ID}"></script>
|
58 |
+
<script>
|
59 |
+
window.dataLayer = window.dataLayer || [];
|
60 |
+
function gtag(){{dataLayer.push(arguments);}}
|
61 |
+
gtag('js', new Date());
|
62 |
+
|
63 |
+
// Enhanced tracking
|
64 |
+
gtag('config', '{GA_TRACKING_ID}', {{
|
65 |
+
'page_title': 'AI Film Studio',
|
66 |
+
'page_location': location.href
|
67 |
+
}});
|
68 |
+
|
69 |
+
function trackAction(type, label) {{
|
70 |
+
gtag('event', 'user_action', {{
|
71 |
+
'event_category': type,
|
72 |
+
'event_label': label,
|
73 |
+
'value': 1
|
74 |
+
}});
|
75 |
+
}}
|
76 |
+
</script>
|
77 |
+
"""
|
78 |
+
|
79 |
+
# ===== SUPPORT SECTION =====
|
80 |
+
support_html = f"""
|
81 |
+
<div style="border-top:1px solid #e6e6e6; padding:25px; text-align:center; margin-top:30px; background:#f9f9f9; border-radius:8px;">
|
82 |
+
<h3 style="margin-bottom:10px;">β€οΈ Support This Project</h3>
|
83 |
+
<p style="margin-bottom:15px;">Enjoying this free tool? Help me add more features!</p>
|
84 |
+
<a href="{KO_FI_LINK}" target="_blank" onclick="trackAction('support', 'kofi_click')" style="padding:10px 20px; background:#29abe0; color:white; border-radius:5px; text-decoration:none; font-weight:bold; display:inline-block; margin-bottom:15px;">
|
85 |
+
β Buy Me a Coffee
|
86 |
+
</a>
|
87 |
+
<p style="color:#666; font-size:0.9em;">π {SUPPORTERS}+ creators have supported!</p>
|
88 |
+
</div>
|
89 |
+
"""
|
90 |
+
|
91 |
+
# ===== MAIN APP =====
|
92 |
+
with gr.Blocks(theme=gr.themes.Soft(), title="AI Film Studio Pro") as app:
|
93 |
+
# Google Analytics
|
94 |
+
gr.HTML(analytics_js)
|
95 |
+
|
96 |
+
# Header
|
97 |
+
gr.Markdown("# π¬ AI Film Studio Pro")
|
98 |
+
gr.Markdown("Generate **watermarked videos** with professional tracking!")
|
99 |
|
100 |
+
# Video Generation UI
|
101 |
+
with gr.Tab("π₯ Video Creator"):
|
102 |
+
with gr.Row():
|
103 |
+
prompt = gr.Textbox(label="Describe Your Scene",
|
104 |
+
placeholder="A spaceship lands in medieval times...")
|
105 |
+
style = gr.Dropdown(["Cinematic", "Anime", "Cyberpunk"], label="Style")
|
106 |
+
|
107 |
+
generate_btn = gr.Button("Generate Video", variant="primary")
|
108 |
+
|
109 |
+
# Video with enhanced download tracking
|
110 |
+
video = gr.Video(
|
111 |
+
label="Your Video",
|
112 |
+
show_download_button=True,
|
113 |
+
interactive=False
|
114 |
+
)
|
115 |
+
|
116 |
+
# Download tracking with quality selection
|
117 |
+
download_js = """
|
118 |
+
<script>
|
119 |
+
document.querySelector('button[aria-label="Download"]').addEventListener('click', () => {
|
120 |
+
trackAction('download', 'video_mp4');
|
121 |
+
alert('Video downloaded! Consider supporting to unlock HD versions π');
|
122 |
+
});
|
123 |
+
</script>
|
124 |
+
"""
|
125 |
+
gr.HTML(download_js)
|
126 |
|
127 |
+
# Watermark Customization (Advanced)
|
128 |
+
with gr.Accordion("βοΈ Watermark Settings", open=False):
|
129 |
+
watermark_text = gr.Textbox(label="Watermark Text", value="Made with AI Film Studio")
|
130 |
+
watermark_color = gr.ColorPicker(label="Color", value="#ffffff")
|
131 |
+
watermark_opacity = gr.Slider(0, 100, value=50, label="Opacity (%)")
|
132 |
+
watermark_position = gr.Dropdown(["bottom-right", "top-left", "center"], label="Position")
|
133 |
+
|
134 |
+
def update_watermark(text, color, opacity, position):
|
135 |
+
r, g, b = tuple(int(color.lstrip('#')[i:i+2], 16) for i in (0, 2, 4))
|
136 |
+
watermarker.text = text
|
137 |
+
watermarker.color = (r, g, b, int(255 * (opacity/100)))
|
138 |
+
watermarker.position = position
|
139 |
+
return "Watermark settings updated!"
|
140 |
+
|
141 |
+
update_btn = gr.Button("Update Watermark")
|
142 |
+
update_btn.click(
|
143 |
+
fn=update_watermark,
|
144 |
+
inputs=[watermark_text, watermark_color, watermark_opacity, watermark_position],
|
145 |
+
outputs=gr.Textbox(visible=False)
|
146 |
+
)
|
147 |
|
148 |
+
# Support Footer
|
149 |
+
gr.HTML(support_html)
|
150 |
|
151 |
+
# Generation function
|
152 |
generate_btn.click(
|
153 |
+
fn=generate_video,
|
154 |
+
inputs=[prompt],
|
155 |
+
outputs=video
|
156 |
+
).then(
|
157 |
+
lambda: trackAction("generation", "video_created"), # Track successful generations
|
158 |
+
outputs=None
|
159 |
)
|
160 |
|
161 |
+
# ===== DEPLOYMENT =====
|
162 |
+
if __name__ == "__main__":
|
163 |
+
app.launch(debug=True)
|