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