Spaces:
Configuration error
Configuration error
Update src/streamlit_app.py
Browse files- src/streamlit_app.py +52 -55
src/streamlit_app.py
CHANGED
|
@@ -9,80 +9,77 @@ Original file is located at
|
|
| 9 |
|
| 10 |
import streamlit as st
|
| 11 |
import requests
|
| 12 |
-
import
|
| 13 |
|
| 14 |
# Konfigurasi Halaman
|
| 15 |
-
st.set_page_config(page_title="AI Scene Director", page_icon="π¬", layout="wide")
|
| 16 |
|
| 17 |
-
#
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
|
|
|
|
|
|
| 21 |
|
| 22 |
-
def query_ai(prompt):
|
|
|
|
| 23 |
payload = {
|
| 24 |
"inputs": prompt,
|
| 25 |
-
"parameters": {"max_new_tokens":
|
| 26 |
}
|
| 27 |
-
response = requests.post(
|
| 28 |
-
return response
|
| 29 |
|
| 30 |
# --- UI INTERFACE ---
|
| 31 |
st.title("π¬ AI Video Scene Architect")
|
| 32 |
-
|
|
|
|
|
|
|
| 33 |
|
| 34 |
with st.sidebar:
|
| 35 |
st.header("Konfigurasi")
|
| 36 |
-
|
|
|
|
|
|
|
|
|
|
| 37 |
num_scenes = st.slider("Jumlah Scene", 1, 20, 5)
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
if hf_token:
|
| 41 |
-
headers["Authorization"] = f"Bearer {hf_token}"
|
| 42 |
|
| 43 |
# Input User
|
| 44 |
col1, col2 = st.columns(2)
|
| 45 |
with col1:
|
| 46 |
-
idea = st.text_area("Ide Utama Video", "
|
| 47 |
with col2:
|
| 48 |
-
details = st.text_area("Detail Visual
|
| 49 |
|
| 50 |
if st.button("π Generate Sequence Prompts"):
|
| 51 |
if not hf_token:
|
| 52 |
-
st.error("
|
| 53 |
-
elif idea:
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
scenes_raw = clean_output.split("Scene")
|
| 82 |
-
for s in scenes_raw:
|
| 83 |
-
if s.strip():
|
| 84 |
-
with st.container():
|
| 85 |
-
st.info(f"π¬ Scene {s.strip()}")
|
| 86 |
-
st.button(f"Copy Scene", key=s[:20])
|
| 87 |
-
else:
|
| 88 |
-
st.error("Gagal menghubungi AI. Pastikan Token benar atau coba lagi nanti.")
|
|
|
|
| 9 |
|
| 10 |
import streamlit as st
|
| 11 |
import requests
|
| 12 |
+
import os
|
| 13 |
|
| 14 |
# Konfigurasi Halaman
|
| 15 |
+
st.set_page_config(page_title="AI Video Scene Director", page_icon="π¬", layout="wide")
|
| 16 |
|
| 17 |
+
# Daftar Model AI (Urutan dari yang paling pintar)
|
| 18 |
+
MODELS = [
|
| 19 |
+
"meta-llama/Meta-Llama-3-8B-Instruct",
|
| 20 |
+
"mistralai/Mistral-7B-Instruct-v0.2",
|
| 21 |
+
"HuggingFaceH4/zephyr-7b-beta"
|
| 22 |
+
]
|
| 23 |
|
| 24 |
+
def query_ai(prompt, model_url, token):
|
| 25 |
+
headers = {"Authorization": f"Bearer {token}"}
|
| 26 |
payload = {
|
| 27 |
"inputs": prompt,
|
| 28 |
+
"parameters": {"max_new_tokens": 1500, "temperature": 0.7, "return_full_text": False}
|
| 29 |
}
|
| 30 |
+
response = requests.post(f"https://api-inference.huggingface.co/models/{model_url}", headers=headers, json=payload)
|
| 31 |
+
return response
|
| 32 |
|
| 33 |
# --- UI INTERFACE ---
|
| 34 |
st.title("π¬ AI Video Scene Architect")
|
| 35 |
+
|
| 36 |
+
# Ambil token dari Secrets atau Sidebar
|
| 37 |
+
hf_token = os.environ.get("HF_TOKEN")
|
| 38 |
|
| 39 |
with st.sidebar:
|
| 40 |
st.header("Konfigurasi")
|
| 41 |
+
if not hf_token:
|
| 42 |
+
hf_token = st.text_input("Masukkan Hugging Face Token (hf_...)", type="password")
|
| 43 |
+
st.info("Tips: Simpan token di Settings > Secrets dengan nama HF_TOKEN agar otomatis terisi.")
|
| 44 |
+
|
| 45 |
num_scenes = st.slider("Jumlah Scene", 1, 20, 5)
|
| 46 |
+
style = st.selectbox("Gaya Visual", ["Cinematic", "Anime", "3D Render", "Cyberpunk", "Nature Documentary"])
|
|
|
|
|
|
|
|
|
|
| 47 |
|
| 48 |
# Input User
|
| 49 |
col1, col2 = st.columns(2)
|
| 50 |
with col1:
|
| 51 |
+
idea = st.text_area("Ide Utama Video", "Astronot menemukan hutan di bulan", height=100)
|
| 52 |
with col2:
|
| 53 |
+
details = st.text_area("Detail Visual", "Neon plants, dark blue sky, cinematic lighting", height=100)
|
| 54 |
|
| 55 |
if st.button("π Generate Sequence Prompts"):
|
| 56 |
if not hf_token:
|
| 57 |
+
st.error("β Token tidak ditemukan! Masukkan token di sidebar atau di Settings Space.")
|
| 58 |
+
elif not idea:
|
| 59 |
+
st.warning("β οΈ Masukkan ide video terlebih dahulu.")
|
| 60 |
+
else:
|
| 61 |
+
success = False
|
| 62 |
+
with st.spinner("Menghubungi otak AI... (mencoba beberapa model jika perlu)"):
|
| 63 |
+
for model in MODELS:
|
| 64 |
+
try:
|
| 65 |
+
res = query_ai(f"[INST] Create {num_scenes} video scenes for: {idea}. Style: {style}. Details: {details}. Each scene 5 seconds. Format: Scene X: [description] [/INST]", model, hf_token)
|
| 66 |
+
|
| 67 |
+
if res.status_code == 200:
|
| 68 |
+
result_json = res.json()
|
| 69 |
+
# Tergantung model, format output bisa berbeda
|
| 70 |
+
text = result_json[0]['generated_text'] if isinstance(result_json, list) else result_json.get('generated_text', '')
|
| 71 |
+
|
| 72 |
+
st.success(f"β
Berhasil menggunakan model: {model}")
|
| 73 |
+
st.markdown("---")
|
| 74 |
+
st.write(text)
|
| 75 |
+
success = True
|
| 76 |
+
break
|
| 77 |
+
elif res.status_code == 503:
|
| 78 |
+
st.info(f"π Model {model} sedang loading (start-up). Mencoba model lain...")
|
| 79 |
+
else:
|
| 80 |
+
st.error(f"β οΈ Model {model} error: {res.status_code}")
|
| 81 |
+
except Exception as e:
|
| 82 |
+
st.error(f"β Kesalahan teknis: {str(e)}")
|
| 83 |
+
|
| 84 |
+
if not success:
|
| 85 |
+
st.error("π₯ Semua model gagal merespon. Pastikan Token kamu valid (tipe 'Read') dan internet stabil.")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|