Triyono2026 commited on
Commit
bec9d7b
·
verified ·
1 Parent(s): 4c69248

Upload 2 files

Browse files
Files changed (2) hide show
  1. src/requirements.txt +2 -0
  2. 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
- import altair as alt
2
- import numpy as np
3
- import pandas as pd
4
- import streamlit as st
5
 
 
 
6
  """
7
- # Welcome to Streamlit!
8
 
9
- Edit `/streamlit_app.py` to customize this app to your heart's desire :heart:.
10
- If you have any questions, checkout our [documentation](https://docs.streamlit.io) and [community
11
- forums](https://discuss.streamlit.io).
12
 
13
- In the meantime, below is an example of what you can do with just a few lines of code:
14
- """
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
15
 
16
- num_points = st.slider("Number of points in spiral", 1, 10000, 1100)
17
- num_turns = st.slider("Number of turns in spiral", 1, 300, 31)
18
-
19
- indices = np.linspace(0, 1, num_points)
20
- theta = 2 * np.pi * num_turns * indices
21
- radius = indices
22
-
23
- x = radius * np.cos(theta)
24
- y = radius * np.sin(theta)
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.")