Spaces:
Configuration error
Configuration error
Upload 2 files
Browse files- src/requirements.txt +2 -0
- src/streamlit_app.py +83 -35
src/requirements.txt
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
streamlit
|
| 2 |
+
requests
|
src/streamlit_app.py
CHANGED
|
@@ -1,40 +1,88 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
|
| 4 |
-
|
| 5 |
|
|
|
|
|
|
|
| 6 |
"""
|
| 7 |
-
# Welcome to Streamlit!
|
| 8 |
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
|
| 13 |
-
|
| 14 |
-
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
df = pd.DataFrame({
|
| 27 |
-
"x": x,
|
| 28 |
-
"y": y,
|
| 29 |
-
"idx": indices,
|
| 30 |
-
"rand": np.random.randn(num_points),
|
| 31 |
-
})
|
| 32 |
-
|
| 33 |
-
st.altair_chart(alt.Chart(df, height=700, width=700)
|
| 34 |
-
.mark_point(filled=True)
|
| 35 |
-
.encode(
|
| 36 |
-
x=alt.X("x", axis=None),
|
| 37 |
-
y=alt.Y("y", axis=None),
|
| 38 |
-
color=alt.Color("idx", legend=None, scale=alt.Scale()),
|
| 39 |
-
size=alt.Size("rand", legend=None, scale=alt.Scale(range=[1, 150])),
|
| 40 |
-
))
|
|
|
|
| 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 json
|
| 13 |
|
| 14 |
+
# Konfigurasi Halaman
|
| 15 |
+
st.set_page_config(page_title="AI Scene Director", page_icon="🎬", layout="wide")
|
| 16 |
+
|
| 17 |
+
# Masukkan Token Hugging Face Anda di sini atau via Sidebar
|
| 18 |
+
API_URL = "https://api-inference.huggingface.co/models/Mistralai/Mistral-7B-Instruct-v0.2"
|
| 19 |
+
# Tips: Ganti API_KEY di bawah dengan token asli Anda
|
| 20 |
+
headers = {"Authorization": "Bearer YOUR_HUGGINGFACE_TOKEN_HERE"}
|
| 21 |
+
|
| 22 |
+
def query_ai(prompt):
|
| 23 |
+
payload = {
|
| 24 |
+
"inputs": prompt,
|
| 25 |
+
"parameters": {"max_new_tokens": 2000, "temperature": 0.7}
|
| 26 |
+
}
|
| 27 |
+
response = requests.post(API_URL, headers=headers, json=payload)
|
| 28 |
+
return response.json()
|
| 29 |
+
|
| 30 |
+
# --- UI INTERFACE ---
|
| 31 |
+
st.title("🎬 AI Video Scene Architect")
|
| 32 |
+
st.markdown("Generator prompt berurutan (5 detik/scene) menggunakan Model Bahasa Open-Source.")
|
| 33 |
+
|
| 34 |
+
with st.sidebar:
|
| 35 |
+
st.header("Konfigurasi")
|
| 36 |
+
hf_token = st.text_input("Hugging Face Token", type="password", help="Dapatkan di huggingface.co/settings/tokens")
|
| 37 |
+
num_scenes = st.slider("Jumlah Scene", 1, 20, 5)
|
| 38 |
+
ratio = st.selectbox("Aspect Ratio", ["16:9 (YouTube)", "9:16 (TikTok/Reels)", "1:1 (Instagram)"])
|
| 39 |
+
|
| 40 |
+
if hf_token:
|
| 41 |
+
headers["Authorization"] = f"Bearer {hf_token}"
|
| 42 |
+
|
| 43 |
+
# Input User
|
| 44 |
+
col1, col2 = st.columns(2)
|
| 45 |
+
with col1:
|
| 46 |
+
idea = st.text_area("Ide Utama Video", "Seorang astronot menemukan taman bunga di Mars", height=150)
|
| 47 |
+
with col2:
|
| 48 |
+
details = st.text_area("Detail Visual & Mood", "Cinematic, photorealistic, sunset lighting, lofi vibes", height=150)
|
| 49 |
+
|
| 50 |
+
if st.button("🚀 Generate Sequence Prompts"):
|
| 51 |
+
if not hf_token:
|
| 52 |
+
st.error("Silakan masukkan Hugging Face Token di sidebar terlebih dahulu!")
|
| 53 |
+
elif idea:
|
| 54 |
+
with st.spinner(f"Sedang merancang {num_scenes} scene berurutan..."):
|
| 55 |
+
|
| 56 |
+
# Engineering Prompt yang memaksa output terstruktur
|
| 57 |
+
master_prompt = f"""
|
| 58 |
+
[INST] Act as a professional Video Director.
|
| 59 |
+
Create a sequential storyboard for a video about: "{idea}".
|
| 60 |
+
Details: {details}.
|
| 61 |
+
|
| 62 |
+
Strict Requirements:
|
| 63 |
+
1. Total scenes: {num_scenes}.
|
| 64 |
+
2. Each scene duration: exactly 5 seconds.
|
| 65 |
+
3. Maintain visual continuity (characters and settings must stay consistent).
|
| 66 |
+
4. Format each scene as:
|
| 67 |
+
Scene [Number]: [5-second visual description for AI Video Generator]
|
| 68 |
+
[/INST]
|
| 69 |
+
"""
|
| 70 |
+
|
| 71 |
+
result = query_ai(master_prompt)
|
| 72 |
+
|
| 73 |
+
if isinstance(result, list) and len(result) > 0:
|
| 74 |
+
output_text = result[0].get('generated_text', '')
|
| 75 |
+
# Membersihkan output dari prompt asli
|
| 76 |
+
clean_output = output_text.split("[/INST]")[-1].strip()
|
| 77 |
+
|
| 78 |
+
st.success("Rangkaian Scene Berhasil Dibuat!")
|
| 79 |
|
| 80 |
+
# Menampilkan hasil dalam bentuk kartu
|
| 81 |
+
scenes_raw = clean_output.split("Scene")
|
| 82 |
+
for s in scenes_raw:
|
| 83 |
+
if s.strip():
|
| 84 |
+
with st.container():
|
| 85 |
+
st.info(f"🎬 Scene {s.strip()}")
|
| 86 |
+
st.button(f"Copy Scene", key=s[:20])
|
| 87 |
+
else:
|
| 88 |
+
st.error("Gagal menghubungi AI. Pastikan Token benar atau coba lagi nanti.")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|