File size: 6,247 Bytes
abd853d
d57b3ca
c4375ed
abd853d
d57b3ca
c4375ed
 
d57b3ca
c4375ed
 
 
 
abd853d
 
c4375ed
 
abd853d
 
f257ee8
c4375ed
abd853d
c4375ed
 
 
 
 
abd853d
c4375ed
 
abd853d
c4375ed
 
 
 
abd853d
c4375ed
 
 
 
 
 
 
 
 
 
abd853d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
370acad
c4375ed
abd853d
c4375ed
 
 
 
 
 
abd853d
c4375ed
abd853d
 
 
c4375ed
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
abd853d
d57b3ca
c4375ed
 
 
abd853d
 
 
 
 
 
 
 
 
 
c4375ed
abd853d
c4375ed
abd853d
c4375ed
abd853d
c4375ed
 
 
 
abd853d
c4375ed
 
 
 
 
 
 
 
 
d57b3ca
abd853d
c4375ed
abd853d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
c4375ed
 
 
 
 
 
 
 
 
 
 
 
 
 
d57b3ca
c4375ed
 
d57b3ca
c4375ed
d57b3ca
c4375ed
 
 
 
abd853d
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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
#@title 🎬 AI Film Studio Pro (Complete Working Version)
import gradio as gr
import numpy as np
import torch
import random
from diffusers import DiffusionPipeline
from PIL import Image, ImageDraw, ImageFont

# ===== 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

# ===== WATERMARKER =====
class Watermarker:
    def __init__(self):
        self.font = ImageFont.load_default()
        self.color = (255, 255, 255, 128)  # White with 50% opacity
        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")
            text_width = draw.textlength(self.text, font=self.font)
            
            if self.position == "bottom-right":
                x = img.width - text_width - 20
                y = img.height - 30
            elif self.position == "top-left":
                x, y = 20, 20
            else:  # center
                x = (img.width - text_width) // 2
                y = (img.height - 30) // 2
                
            draw.text((x, y), self.text, fill=self.color, font=self.font)
            watermarked_frames.append(np.array(img))
        return np.stack(watermarked_frames)

watermarker = Watermarker()

# ===== VIDEO GENERATION =====
def generate_video(prompt):
    # Initialize pipeline (cached after first run)
    pipe = DiffusionPipeline.from_pretrained(
        "cerspense/zeroscope_v2_576w",
        torch_dtype=torch.float16
    )
    
    # Generate frames (24 frames at 576x320)
    frames = pipe(
        prompt,
        num_frames=24,
        height=320,
        width=576
    ).frames
    
    # Apply watermark and return as numpy array
    return (np.stack(watermarker.apply(frames))), 12  # (frames, fps)

# ===== 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());
  gtag('config', '{GA_TRACKING_ID}');
  
  function trackAction(action, label) {{
    gtag('event', action, {{
      'event_category': 'engagement',
      '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 professional videos with AI - **no experience needed!**")
    
    # Video Generation UI
    with gr.Tab("πŸŽ₯ Video Creator"):
        with gr.Row():
            prompt = gr.Textbox(
                label="Describe Your Scene",
                placeholder="A cyberpunk detective chases an android through neon streets...",
                lines=3
            )
            style = gr.Dropdown(
                ["Cinematic", "Anime", "Noir", "Cyberpunk"],
                label="Visual Style",
                value="Cinematic"
            )
        
        generate_btn = gr.Button("✨ Generate Video", variant="primary")
        
        # Video output with download tracking
        video = gr.Video(
            label="Your Generated Video",
            show_download_button=True,
            interactive=False
        )
        
        # Download tracking
        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
    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",
            value="bottom-right"
        )
        
        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: gr.HTML("<script>trackAction('generation', 'video_created')</script>"),
        outputs=None
    )

# ===== DEPLOYMENT =====
if __name__ == "__main__":
    app.launch(debug=True)