Spaces:
No application file
No application file
| import streamlit as st | |
| import google.generativeai as genai | |
| import os | |
| # ============================ | |
| # 1. Konfigurasi API Key | |
| # ============================ | |
| API_KEY = os.getenv("GOOGLE_API_KEY") # ambil API Key dari Secrets di Settings | |
| if API_KEY: | |
| genai.configure(api_key=API_KEY) | |
| else: | |
| st.warning("⚠️ GOOGLE_API_KEY belum diset di Repository Secrets pada Hugging Face.") | |
| # ============================ | |
| # 2. UI Streamlit | |
| # ============================ | |
| st.set_page_config(page_title="Veo‑3 Video Generator 🎬") | |
| st.title("🎬 Veo‑3 Video Generator") | |
| st.write("Masukkan deskripsi, lalu tekan tombol untuk menghasilkan video dengan model **Veo‑3**.") | |
| prompt = st.text_area( | |
| "Masukkan deskripsi video:", | |
| "Seekor naga terbang melintasi langit malam penuh bintang dengan gaya sinematik" | |
| ) | |
| duration = st.slider("Durasi video (detik)", 2, 10, 4) | |
| if st.button("🚀 Generate Video"): | |
| if not API_KEY: | |
| st.error("❌ GOOGLE_API_KEY belum diatur. Silakan tambah di Settings → Secrets.") | |
| else: | |
| with st.spinner("Sedang memanggil API Veo‑3..."): | |
| try: | |
| # ============================ | |
| # 3. Panggilan API Veo‑3 | |
| # ============================ | |
| response = genai.generate_video( | |
| model="veo-3", # gunakan model Veo‑3 | |
| prompt=prompt, | |
| duration=duration | |
| ) | |
| # Ambil URI video dari hasil respons | |
| video_url = response.video.uri | |
| # ============================ | |
| # 4. Tampilkan hasil | |
| # ============================ | |
| st.video(video_url) | |
| st.success("✅ Video berhasil dibuat dengan Veo‑3!") | |
| except Exception as e: | |
| st.error(f"Terjadi error saat memanggil API: {e}") |