import gradio as gr from gtts import gTTS import requests import os # سكريبت حسب الاستايل def generate_script(idea, style): if style == "Horror": return f"A dark horror story about {idea}. Something is watching you. The silence is not safe. Fear is everywhere." elif style == "Sci-Fi": return f"A sci-fi story about {idea}. Reality is breaking. Technology controls everything. Nothing is real anymore." else: return f"A story about {idea}. A journey begins. Everything starts to change. Unexpected things happen." # تقسيم def split_script(script): return [s.strip() for s in script.split(".") if s.strip()] def generate_video(idea, duration_minutes, style): # تحويل الدقائق إلى ثواني duration = int(duration_minutes * 60) script = generate_script(idea, style) sentences = split_script(script) clips = [] # توزيع الوقت على المشاهد scene_time = max(3, duration // len(sentences)) for i, sentence in enumerate(sentences): # صورة img_url = f"https://picsum.photos/1280/720?random={i}" img_data = requests.get(img_url).content img_file = f"img_{i}.jpg" with open(img_file, "wb") as f: f.write(img_data) # صوت audio_file = f"audio_{i}.mp3" tts = gTTS(sentence) tts.save(audio_file) # FFmpeg فيديو المشهد output_file = f"scene_{i}.mp4" os.system(f""" ffmpeg -y -loop 1 -i {img_file} -i {audio_file} \ -c:v libx264 -t {scene_time} -c:a aac \ -pix_fmt yuv420p -shortest {output_file} """) clips.append(output_file) # دمج الفيديوهات with open("list.txt", "w") as f: for c in clips: f.write(f"file '{c}'\n") os.system("ffmpeg -y -f concat -safe 0 -i list.txt -c copy output.mp4") return script, "output.mp4" demo = gr.Interface( fn=generate_video, inputs=[ gr.Textbox(label="💡 فكرة الفيديو"), gr.Slider(0.1, 10, value=1, label="⏱️ مدة الفيديو (بالدقائق)"), gr.Dropdown(["Horror", "Sci-Fi", "Normal"], label="🎨 الاستايل") ], outputs=[ gr.Textbox(label="📜 السكريبت"), gr.Video(label="🎬 الفيديو النهائي") ], title="🔥 AI Video Generator V3" ) demo.launch()