Spaces:
Configuration error
Configuration error
| # -*- 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.") |