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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import json
|
| 3 |
+
import pandas as pd
|
| 4 |
+
from groq import Groq
|
| 5 |
+
from prompt_engine import PromptGenerator
|
| 6 |
+
from utils import load_techniques, load_styles, parse_prompt_result
|
| 7 |
+
|
| 8 |
+
# ページ設定
|
| 9 |
+
st.set_page_config(
|
| 10 |
+
page_title="AI Art Prompt Generator",
|
| 11 |
+
page_icon="🎨",
|
| 12 |
+
layout="wide",
|
| 13 |
+
initial_sidebar_state="expanded"
|
| 14 |
+
)
|
| 15 |
+
|
| 16 |
+
# Groq APIクライアント設定
|
| 17 |
+
@st.cache_resource
|
| 18 |
+
def get_groq_client():
|
| 19 |
+
return Groq(api_key=st.secrets["GROQ_API_KEY"])
|
| 20 |
+
|
| 21 |
+
# データロード
|
| 22 |
+
@st.cache_data
|
| 23 |
+
def load_data():
|
| 24 |
+
techniques = load_techniques()
|
| 25 |
+
styles = load_styles()
|
| 26 |
+
return techniques, styles
|
| 27 |
+
|
| 28 |
+
# 初期化
|
| 29 |
+
client = get_groq_client()
|
| 30 |
+
techniques, styles = load_data()
|
| 31 |
+
prompt_generator = PromptGenerator()
|
| 32 |
+
|
| 33 |
+
# タイトルとイントロ
|
| 34 |
+
st.title("🎨 究極のMidJourney/nijiJourneyプロンプトジェネレーター")
|
| 35 |
+
st.markdown("""
|
| 36 |
+
このツールは、MidJourneyとnijiJourneyで使用する高度なプロンプトを簡単に生成します。
|
| 37 |
+
基本的な説明から始めて、AIが最先端のテクニックを応用した洗練されたプロンプトに変換します。
|
| 38 |
+
""")
|
| 39 |
+
|
| 40 |
+
# サイドバー
|
| 41 |
+
with st.sidebar:
|
| 42 |
+
st.header("⚙️ 基本設定")
|
| 43 |
+
|
| 44 |
+
mode = st.radio(
|
| 45 |
+
"モード選択",
|
| 46 |
+
["MidJourney", "nijiJourney"],
|
| 47 |
+
help="生成するプロンプトの対象となるAIツールを選択します"
|
| 48 |
+
)
|
| 49 |
+
|
| 50 |
+
complexity = st.select_slider(
|
| 51 |
+
"複雑さレベル",
|
| 52 |
+
options=["シンプル", "バランス", "詳細", "実験的"],
|
| 53 |
+
value="バランス",
|
| 54 |
+
help="生成されるプロンプトの複雑さを調整します"
|
| 55 |
+
)
|
| 56 |
+
|
| 57 |
+
st.markdown("---")
|
| 58 |
+
|
| 59 |
+
st.header("🧙♂️ テクニック設定")
|
| 60 |
+
auto_select = st.checkbox("テクニックを自動選択", value=True,
|
| 61 |
+
help="オフにすると手動でテクニックを選択できます")
|
| 62 |
+
|
| 63 |
+
if not auto_select:
|
| 64 |
+
selected_techniques = st.multiselect(
|
| 65 |
+
"使用するテクニック",
|
| 66 |
+
options=list(techniques.keys()),
|
| 67 |
+
default=[],
|
| 68 |
+
help="プロンプトに適用する特定のテクニックを選択します"
|
| 69 |
+
)
|
| 70 |
+
else:
|
| 71 |
+
selected_techniques = []
|
| 72 |
+
|
| 73 |
+
# メインインプット
|
| 74 |
+
st.header("🎯 あなたのイメージを教えてください")
|
| 75 |
+
user_input = st.text_area(
|
| 76 |
+
"描きたいイメージを自由に入力してください",
|
| 77 |
+
height=100,
|
| 78 |
+
help="日本語で自然に入力できます。AIが最適な英語のプロンプトに変換します。"
|
| 79 |
+
)
|
| 80 |
+
|
| 81 |
+
# 詳細設定タブ
|
| 82 |
+
tab1, tab2, tab3, tab4 = st.tabs(["基本設定", "高度なテクニック", "専門家向け設定", "実験的機能"])
|
| 83 |
+
|
| 84 |
+
with tab1:
|
| 85 |
+
col1, col2 = st.columns(2)
|
| 86 |
+
|
| 87 |
+
with col1:
|
| 88 |
+
aspect_ratio = st.selectbox(
|
| 89 |
+
"アスペクト比",
|
| 90 |
+
["1:1 (正方形)", "16:9 (横長)", "9:16 (縦長)", "3:2 (標準)", "4:3", "2:3", "カスタム"],
|
| 91 |
+
help="画像の縦横比を設定します"
|
| 92 |
+
)
|
| 93 |
+
|
| 94 |
+
if aspect_ratio == "カスタム":
|
| 95 |
+
custom_ratio = st.text_input("カスタム比率 (例: 5:4)")
|
| 96 |
+
aspect_ratio = custom_ratio if custom_ratio else "1:1"
|
| 97 |
+
|
| 98 |
+
quality = st.slider(
|
| 99 |
+
"クオリティ (--q)",
|
| 100 |
+
min_value=0.25,
|
| 101 |
+
max_value=5.0,
|
| 102 |
+
value=2.0,
|
| 103 |
+
step=0.25,
|
| 104 |
+
help="高いほど詳細な画像が生成されますが、処理時間が長くなります"
|
| 105 |
+
)
|
| 106 |
+
|
| 107 |
+
with col2:
|
| 108 |
+
style_category = st.selectbox(
|
| 109 |
+
"スタイルカテゴリ",
|
| 110 |
+
list(styles.keys()),
|
| 111 |
+
help="生成画像の基本的なスタイル方向性を選択します"
|
| 112 |
+
)
|
| 113 |
+
|
| 114 |
+
style_options = styles[style_category]
|
| 115 |
+
style = st.selectbox(
|
| 116 |
+
"スタイル",
|
| 117 |
+
style_options,
|
| 118 |
+
help="具体的なスタイルを選択します"
|
| 119 |
+
)
|
| 120 |
+
|
| 121 |
+
stylize = st.slider(
|
| 122 |
+
"スタイル強度 (--s)",
|
| 123 |
+
min_value=0,
|
| 124 |
+
max_value=1000,
|
| 125 |
+
value=100,
|
| 126 |
+
step=50,
|
| 127 |
+
help="AIの創造性レベルを調整します。高いほど創造的な結果になります"
|
| 128 |
+
)
|
| 129 |
+
|
| 130 |
+
with tab2:
|
| 131 |
+
if auto_select:
|
| 132 |
+
st.info("「テクニックを自動選択」がオンになっています。AIが最適なテクニックを選択します。")
|
| 133 |
+
else:
|
| 134 |
+
st.markdown("### 選択したテクニック")
|
| 135 |
+
|
| 136 |
+
if selected_techniques:
|
| 137 |
+
for tech in selected_techniques:
|
| 138 |
+
st.markdown(f"**{tech}**: {techniques[tech]['description']}")
|
| 139 |
+
else:
|
| 140 |
+
st.warning("テクニックが選択されていません。サイドバーから選択してください。")
|
| 141 |
+
|
| 142 |
+
st.markdown("### テクニック解説")
|
| 143 |
+
tech_df = pd.DataFrame({
|
| 144 |
+
"テクニック": list(techniques.keys()),
|
| 145 |
+
"説明": [t["description"] for t in techniques.values()],
|
| 146 |
+
"効果": [t["effect"] for t in techniques.values()],
|
| 147 |
+
})
|
| 148 |
+
st.dataframe(tech_df, use_container_width=True)
|
| 149 |
+
|
| 150 |
+
with tab3:
|
| 151 |
+
st.markdown("### 専門家向け設定")
|
| 152 |
+
|
| 153 |
+
col1, col2 = st.columns(2)
|
| 154 |
+
|
| 155 |
+
with col1:
|
| 156 |
+
camera_angle = st.selectbox(
|
| 157 |
+
"カメラアングル",
|
| 158 |
+
["自動選択", "eye level", "low angle", "high angle", "dutch angle", "aerial view", "worm's eye view"],
|
| 159 |
+
help="撮影視点の角度を指定します"
|
| 160 |
+
)
|
| 161 |
+
|
| 162 |
+
lens_type = st.selectbox(
|
| 163 |
+
"レンズタイプ",
|
| 164 |
+
["自動選択", "wide angle", "telephoto", "macro", "fisheye", "tilt-shift", "normal"],
|
| 165 |
+
help="カメラレンズの種類を指定します"
|
| 166 |
+
)
|
| 167 |
+
|
| 168 |
+
with col2:
|
| 169 |
+
lighting = st.selectbox(
|
| 170 |
+
"照明設定",
|
| 171 |
+
["自動選択", "natural light", "golden hour", "blue hour", "dramatic lighting", "backlight", "studio lighting"],
|
| 172 |
+
help="画像の照明条件を指定します"
|
| 173 |
+
)
|
| 174 |
+
|
| 175 |
+
composition = st.selectbox(
|
| 176 |
+
"構図",
|
| 177 |
+
["自動選択", "rule of thirds", "golden ratio", "symmetrical", "asymmetrical", "leading lines", "frame within frame"],
|
| 178 |
+
help="画像の構図テクニックを指定します"
|
| 179 |
+
)
|
| 180 |
+
|
| 181 |
+
advanced_params = st.text_area(
|
| 182 |
+
"カスタムパラメータ (JSONフォーマット)",
|
| 183 |
+
"{}",
|
| 184 |
+
help="上級者向け: 追加のカスタムパラメータをJSON形式で指定できます"
|
| 185 |
+
)
|
| 186 |
+
|
| 187 |
+
with tab4:
|
| 188 |
+
st.markdown("### 実験的機能")
|
| 189 |
+
st.warning("これらの機能は予測不能な結果をもたらす可能性があります")
|
| 190 |
+
|
| 191 |
+
col1, col2 = st.columns(2)
|
| 192 |
+
|
| 193 |
+
with col1:
|
| 194 |
+
use_pattern_interrupt = st.checkbox(
|
| 195 |
+
"パターン中断",
|
| 196 |
+
help="対照的な概念を組み合わせて意外性のある結果を生成します"
|
| 197 |
+
)
|
| 198 |
+
|
| 199 |
+
use_logical_paradox = st.checkbox(
|
| 200 |
+
"論理パラドックス",
|
| 201 |
+
help="矛盾する要素を組み合わせて創造的な表現を引き出します"
|
| 202 |
+
)
|
| 203 |
+
|
| 204 |
+
with col2:
|
| 205 |
+
use_magic_words = st.checkbox(
|
| 206 |
+
"魔法の単語",
|
| 207 |
+
help="特定の「魔法の単語」を使って特殊な効果を引き出します"
|
| 208 |
+
)
|
| 209 |
+
|
| 210 |
+
use_emotion_matrix = st.checkbox(
|
| 211 |
+
"感情マトリックス",
|
| 212 |
+
help="複雑な感情表現を階層的に組み込みます"
|
| 213 |
+
)
|
| 214 |
+
|
| 215 |
+
if use_pattern_interrupt:
|
| 216 |
+
pattern_concepts = st.text_input(
|
| 217 |
+
"対照的な概念を入力 (コンマ区切り)",
|
| 218 |
+
help="例: 「エーテル,サイバーパンク」「古代,未来」"
|
| 219 |
+
)
|
| 220 |
+
|
| 221 |
+
if use_emotion_matrix:
|
| 222 |
+
primary_emotion = st.selectbox(
|
| 223 |
+
"主要感情",
|
| 224 |
+
["joy", "fear", "sadness", "anger", "surprise", "contemplative", "peaceful", "mysterious"]
|
| 225 |
+
)
|
| 226 |
+
secondary_emotion = st.selectbox(
|
| 227 |
+
"二次感情",
|
| 228 |
+
["hopeful", "melancholic", "anxious", "determined", "curious", "nostalgic", "dreamy", "tense"]
|
| 229 |
+
)
|
| 230 |
+
|
| 231 |
+
# 生成ボタン
|
| 232 |
+
if st.button("🚀 プロンプトを生成", type="primary", use_container_width=True):
|
| 233 |
+
if not user_input:
|
| 234 |
+
st.error("描きたいイメージを入力してください")
|
| 235 |
+
else:
|
| 236 |
+
with st.spinner("AIがプロンプトを生成中..."):
|
| 237 |
+
# パラメータの準備
|
| 238 |
+
params = {
|
| 239 |
+
"input": user_input,
|
| 240 |
+
"mode": mode.lower(),
|
| 241 |
+
"complexity": complexity,
|
| 242 |
+
"aspect_ratio": aspect_ratio,
|
| 243 |
+
"quality": quality,
|
| 244 |
+
"style": style,
|
| 245 |
+
"stylize": stylize,
|
| 246 |
+
"advanced": {
|
| 247 |
+
"camera_angle": None if camera_angle == "自動選択" else camera_angle,
|
| 248 |
+
"lens_type": None if lens_type == "自動選択" else lens_type,
|
| 249 |
+
"lighting": None if lighting == "自動選択" else lighting,
|
| 250 |
+
"composition": None if composition == "自動選択" else composition,
|
| 251 |
+
"advanced_params": json.loads(advanced_params) if advanced_params else {}
|
| 252 |
+
},
|
| 253 |
+
"experimental": {
|
| 254 |
+
"pattern_interrupt": use_pattern_interrupt,
|
| 255 |
+
"logical_paradox": use_logical_paradox,
|
| 256 |
+
"magic_words": use_magic_words,
|
| 257 |
+
"emotion_matrix": use_emotion_matrix
|
| 258 |
+
}
|
| 259 |
+
}
|
| 260 |
+
|
| 261 |
+
# 実験的機能の詳細
|
| 262 |
+
if use_pattern_interrupt and pattern_concepts:
|
| 263 |
+
params["experimental"]["pattern_concepts"] = [c.strip() for c in pattern_concepts.split(",")]
|
| 264 |
+
|
| 265 |
+
if use_emotion_matrix:
|
| 266 |
+
params["experimental"]["emotions"] = {
|
| 267 |
+
"primary": primary_emotion,
|
| 268 |
+
"secondary": secondary_emotion
|
| 269 |
+
}
|
| 270 |
+
|
| 271 |
+
# テクニック
|
| 272 |
+
if not auto_select and selected_techniques:
|
| 273 |
+
params["techniques"] = selected_techniques
|
| 274 |
+
|
| 275 |
+
# プロンプト生成呼び出し
|
| 276 |
+
result = prompt_generator.generate_prompt(client, params)
|
| 277 |
+
|
| 278 |
+
# 結果の解析
|
| 279 |
+
prompt, explanation = parse_prompt_result(result)
|
| 280 |
+
|
| 281 |
+
# 結果表示
|
| 282 |
+
st.success("プロンプトを生成しました!")
|
| 283 |
+
|
| 284 |
+
st.markdown("### 生成されたプロンプト")
|
| 285 |
+
st.code(prompt, language=None)
|
| 286 |
+
|
| 287 |
+
col1, col2 = st.columns([1, 4])
|
| 288 |
+
with col1:
|
| 289 |
+
if st.button("📋 コピー", key="copy_button"):
|
| 290 |
+
st.write("クリップボードにコピーしました")
|
| 291 |
+
with col2:
|
| 292 |
+
st.caption("MidJourney/nijiJourneyにこのプロンプトを貼り付けて使用してください")
|
| 293 |
+
|
| 294 |
+
if explanation:
|
| 295 |
+
st.markdown("### プロンプト解説")
|
| 296 |
+
st.markdown(explanation)
|
| 297 |
+
|
| 298 |
+
# フッター
|
| 299 |
+
st.markdown("---")
|
| 300 |
+
st.markdown("© 2025 AI Art Prompt Generator - Powered by Groq & Hugging Face")
|