Spaces:
Configuration error
Configuration error
Update src/streamlit_app.py
Browse files- src/streamlit_app.py +63 -48
src/streamlit_app.py
CHANGED
|
@@ -1,52 +1,67 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
-
import
|
| 3 |
import os
|
| 4 |
|
| 5 |
-
# Konfigurasi
|
| 6 |
-
st.set_page_config(page_title="Video
|
| 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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
+
from huggingface_hub import InferenceClient
|
| 3 |
import os
|
| 4 |
|
| 5 |
+
# Konfigurasi Halaman
|
| 6 |
+
st.set_page_config(page_title="AI Video Scene Architect", page_icon="π¬", layout="wide")
|
| 7 |
+
|
| 8 |
+
st.title("π¬ AI Video Scene Architect")
|
| 9 |
+
|
| 10 |
+
# Ambil token dari Secrets (HF_TOKEN)
|
| 11 |
+
hf_token = os.environ.get("HF_TOKEN")
|
| 12 |
+
|
| 13 |
+
with st.sidebar:
|
| 14 |
+
st.header("βοΈ Pengaturan")
|
| 15 |
+
if not hf_token:
|
| 16 |
+
hf_token = st.text_input("Masukkan Hugging Face Token", type="password")
|
| 17 |
+
st.caption("Dapatkan di: huggingface.co/settings/tokens")
|
| 18 |
+
|
| 19 |
+
num_scenes = st.slider("Jumlah Scene", 1, 20, 5)
|
| 20 |
+
|
| 21 |
+
aspect_ratio = st.selectbox(
|
| 22 |
+
"Ukuran Video (Aspect Ratio)",
|
| 23 |
+
["16:9", "9:16", "2:3", "4:5"]
|
| 24 |
+
)
|
| 25 |
+
|
| 26 |
+
style = st.selectbox("Gaya Visual", ["Cinematic", "Realistic Photography", "Anime Style", "3D Animation"])
|
| 27 |
+
|
| 28 |
+
# Input User
|
| 29 |
+
col1, col2 = st.columns(2)
|
| 30 |
+
with col1:
|
| 31 |
+
idea = st.text_area("Ide Utama Video", placeholder="Contoh: Astronot memasak di bulan...", height=120)
|
| 32 |
+
with col2:
|
| 33 |
+
details = st.text_area("Detail Visual", placeholder="Pencahayaan dramatis, warna cerah...", height=120)
|
| 34 |
+
|
| 35 |
+
if st.button("π Generate Sequence Prompts"):
|
| 36 |
+
if not hf_token:
|
| 37 |
+
st.error("β Token tidak ditemukan! Isi di sidebar atau Settings > Secrets.")
|
| 38 |
+
elif not idea:
|
| 39 |
+
st.warning("β οΈ Silakan tulis ide video Anda.")
|
| 40 |
+
else:
|
| 41 |
+
with st.spinner("Menghubungi AI melalui Router Baru..."):
|
| 42 |
+
try:
|
| 43 |
+
# Inisialisasi Client (Otomatis menangani routing & error 410)
|
| 44 |
+
client = InferenceClient(
|
| 45 |
+
model="mistralai/Mistral-7B-Instruct-v0.3",
|
| 46 |
+
token=hf_token
|
| 47 |
+
)
|
| 48 |
+
|
| 49 |
+
# Format Prompt
|
| 50 |
+
system_instruction = f"Create {num_scenes} sequential video prompts for: {idea}. Details: {details}. Style: {style}. Ratio: {aspect_ratio}. Duration: 5s per scene. Format: Scene [X] (5s): [Description]"
|
| 51 |
|
| 52 |
+
# Memanggil AI
|
| 53 |
+
response = ""
|
| 54 |
+
for message in client.chat_completion(
|
| 55 |
+
messages=[{"role": "user", "content": system_instruction}],
|
| 56 |
+
max_tokens=2000,
|
| 57 |
+
stream=True,
|
| 58 |
+
):
|
| 59 |
+
response += message.choices[0].delta.content
|
| 60 |
+
|
| 61 |
+
st.success("β
Rangkaian Scene Berhasil Dibuat!")
|
| 62 |
+
st.markdown("---")
|
| 63 |
+
st.write(response)
|
| 64 |
+
|
| 65 |
+
except Exception as e:
|
| 66 |
+
st.error(f"β Terjadi kesalahan: {e}")
|
| 67 |
+
st.info("Jika error 503, tunggu 1 menit lalu klik Generate lagi karena model sedang 'warming up'.")
|