Spaces:
Configuration error
Configuration error
Update src/streamlit_app.py
Browse files- src/streamlit_app.py +11 -81
src/streamlit_app.py
CHANGED
|
@@ -2,96 +2,26 @@ import streamlit as st
|
|
| 2 |
import requests
|
| 3 |
import os
|
| 4 |
|
| 5 |
-
#
|
| 6 |
-
st.set_page_config(page_title="AI Video Scene Architect", page_icon="π¬", layout="wide")
|
| 7 |
-
|
| 8 |
-
# Menggunakan Model yang mendukung API Router terbaru
|
| 9 |
-
# Kita gunakan Mistral 7B v0.3 yang sangat stabil
|
| 10 |
MODEL_ID = "mistralai/Mistral-7B-Instruct-v0.3"
|
|
|
|
| 11 |
API_URL = f"https://api-inference.huggingface.co/models/{MODEL_ID}"
|
| 12 |
|
| 13 |
def query_ai(prompt, token):
|
| 14 |
-
headers = {
|
|
|
|
|
|
|
|
|
|
| 15 |
payload = {
|
| 16 |
"inputs": f"<s>[INST] {prompt} [/INST]",
|
| 17 |
"parameters": {
|
| 18 |
"max_new_tokens": 1500,
|
| 19 |
"temperature": 0.7,
|
| 20 |
-
|
|
|
|
| 21 |
}
|
| 22 |
}
|
|
|
|
|
|
|
| 23 |
response = requests.post(API_URL, headers=headers, json=payload)
|
| 24 |
-
return response
|
| 25 |
-
|
| 26 |
-
# --- UI INTERFACE ---
|
| 27 |
-
st.title("π¬ AI Video Scene Architect")
|
| 28 |
-
|
| 29 |
-
# Ambil token dari Secrets (HF_TOKEN)
|
| 30 |
-
hf_token = os.environ.get("HF_TOKEN")
|
| 31 |
-
|
| 32 |
-
with st.sidebar:
|
| 33 |
-
st.header("βοΈ Pengaturan")
|
| 34 |
-
if not hf_token:
|
| 35 |
-
hf_token = st.text_input("Masukkan Hugging Face Token", type="password")
|
| 36 |
-
st.caption("Dapatkan di: huggingface.co/settings/tokens")
|
| 37 |
-
|
| 38 |
-
num_scenes = st.slider("Jumlah Scene", 1, 20, 5)
|
| 39 |
-
|
| 40 |
-
aspect_ratio = st.selectbox(
|
| 41 |
-
"Ukuran Video (Aspect Ratio)",
|
| 42 |
-
["16:9 (YouTube)", "9:16 (TikTok/Reels)", "2:3 (Vertical)", "4:5 (Instagram)"]
|
| 43 |
-
)
|
| 44 |
-
|
| 45 |
-
style = st.selectbox("Gaya Visual", ["Cinematic", "Realistic Photography", "Anime Style", "3D Animation"])
|
| 46 |
-
|
| 47 |
-
# Input User
|
| 48 |
-
col1, col2 = st.columns(2)
|
| 49 |
-
with col1:
|
| 50 |
-
idea = st.text_area("Ide Utama Video", placeholder="Contoh: Petualangan robot di hutan hujan...", height=120)
|
| 51 |
-
with col2:
|
| 52 |
-
details = st.text_area("Detail Visual", placeholder="Pencahayaan dramatis, warna cerah, detail tinggi...", height=120)
|
| 53 |
-
|
| 54 |
-
if st.button("π Generate Sequence Prompts"):
|
| 55 |
-
if not hf_token:
|
| 56 |
-
st.error("β Token tidak ditemukan! Masukkan di sidebar atau di Settings Space.")
|
| 57 |
-
elif not idea:
|
| 58 |
-
st.warning("β οΈ Silakan tulis ide video Anda.")
|
| 59 |
-
else:
|
| 60 |
-
with st.spinner("Menghubungi AI... Mohon tunggu sebentar."):
|
| 61 |
-
# Instruksi yang memaksa AI memberikan hasil akurat per 5 detik
|
| 62 |
-
system_prompt = f"""
|
| 63 |
-
Create a storyboard of {num_scenes} sequential scenes.
|
| 64 |
-
Video Topic: {idea}
|
| 65 |
-
Specific Details: {details}
|
| 66 |
-
Visual Style: {style}
|
| 67 |
-
Aspect Ratio: {aspect_ratio}
|
| 68 |
-
|
| 69 |
-
Strict Rule:
|
| 70 |
-
- Each scene MUST be exactly 5 seconds long.
|
| 71 |
-
- Ensure visual continuity between scenes.
|
| 72 |
-
- Provide a detailed prompt for each scene suitable for AI Video Generators.
|
| 73 |
-
|
| 74 |
-
Format:
|
| 75 |
-
Scene [Number] (5s): [Visual Prompt]
|
| 76 |
-
"""
|
| 77 |
-
|
| 78 |
-
res = query_ai(system_prompt, hf_token)
|
| 79 |
-
|
| 80 |
-
if res.status_code == 200:
|
| 81 |
-
result = res.json()
|
| 82 |
-
# Penanganan jika output berbentuk list atau dict
|
| 83 |
-
output_text = result[0]['generated_text'] if isinstance(result, list) else result.get('generated_text', '')
|
| 84 |
-
|
| 85 |
-
st.success("β
Rangkaian Scene Berhasil Dibuat!")
|
| 86 |
-
st.markdown("---")
|
| 87 |
-
|
| 88 |
-
# Pembersihan teks dari instruksi awal
|
| 89 |
-
final_output = output_text.split("[/INST]")[-1].strip()
|
| 90 |
-
st.write(final_output)
|
| 91 |
-
elif res.status_code == 503:
|
| 92 |
-
st.warning("π Model sedang disiapkan oleh Hugging Face. Silakan tunggu 30 detik lalu klik 'Generate' lagi.")
|
| 93 |
-
elif res.status_code == 404:
|
| 94 |
-
st.error("β Error 404: Model tidak ditemukan atau URL salah. Pastikan nama model benar.")
|
| 95 |
-
else:
|
| 96 |
-
st.error(f"β Terjadi kesalahan (Error {res.status_code}).")
|
| 97 |
-
st.info(f"Pesan: {res.text}")
|
|
|
|
| 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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|