Triyono2026 commited on
Commit
0cae52d
·
verified ·
1 Parent(s): 4e80d08

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +48 -23
src/streamlit_app.py CHANGED
@@ -2,26 +2,51 @@ import streamlit as st
2
  import requests
3
  import os
4
 
5
- # Gunakan model yang terbukti stabil dengan router baru
6
- MODEL_ID = "mistralai/Mistral-7B-Instruct-v0.3"
7
- # Endpoint terbaru yang direkomendasikan Hugging Face
8
- API_URL = f"https://api-inference.huggingface.co/models/{MODEL_ID}"
9
-
10
- def query_ai(prompt, token):
11
- headers = {
12
- "Authorization": f"Bearer {token}",
13
- "Content-Type": "application/json"
14
- }
15
- payload = {
16
- "inputs": f"<s>[INST] {prompt} [/INST]",
17
- "parameters": {
18
- "max_new_tokens": 1500,
19
- "temperature": 0.7,
20
- # wait_for_model memaksa router menunggu hingga model siap (mencegah 503/404)
21
- "wait_for_model": True
22
- }
23
- }
24
- # Tetap gunakan api-inference tetapi dengan parameter wait_for_model
25
- # Sistem Hugging Face akan melakukan routing otomatis di belakang layar
26
- response = requests.post(API_URL, headers=headers, json=payload)
27
- return response
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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}")