Triyono2026 commited on
Commit
4f052e9
Β·
verified Β·
1 Parent(s): 234f075

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. 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 json
13
 
14
  # Konfigurasi Halaman
15
- st.set_page_config(page_title="AI Scene Director", page_icon="🎬", layout="wide")
16
 
17
- # Masukkan Token Hugging Face Anda di sini atau via Sidebar
18
- API_URL = "https://api-inference.huggingface.co/models/meta-llama/Meta-Llama-3-8B-Instruct"
19
- # Tips: Ganti API_KEY di bawah dengan token asli Anda
20
- headers = {"Authorization": "Bearer YOUR_HUGGINGFACE_TOKEN_HERE"}
 
 
21
 
22
- def query_ai(prompt):
 
23
  payload = {
24
  "inputs": prompt,
25
- "parameters": {"max_new_tokens": 2000, "temperature": 0.7}
26
  }
27
- response = requests.post(API_URL, headers=headers, json=payload)
28
- return response.json()
29
 
30
  # --- UI INTERFACE ---
31
  st.title("🎬 AI Video Scene Architect")
32
- st.markdown("Generator prompt berurutan (5 detik/scene) menggunakan Model Bahasa Open-Source.")
 
 
33
 
34
  with st.sidebar:
35
  st.header("Konfigurasi")
36
- hf_token = st.text_input("Hugging Face Token", type="password", help="Dapatkan di huggingface.co/settings/tokens")
 
 
 
37
  num_scenes = st.slider("Jumlah Scene", 1, 20, 5)
38
- ratio = st.selectbox("Aspect Ratio", ["16:9 (YouTube)", "9:16 (TikTok/Reels)", "1:1 (Instagram)"])
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", "Seorang astronot menemukan taman bunga di Mars", height=150)
47
  with col2:
48
- details = st.text_area("Detail Visual & Mood", "Cinematic, photorealistic, sunset lighting, lofi vibes", height=150)
49
 
50
  if st.button("πŸš€ Generate Sequence Prompts"):
51
  if not hf_token:
52
- st.error("Silakan masukkan Hugging Face Token di sidebar terlebih dahulu!")
53
- elif idea:
54
- with st.spinner(f"Sedang merancang {num_scenes} scene berurutan..."):
55
-
56
- # Engineering Prompt yang memaksa output terstruktur
57
- master_prompt = f"""
58
- [INST] Act as a professional Video Director.
59
- Create a sequential storyboard for a video about: "{idea}".
60
- Details: {details}.
61
-
62
- Strict Requirements:
63
- 1. Total scenes: {num_scenes}.
64
- 2. Each scene duration: exactly 5 seconds.
65
- 3. Maintain visual continuity (characters and settings must stay consistent).
66
- 4. Format each scene as:
67
- Scene [Number]: [5-second visual description for AI Video Generator]
68
- [/INST]
69
- """
70
-
71
- result = query_ai(master_prompt)
72
-
73
- if isinstance(result, list) and len(result) > 0:
74
- output_text = result[0].get('generated_text', '')
75
- # Membersihkan output dari prompt asli
76
- clean_output = output_text.split("[/INST]")[-1].strip()
77
-
78
- st.success("Rangkaian Scene Berhasil Dibuat!")
79
-
80
- # Menampilkan hasil dalam bentuk kartu
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.")