Spaces:
Configuration error
Configuration error
Update src/streamlit_app.py
Browse files- src/streamlit_app.py +44 -39
src/streamlit_app.py
CHANGED
|
@@ -1,12 +1,3 @@
|
|
| 1 |
-
# -*- coding: utf-8 -*-
|
| 2 |
-
"""Untitled0.ipynb
|
| 3 |
-
|
| 4 |
-
Automatically generated by Colab.
|
| 5 |
-
|
| 6 |
-
Original file is located at
|
| 7 |
-
https://colab.research.google.com/drive/1XzCraWM_cfHaZvcAoEw56ClMXCmJG3TN
|
| 8 |
-
"""
|
| 9 |
-
|
| 10 |
import streamlit as st
|
| 11 |
import requests
|
| 12 |
import os
|
|
@@ -14,79 +5,93 @@ import os
|
|
| 14 |
# Konfigurasi Halaman
|
| 15 |
st.set_page_config(page_title="AI Video Scene Architect", page_icon="π¬", layout="wide")
|
| 16 |
|
| 17 |
-
# Model yang
|
| 18 |
-
|
|
|
|
|
|
|
| 19 |
|
| 20 |
def query_ai(prompt, token):
|
| 21 |
headers = {"Authorization": f"Bearer {token}"}
|
| 22 |
payload = {
|
| 23 |
"inputs": f"<s>[INST] {prompt} [/INST]",
|
| 24 |
-
"parameters": {
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
}
|
| 26 |
-
response = requests.post(
|
| 27 |
return response
|
| 28 |
|
| 29 |
# --- UI INTERFACE ---
|
| 30 |
st.title("π¬ AI Video Scene Architect")
|
| 31 |
|
| 32 |
-
# Ambil token dari Secrets
|
| 33 |
hf_token = os.environ.get("HF_TOKEN")
|
| 34 |
|
| 35 |
with st.sidebar:
|
| 36 |
st.header("βοΈ Pengaturan")
|
| 37 |
if not hf_token:
|
| 38 |
hf_token = st.text_input("Masukkan Hugging Face Token", type="password")
|
|
|
|
| 39 |
|
| 40 |
num_scenes = st.slider("Jumlah Scene", 1, 20, 5)
|
| 41 |
|
| 42 |
-
# Fitur Baru: Aspect Ratio
|
| 43 |
aspect_ratio = st.selectbox(
|
| 44 |
-
"
|
| 45 |
-
["16:9 (
|
| 46 |
)
|
| 47 |
|
| 48 |
-
style = st.selectbox("Gaya Visual", ["Cinematic", "Realistic", "Anime", "3D Animation"])
|
| 49 |
|
| 50 |
# Input User
|
| 51 |
col1, col2 = st.columns(2)
|
| 52 |
with col1:
|
| 53 |
-
idea = st.text_area("Ide Utama Video", placeholder="Contoh:
|
| 54 |
with col2:
|
| 55 |
-
details = st.text_area("Detail Visual", placeholder="
|
| 56 |
|
| 57 |
if st.button("π Generate Sequence Prompts"):
|
| 58 |
if not hf_token:
|
| 59 |
-
st.error("β Token
|
| 60 |
elif not idea:
|
| 61 |
-
st.warning("β οΈ
|
| 62 |
else:
|
| 63 |
-
with st.spinner("
|
| 64 |
-
#
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
Topic: {idea}
|
| 68 |
-
Details: {details}
|
| 69 |
Visual Style: {style}
|
| 70 |
-
|
| 71 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 72 |
|
| 73 |
-
Format
|
| 74 |
-
Scene [Number] (
|
| 75 |
"""
|
| 76 |
|
| 77 |
-
res = query_ai(
|
| 78 |
|
| 79 |
if res.status_code == 200:
|
| 80 |
result = res.json()
|
|
|
|
| 81 |
output_text = result[0]['generated_text'] if isinstance(result, list) else result.get('generated_text', '')
|
| 82 |
|
| 83 |
-
# Menampilkan hasil
|
| 84 |
st.success("β
Rangkaian Scene Berhasil Dibuat!")
|
| 85 |
st.markdown("---")
|
| 86 |
|
| 87 |
-
#
|
| 88 |
-
|
| 89 |
-
st.write(
|
|
|
|
|
|
|
|
|
|
|
|
|
| 90 |
else:
|
| 91 |
-
st.error(f"β Error {res.status_code}
|
| 92 |
-
st.info("
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
import requests
|
| 3 |
import os
|
|
|
|
| 5 |
# Konfigurasi Halaman
|
| 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 = {"Authorization": f"Bearer {token}"}
|
| 15 |
payload = {
|
| 16 |
"inputs": f"<s>[INST] {prompt} [/INST]",
|
| 17 |
+
"parameters": {
|
| 18 |
+
"max_new_tokens": 1500,
|
| 19 |
+
"temperature": 0.7,
|
| 20 |
+
"wait_for_model": True # Penting: Menunggu jika model sedang loading
|
| 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}")
|