Spaces:
Configuration error
Configuration error
Update src/streamlit_app.py
Browse files- 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 |
-
#
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
"
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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}")
|