File size: 6,113 Bytes
c4375ed d57b3ca c4375ed d57b3ca c4375ed d57b3ca c4375ed f257ee8 c4375ed f257ee8 c4375ed d57b3ca c4375ed d57b3ca c4375ed d57b3ca c4375ed d57b3ca c4375ed d57b3ca c4375ed d57b3ca c4375ed d57b3ca c4375ed |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 |
#@title π¬ AI Film Studio Pro (Advanced Watermark + Analytics)
import gradio as gr
import numpy as np
import random
from diffusers import DiffusionPipeline
from PIL import Image, ImageDraw, ImageFont
import base64
# ===== CONFIG =====
SUPPORTERS = random.randint(50, 200)
KO_FI_LINK = "https://ko-fi.com/fecolywill"
GA_TRACKING_ID = "G-XXXXXXXXXX" # Replace with your Google Analytics ID
# In your Watermarker class:
class Watermarker:
def __init__(self):
try:
# Try loading default font first
self.font = ImageFont.load_default().font_variant(size=24)
except:
# Fallback to basic font
self.font = ImageFont.load_default()
self.color = (255, 255, 255, 128)
self.position = "bottom-right"
self.text = "Made with AI Film Studio"
def apply(self, frames):
watermarked_frames = []
for frame in frames:
img = Image.fromarray(frame)
draw = ImageDraw.Draw(img, "RGBA")
if self.position == "bottom-right":
x = img.width - draw.textlength(self.text, self.font) - 20
y = img.height - 30
elif self.position == "top-left":
x, y = 20, 20
else: # center
x = (img.width - draw.textlength(self.text, self.font)) // 2
y = (img.height - 30) // 2
draw.text((x, y), self.text, fill=self.color, font=self.font)
if self.logo:
logo_img = Image.open(self.logo).resize((50, 50))
img.paste(logo_img, (x-60, y-5), logo_img)
watermarked_frames.append(np.array(img))
return np.stack(watermarked_frames)
watermarker = Watermarker()
# ===== VIDEO GENERATION =====
def generate_video(prompt):
pipe = DiffusionPipeline.from_pretrained("cerspense/zeroscope_v2_576w")
frames = pipe(prompt, num_frames=24).frames
return watermarker.apply(frames), 12 # (watermarked_frames, fps)
# ===== ENHANCED ANALYTICS =====
analytics_js = f"""
<script async src="https://www.googletagmanager.com/gtag/js?id={GA_TRACKING_ID}"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){{dataLayer.push(arguments);}}
gtag('js', new Date());
// Enhanced tracking
gtag('config', '{GA_TRACKING_ID}', {{
'page_title': 'AI Film Studio',
'page_location': location.href
}});
function trackAction(type, label) {{
gtag('event', 'user_action', {{
'event_category': type,
'event_label': label,
'value': 1
}});
}}
</script>
"""
# ===== SUPPORT SECTION =====
support_html = f"""
<div style="border-top:1px solid #e6e6e6; padding:25px; text-align:center; margin-top:30px; background:#f9f9f9; border-radius:8px;">
<h3 style="margin-bottom:10px;">β€οΈ Support This Project</h3>
<p style="margin-bottom:15px;">Enjoying this free tool? Help me add more features!</p>
<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;">
β Buy Me a Coffee
</a>
<p style="color:#666; font-size:0.9em;">π {SUPPORTERS}+ creators have supported!</p>
</div>
"""
# ===== MAIN APP =====
with gr.Blocks(theme=gr.themes.Soft(), title="AI Film Studio Pro") as app:
# Google Analytics
gr.HTML(analytics_js)
# Header
gr.Markdown("# π¬ AI Film Studio Pro")
gr.Markdown("Generate **watermarked videos** with professional tracking!")
# Video Generation UI
with gr.Tab("π₯ Video Creator"):
with gr.Row():
prompt = gr.Textbox(label="Describe Your Scene",
placeholder="A spaceship lands in medieval times...")
style = gr.Dropdown(["Cinematic", "Anime", "Cyberpunk"], label="Style")
generate_btn = gr.Button("Generate Video", variant="primary")
# Video with enhanced download tracking
video = gr.Video(
label="Your Video",
show_download_button=True,
interactive=False
)
# Download tracking with quality selection
download_js = """
<script>
document.querySelector('button[aria-label="Download"]').addEventListener('click', () => {
trackAction('download', 'video_mp4');
alert('Video downloaded! Consider supporting to unlock HD versions π');
});
</script>
"""
gr.HTML(download_js)
# Watermark Customization (Advanced)
with gr.Accordion("βοΈ Watermark Settings", open=False):
watermark_text = gr.Textbox(label="Watermark Text", value="Made with AI Film Studio")
watermark_color = gr.ColorPicker(label="Color", value="#ffffff")
watermark_opacity = gr.Slider(0, 100, value=50, label="Opacity (%)")
watermark_position = gr.Dropdown(["bottom-right", "top-left", "center"], label="Position")
def update_watermark(text, color, opacity, position):
r, g, b = tuple(int(color.lstrip('#')[i:i+2], 16) for i in (0, 2, 4))
watermarker.text = text
watermarker.color = (r, g, b, int(255 * (opacity/100)))
watermarker.position = position
return "Watermark settings updated!"
update_btn = gr.Button("Update Watermark")
update_btn.click(
fn=update_watermark,
inputs=[watermark_text, watermark_color, watermark_opacity, watermark_position],
outputs=gr.Textbox(visible=False)
)
# Support Footer
gr.HTML(support_html)
# Generation function
generate_btn.click(
fn=generate_video,
inputs=[prompt],
outputs=video
).then(
lambda: trackAction("generation", "video_created"), # Track successful generations
outputs=None
)
# ===== DEPLOYMENT =====
if __name__ == "__main__":
app.launch(debug=True) |