Spaces:
No application file
No application file
Update streamlit_app.py
Browse files- streamlit_app.py +39 -11
streamlit_app.py
CHANGED
|
@@ -1,16 +1,44 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
import google.genai as genai
|
|
|
|
| 3 |
|
| 4 |
-
|
| 5 |
-
genai.configure(api_key="YOUR_API_KEY")
|
| 6 |
|
| 7 |
-
|
|
|
|
| 8 |
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
import google.genai as genai
|
| 3 |
+
import os
|
| 4 |
|
| 5 |
+
st.title("🎬 Veo 3 Video Generator (Manual API Key)")
|
|
|
|
| 6 |
|
| 7 |
+
# Input manual API Key (pakai password type, biar tidak terlihat jelas)
|
| 8 |
+
API_KEY = st.text_input("Masukkan GENAI API Key:", type="password")
|
| 9 |
|
| 10 |
+
if not API_KEY:
|
| 11 |
+
st.warning("⚠️ Silakan masukkan API key anda.")
|
| 12 |
+
else:
|
| 13 |
+
# Buat client dengan API Key yang diberikan user
|
| 14 |
+
try:
|
| 15 |
+
client = genai.Client(api_key=API_KEY)
|
| 16 |
+
|
| 17 |
+
# Prompt dari user
|
| 18 |
+
prompt = st.text_area("Masukkan prompt video:", "Flying cats in outer space, cinematic")
|
| 19 |
+
|
| 20 |
+
# Pilih jenis video
|
| 21 |
+
video_type = st.radio("Jenis video:", ["Pendek", "Panjang"], horizontal=True)
|
| 22 |
+
|
| 23 |
+
if st.button("🎥 Generate Video"):
|
| 24 |
+
with st.spinner("Sedang generate video..."):
|
| 25 |
+
try:
|
| 26 |
+
# ⚠️ Method bisa beda tergantung versi SDK
|
| 27 |
+
if video_type == "Pendek":
|
| 28 |
+
video = client.generate.video(model="veo-3", prompt=prompt, duration="short")
|
| 29 |
+
else:
|
| 30 |
+
video = client.generate.video(model="veo-3", prompt=prompt, duration="long")
|
| 31 |
+
|
| 32 |
+
# Simpan hasil video
|
| 33 |
+
output_path = "output.mp4"
|
| 34 |
+
with open(output_path, "wb") as f:
|
| 35 |
+
f.write(video)
|
| 36 |
+
|
| 37 |
+
st.success("✅ Video berhasil dibuat!")
|
| 38 |
+
st.video(output_path)
|
| 39 |
+
|
| 40 |
+
except Exception as e:
|
| 41 |
+
st.error(f"❌ Error saat generate video: {e}")
|
| 42 |
+
st.warning("⚠️ Pastikan API key dan endpoint masih valid.")
|
| 43 |
+
except Exception as e:
|
| 44 |
+
st.error(f"❌ API Key tidak valid: {e}")
|