Download app.py from hhh454/111: direct link, hf CLI and curl.
- Browser
- Download file 2.45 kB
-
https://huggingface.co/spaces/hhh454/111/resolve/main/app.py
- Command line
-
hf download hf://spaces/hhh454/111/app.py
-
curl -L -o app.py https://huggingface.co/spaces/hhh454/111/resolve/main/app.py
2.45 kB
| 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() |