Triyono2026 commited on
Commit
58c89ce
Β·
verified Β·
1 Parent(s): f71a8d1

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +63 -48
src/streamlit_app.py CHANGED
@@ -1,52 +1,67 @@
1
  import streamlit as st
2
- import requests
3
  import os
4
 
5
- # Konfigurasi halaman diletakkan paling atas
6
- st.set_page_config(page_title="Video Prompt Gen", layout="wide")
7
-
8
- try:
9
- # Model ID & URL
10
- MODEL_ID = "mistralai/Mistral-7B-Instruct-v0.3"
11
- API_URL = f"https://api-inference.huggingface.co/models/{MODEL_ID}"
12
-
13
- st.title("🎬 Video Scene Prompt Generator")
14
-
15
- # Ambil token
16
- hf_token = os.environ.get("HF_TOKEN")
17
-
18
- with st.sidebar:
19
- st.header("βš™οΈ Settings")
20
- if not hf_token:
21
- hf_token = st.text_input("HF Token", type="password")
22
-
23
- num_scenes = st.slider("Jumlah Scene", 1, 20, 5)
24
- aspect_ratio = st.selectbox("Ratio", ["16:9", "9:16", "2:3", "4:5"])
25
- style = st.selectbox("Style", ["Cinematic", "Anime", "3D", "Realistic"])
26
-
27
- col1, col2 = st.columns(2)
28
- with col1:
29
- idea = st.text_area("Ide Video", "Seorang pemuda makan nasi kandar")
30
- with col2:
31
- details = st.text_area("Detail", "Siang hari, cerah")
32
-
33
- if st.button("πŸš€ Generate"):
34
- if not hf_token:
35
- st.error("Masukkan Token di Sidebar/Settings!")
36
- else:
37
- with st.spinner("AI sedang bekerja..."):
38
- prompt = f"Create {num_scenes} scenes for: {idea}. Details: {details}. Style: {style}. Ratio: {aspect_ratio}. Each scene 5s."
39
- headers = {"Authorization": f"Bearer {hf_token}"}
40
- payload = {"inputs": f"<s>[INST] {prompt} [/INST]", "parameters": {"wait_for_model": True}}
41
-
42
- response = requests.post(API_URL, headers=headers, json=payload)
 
 
 
 
 
 
 
 
43
 
44
- if response.status_code == 200:
45
- res_json = response.json()
46
- st.success("Selesai!")
47
- st.write(res_json[0]['generated_text'].split("[/INST]")[-1])
48
- else:
49
- st.error(f"Error {response.status_code}: {response.text}")
50
-
51
- except Exception as e:
52
- st.error(f"Aplikasi Error saat Start: {e}")
 
 
 
 
 
 
 
 
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'.")