Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,6 +2,7 @@ import streamlit as st
|
|
| 2 |
import json
|
| 3 |
import pandas as pd
|
| 4 |
import random
|
|
|
|
| 5 |
from groq import Groq
|
| 6 |
from prompt_engine import PromptGenerator
|
| 7 |
from utils import load_techniques, load_styles, parse_prompt_result
|
|
@@ -12,7 +13,8 @@ model_themes = {
|
|
| 12 |
"llama-3.3-70b-versatile": {"primary": "#4b367c", "secondary": "#d1c4e9"},
|
| 13 |
"meta-llama/llama-4-maverick-17b-128e-instruct": {"primary": "#00897b", "secondary": "#b2dfdb"},
|
| 14 |
"mistral-saba-24b": {"primary": "#0277bd", "secondary": "#b3e5fc"},
|
| 15 |
-
"qwen-qwq-32b": {"primary": "#6a1b9a", "secondary": "#e1bee7"}
|
|
|
|
| 16 |
}
|
| 17 |
|
| 18 |
# 選択されたモデル(初回読み込み時のデフォルト値)
|
|
@@ -52,6 +54,13 @@ st.markdown(f"""
|
|
| 52 |
def get_groq_client():
|
| 53 |
return Groq(api_key=st.secrets["GROQ_API_KEY"])
|
| 54 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 55 |
# データロード
|
| 56 |
@st.cache_data
|
| 57 |
def load_data():
|
|
@@ -61,6 +70,7 @@ def load_data():
|
|
| 61 |
|
| 62 |
# 初期化
|
| 63 |
client = get_groq_client()
|
|
|
|
| 64 |
techniques, styles = load_data()
|
| 65 |
prompt_generator = PromptGenerator()
|
| 66 |
|
|
@@ -92,15 +102,22 @@ with st.sidebar:
|
|
| 92 |
st.markdown("---")
|
| 93 |
st.header("🧠 AIモデル")
|
| 94 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 95 |
model = st.selectbox(
|
| 96 |
"AIモデルを選択",
|
| 97 |
-
|
| 98 |
-
"deepseek-r1-distill-llama-70b",
|
| 99 |
-
"llama-3.3-70b-versatile",
|
| 100 |
-
"meta-llama/llama-4-maverick-17b-128e-instruct",
|
| 101 |
-
"mistral-saba-24b",
|
| 102 |
-
"qwen-qwq-32b"
|
| 103 |
-
],
|
| 104 |
index=4, # デフォルトは qwen-qwq-32b
|
| 105 |
help="使用するAIモデルを選択します。各モデルによって生成結果の特性が異なります"
|
| 106 |
)
|
|
@@ -129,7 +146,8 @@ with st.sidebar:
|
|
| 129 |
"llama-3.3-70b-versatile": "Meta AIの最新LLaMA 3.3。バランスの取れた高性能モデルで、多くのタスクに適しています。",
|
| 130 |
"meta-llama/llama-4-maverick-17b-128e-instruct": "LLaMA 4 Maverickの指示チューニング版。小型ながら高性能です。",
|
| 131 |
"mistral-saba-24b": "Mistral AIのSaba 24Bモデル。創造性と一貫性のバランスに優れています。",
|
| 132 |
-
"qwen-qwq-32b": "Qwen QWQモデル。創造的な表現力が高く、芸術的プロンプトに適しています。"
|
|
|
|
| 133 |
}
|
| 134 |
|
| 135 |
st.caption(model_info.get(model, ""))
|
|
@@ -499,10 +517,16 @@ with tab4:
|
|
| 499 |
["hopeful", "melancholic", "anxious", "determined", "curious", "nostalgic", "dreamy", "tense"]
|
| 500 |
)
|
| 501 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 502 |
# 生成ボタン
|
| 503 |
if st.button("🚀 プロンプトを生成", type="primary", use_container_width=True):
|
| 504 |
if not user_input:
|
| 505 |
st.error("描きたいイメージを入力してください")
|
|
|
|
|
|
|
| 506 |
else:
|
| 507 |
with st.spinner("AIがプロンプトを生成中..."):
|
| 508 |
# パラメータの準備
|
|
|
|
| 2 |
import json
|
| 3 |
import pandas as pd
|
| 4 |
import random
|
| 5 |
+
import os
|
| 6 |
from groq import Groq
|
| 7 |
from prompt_engine import PromptGenerator
|
| 8 |
from utils import load_techniques, load_styles, parse_prompt_result
|
|
|
|
| 13 |
"llama-3.3-70b-versatile": {"primary": "#4b367c", "secondary": "#d1c4e9"},
|
| 14 |
"meta-llama/llama-4-maverick-17b-128e-instruct": {"primary": "#00897b", "secondary": "#b2dfdb"},
|
| 15 |
"mistral-saba-24b": {"primary": "#0277bd", "secondary": "#b3e5fc"},
|
| 16 |
+
"qwen-qwq-32b": {"primary": "#6a1b9a", "secondary": "#e1bee7"},
|
| 17 |
+
"o4-mini-2025-04-16": {"primary": "#10a37f", "secondary": "#d2f4ea"}
|
| 18 |
}
|
| 19 |
|
| 20 |
# 選択されたモデル(初回読み込み時のデフォルト値)
|
|
|
|
| 54 |
def get_groq_client():
|
| 55 |
return Groq(api_key=st.secrets["GROQ_API_KEY"])
|
| 56 |
|
| 57 |
+
# OpenAI APIキーの設定
|
| 58 |
+
def setup_openai_api():
|
| 59 |
+
if "OPENAI_API_KEY" in st.secrets:
|
| 60 |
+
os.environ["OPENAI_API_KEY"] = st.secrets["OPENAI_API_KEY"]
|
| 61 |
+
return True
|
| 62 |
+
return False
|
| 63 |
+
|
| 64 |
# データロード
|
| 65 |
@st.cache_data
|
| 66 |
def load_data():
|
|
|
|
| 70 |
|
| 71 |
# 初期化
|
| 72 |
client = get_groq_client()
|
| 73 |
+
openai_available = setup_openai_api()
|
| 74 |
techniques, styles = load_data()
|
| 75 |
prompt_generator = PromptGenerator()
|
| 76 |
|
|
|
|
| 102 |
st.markdown("---")
|
| 103 |
st.header("🧠 AIモデル")
|
| 104 |
|
| 105 |
+
# Claudeのsonnetをモデル選択に追加
|
| 106 |
+
model_options = [
|
| 107 |
+
"deepseek-r1-distill-llama-70b",
|
| 108 |
+
"llama-3.3-70b-versatile",
|
| 109 |
+
"meta-llama/llama-4-maverick-17b-128e-instruct",
|
| 110 |
+
"mistral-saba-24b",
|
| 111 |
+
"qwen-qwq-32b"
|
| 112 |
+
]
|
| 113 |
+
|
| 114 |
+
# OpenAI APIキーが設定されている場合のみGPTモデルを選択肢に追加
|
| 115 |
+
if openai_available:
|
| 116 |
+
model_options.append("o4-mini-2025-04-16")
|
| 117 |
+
|
| 118 |
model = st.selectbox(
|
| 119 |
"AIモデルを選択",
|
| 120 |
+
model_options,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 121 |
index=4, # デフォルトは qwen-qwq-32b
|
| 122 |
help="使用するAIモデルを選択します。各モデルによって生成結果の特性が異なります"
|
| 123 |
)
|
|
|
|
| 146 |
"llama-3.3-70b-versatile": "Meta AIの最新LLaMA 3.3。バランスの取れた高性能モデルで、多くのタスクに適しています。",
|
| 147 |
"meta-llama/llama-4-maverick-17b-128e-instruct": "LLaMA 4 Maverickの指示チューニング版。小型ながら高性能です。",
|
| 148 |
"mistral-saba-24b": "Mistral AIのSaba 24Bモデル。創造性と一貫性のバランスに優れています。",
|
| 149 |
+
"qwen-qwq-32b": "Qwen QWQモデル。創造的な表現力が高く、芸術的プロンプトに適しています。",
|
| 150 |
+
"o4-mini-2025-04-16": "OpenAIの最新o4モデルのコンパクト版。高度なコンテキスト理解と創造的なプロンプト生成能力に優れています。"
|
| 151 |
}
|
| 152 |
|
| 153 |
st.caption(model_info.get(model, ""))
|
|
|
|
| 517 |
["hopeful", "melancholic", "anxious", "determined", "curious", "nostalgic", "dreamy", "tense"]
|
| 518 |
)
|
| 519 |
|
| 520 |
+
# OpenAI APIキーが設定されていない場合の警告
|
| 521 |
+
if "o4-mini-2025-04-16" in model_options and not openai_available and model == "o4-mini-2025-04-16":
|
| 522 |
+
st.warning("OpenAI APIキーが設定されていないため、GPTモデルは使用できません。他のモデルを選択してください。")
|
| 523 |
+
|
| 524 |
# 生成ボタン
|
| 525 |
if st.button("🚀 プロンプトを生成", type="primary", use_container_width=True):
|
| 526 |
if not user_input:
|
| 527 |
st.error("描きたいイメージを入力してください")
|
| 528 |
+
elif model == "o4-mini-2025-04-16" and not openai_available:
|
| 529 |
+
st.error("OpenAI APIキーが設定されていないため、GPTモデルは使用できません。他のモデルを選択してください。")
|
| 530 |
else:
|
| 531 |
with st.spinner("AIがプロンプトを生成中..."):
|
| 532 |
# パラメータの準備
|