GitHub Action
commited on
Commit
·
0661b76
1
Parent(s):
17afe48
🚀 Auto-deploy from GitHub Actions
Browse files
Makefile
CHANGED
@@ -7,7 +7,7 @@ COLOR_CYAN=\033[1;36m
|
|
7 |
COLOR_GREEN=\033[1;32m
|
8 |
|
9 |
# Defines the targets help, install, dev-install, and run as phony targets.
|
10 |
-
.PHONY: help install run
|
11 |
|
12 |
#sets the default goal to help when no target is specified on the command line.
|
13 |
.DEFAULT_GOAL := help
|
@@ -24,6 +24,13 @@ help:
|
|
24 |
@echo " help Return this message with usage instructions."
|
25 |
@echo " install Will install the dependencies using Poetry."
|
26 |
@echo " run <folder_name> Runs GPT Engineer on the folder with the given name."
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
27 |
|
28 |
#Defines a target named install. This target will install the project using Poetry.
|
29 |
install: poetry-install install-pre-commit farewell
|
@@ -70,4 +77,67 @@ cloc:
|
|
70 |
cloc . --exclude-dir=node_modules,dist,build,.mypy_cache,benchmark --exclude-list-file=.gitignore --fullpath --not-match-d='docs/_build' --by-file
|
71 |
|
72 |
ssh:
|
73 |
-
ssh-keygen -t rsa -b 4096 \-f ~/.ssh/id_rsa_new
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
7 |
COLOR_GREEN=\033[1;32m
|
8 |
|
9 |
# Defines the targets help, install, dev-install, and run as phony targets.
|
10 |
+
.PHONY: help install run dev debug app server test clean requirements
|
11 |
|
12 |
#sets the default goal to help when no target is specified on the command line.
|
13 |
.DEFAULT_GOAL := help
|
|
|
24 |
@echo " help Return this message with usage instructions."
|
25 |
@echo " install Will install the dependencies using Poetry."
|
26 |
@echo " run <folder_name> Runs GPT Engineer on the folder with the given name."
|
27 |
+
@echo " app Run the main FastAPI application (app.py)"
|
28 |
+
@echo " dev Run the application in development mode with hot reload"
|
29 |
+
@echo " debug Run the application in debug mode (no reload)"
|
30 |
+
@echo " server Run the ASGI server directly with uvicorn"
|
31 |
+
@echo " test Run all tests"
|
32 |
+
@echo " requirements Install Python requirements from requirements.txt"
|
33 |
+
@echo " clean Clean up temporary files and caches"
|
34 |
|
35 |
#Defines a target named install. This target will install the project using Poetry.
|
36 |
install: poetry-install install-pre-commit farewell
|
|
|
77 |
cloc . --exclude-dir=node_modules,dist,build,.mypy_cache,benchmark --exclude-list-file=.gitignore --fullpath --not-match-d='docs/_build' --by-file
|
78 |
|
79 |
ssh:
|
80 |
+
ssh-keygen -t rsa -b 4096 \-f ~/.ssh/id_rsa_new
|
81 |
+
|
82 |
+
# Application commands
|
83 |
+
app:
|
84 |
+
@echo -e "$(COLOR_CYAN)Starting FastAPI application...$(COLOR_RESET)"
|
85 |
+
SPACE_ID="" python app.py
|
86 |
+
|
87 |
+
dev:
|
88 |
+
@echo -e "$(COLOR_CYAN)Starting application in development mode...$(COLOR_RESET)"
|
89 |
+
SPACE_ID="" python app.py
|
90 |
+
|
91 |
+
debug:
|
92 |
+
@echo -e "$(COLOR_CYAN)Starting application in debug mode...$(COLOR_RESET)"
|
93 |
+
SPACE_ID="" python app.py --debug
|
94 |
+
|
95 |
+
server:
|
96 |
+
@echo -e "$(COLOR_CYAN)Starting ASGI server directly...$(COLOR_RESET)"
|
97 |
+
uvicorn mysite.asgi:app --host 0.0.0.0 --port 7860 --reload
|
98 |
+
|
99 |
+
# Requirements and dependencies
|
100 |
+
requirements:
|
101 |
+
@echo -e "$(COLOR_CYAN)Installing Python requirements...$(COLOR_RESET)"
|
102 |
+
pip install -r requirements.txt
|
103 |
+
|
104 |
+
# Testing
|
105 |
+
test:
|
106 |
+
@echo -e "$(COLOR_CYAN)Running tests...$(COLOR_RESET)"
|
107 |
+
python -m pytest tests/ -v
|
108 |
+
|
109 |
+
# Utility commands
|
110 |
+
clean:
|
111 |
+
@echo -e "$(COLOR_CYAN)Cleaning up temporary files...$(COLOR_RESET)"
|
112 |
+
find . -type f -name "*.pyc" -delete
|
113 |
+
find . -type d -name "__pycache__" -delete
|
114 |
+
find . -type d -name "*.egg-info" -exec rm -rf {} +
|
115 |
+
rm -rf .pytest_cache/
|
116 |
+
rm -rf build/
|
117 |
+
rm -rf dist/
|
118 |
+
|
119 |
+
# Database commands
|
120 |
+
migrate:
|
121 |
+
@echo -e "$(COLOR_CYAN)Running database migrations...$(COLOR_RESET)"
|
122 |
+
python manage.py migrate
|
123 |
+
|
124 |
+
makemigrations:
|
125 |
+
@echo -e "$(COLOR_CYAN)Creating database migrations...$(COLOR_RESET)"
|
126 |
+
python manage.py makemigrations
|
127 |
+
|
128 |
+
# Docker commands
|
129 |
+
docker-build:
|
130 |
+
@echo -e "$(COLOR_CYAN)Building Docker image...$(COLOR_RESET)"
|
131 |
+
docker-compose build
|
132 |
+
|
133 |
+
docker-up:
|
134 |
+
@echo -e "$(COLOR_CYAN)Starting Docker containers...$(COLOR_RESET)"
|
135 |
+
docker-compose up -d
|
136 |
+
|
137 |
+
docker-down:
|
138 |
+
@echo -e "$(COLOR_CYAN)Stopping Docker containers...$(COLOR_RESET)"
|
139 |
+
docker-compose down
|
140 |
+
|
141 |
+
docker-logs:
|
142 |
+
@echo -e "$(COLOR_CYAN)Showing Docker logs...$(COLOR_RESET)"
|
143 |
+
docker-compose logs -f
|
app.py
CHANGED
@@ -33,28 +33,23 @@ from interpreter import interpreter
|
|
33 |
import os
|
34 |
|
35 |
GENERATION_TIMEOUT_SEC = 60
|
36 |
-
import os
|
37 |
-
|
38 |
-
from llamafactory.webui.interface import create_ui
|
39 |
-
|
40 |
-
# Gradio インターフェース作成
|
41 |
-
demo = create_ui()
|
42 |
|
43 |
if __name__ == "__main__":
|
44 |
import sys
|
45 |
|
46 |
-
#
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
|
|
|
|
55 |
else:
|
56 |
-
|
57 |
-
is_debug = "--debug" in sys.argv or any("debugpy" in arg for arg in sys.argv)
|
58 |
|
59 |
try:
|
60 |
print("🚀 アプリケーションを開始しています...")
|
|
|
33 |
import os
|
34 |
|
35 |
GENERATION_TIMEOUT_SEC = 60
|
|
|
|
|
|
|
|
|
|
|
|
|
36 |
|
37 |
if __name__ == "__main__":
|
38 |
import sys
|
39 |
|
40 |
+
# デバッグ: コマンドライン引数と環境変数を確認
|
41 |
+
print(f"🔍 sys.argv: {sys.argv}")
|
42 |
+
print(f"🔍 SPACE_ID環境変数: {os.getenv('SPACE_ID')}")
|
43 |
+
print(f"🔍 '--gradio' in sys.argv: {'--gradio' in sys.argv}")
|
44 |
+
|
45 |
+
# デバッグモードかどうかを判定
|
46 |
+
is_debug = "--debug" in sys.argv or any("debugpy" in arg for arg in sys.argv)
|
47 |
+
|
48 |
+
# 実行環境の表示
|
49 |
+
if os.getenv("SPACE_ID"):
|
50 |
+
print("🤗 Hugging Face Spaces環境で実行中")
|
51 |
else:
|
52 |
+
print("💻 ローカル開発環境で実行中")
|
|
|
53 |
|
54 |
try:
|
55 |
print("🚀 アプリケーションを開始しています...")
|
controllers/gra_03_programfromdocgas/programfromdocAI_backup.py
ADDED
@@ -0,0 +1,287 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from mysite.libs.utilities import chat_with_interpreter, completion, process_file, no_process_file
|
3 |
+
from interpreter import interpreter
|
4 |
+
import mysite.interpreter.interpreter_config # インポートするだけで設定が適用されます
|
5 |
+
import sqlite3
|
6 |
+
import os
|
7 |
+
from datetime import datetime
|
8 |
+
from typing import List, Tuple, Optional
|
9 |
+
|
10 |
+
# データベース設定
|
11 |
+
DB_PATH = "prompts.db"
|
12 |
+
|
13 |
+
def init_db():
|
14 |
+
"""プロンプトデータベースの初期化"""
|
15 |
+
conn = sqlite3.connect(DB_PATH)
|
16 |
+
cursor = conn.cursor()
|
17 |
+
|
18 |
+
cursor.execute('''
|
19 |
+
CREATE TABLE IF NOT EXISTS prompts (
|
20 |
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
21 |
+
title TEXT NOT NULL,
|
22 |
+
url TEXT,
|
23 |
+
content TEXT NOT NULL,
|
24 |
+
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
25 |
+
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
26 |
+
)
|
27 |
+
''')
|
28 |
+
|
29 |
+
# デフォルトプロンプトの追加(初回のみ)
|
30 |
+
cursor.execute('SELECT COUNT(*) FROM prompts')
|
31 |
+
if cursor.fetchone()[0] == 0:
|
32 |
+
default_prompt = """# gradio で miiboのナレッジに登録する画面の作成
|
33 |
+
gradio_interface interfacec name
|
34 |
+
|
35 |
+
# fastapi
|
36 |
+
gradio apiに接続するAPI
|
37 |
+
router で作成
|
38 |
+
|
39 |
+
1ファイルで作成
|
40 |
+
仕様書の作成
|
41 |
+
plantumlで図にする
|
42 |
+
|
43 |
+
#sample fastapi
|
44 |
+
import requests
|
45 |
+
import json
|
46 |
+
import os
|
47 |
+
|
48 |
+
from fastapi import APIRouter, HTTPException
|
49 |
+
from gradio_client import Client
|
50 |
+
|
51 |
+
router = APIRouter(prefix="/gradio", tags=["gradio"])
|
52 |
+
@router.get("/route/gradio")
|
53 |
+
|
54 |
+
def get_senario(id,res):
|
55 |
+
table = "LOG"
|
56 |
+
client = Client("kenken999/fastapi_django_main_live")
|
57 |
+
result = client.predict(
|
58 |
+
message="Hello!!",
|
59 |
+
request=0.95,
|
60 |
+
param_3=512,
|
61 |
+
api_name="/chat"
|
62 |
+
)
|
63 |
+
return result
|
64 |
+
"""
|
65 |
+
cursor.execute(
|
66 |
+
'INSERT INTO prompts (title, url, content) VALUES (?, ?, ?)',
|
67 |
+
('デフォルト:Gradio + FastAPI作成', 'https://example.com', default_prompt)
|
68 |
+
)
|
69 |
+
|
70 |
+
conn.commit()
|
71 |
+
conn.close()
|
72 |
+
|
73 |
+
def save_prompt(title: str, url: str, content: str) -> str:
|
74 |
+
"""プロンプトを保存"""
|
75 |
+
try:
|
76 |
+
conn = sqlite3.connect(DB_PATH)
|
77 |
+
cursor = conn.cursor()
|
78 |
+
|
79 |
+
cursor.execute(
|
80 |
+
'INSERT INTO prompts (title, url, content) VALUES (?, ?, ?)',
|
81 |
+
(title, url, content)
|
82 |
+
)
|
83 |
+
|
84 |
+
conn.commit()
|
85 |
+
conn.close()
|
86 |
+
return f"✅ プロンプト '{title}' を保存しました!"
|
87 |
+
except Exception as e:
|
88 |
+
return f"❌ エラー: {str(e)}"
|
89 |
+
|
90 |
+
def get_prompts() -> List[Tuple]:
|
91 |
+
"""全プロンプトを取得"""
|
92 |
+
try:
|
93 |
+
conn = sqlite3.connect(DB_PATH)
|
94 |
+
cursor = conn.cursor()
|
95 |
+
|
96 |
+
cursor.execute('SELECT id, title, url, created_at FROM prompts ORDER BY created_at DESC')
|
97 |
+
prompts = cursor.fetchall()
|
98 |
+
|
99 |
+
conn.close()
|
100 |
+
return prompts
|
101 |
+
except Exception as e:
|
102 |
+
print(f"プロンプト取得エラー: {e}")
|
103 |
+
return []
|
104 |
+
|
105 |
+
def get_prompt_content(prompt_id: int) -> str:
|
106 |
+
"""指定IDのプロンプト内容を取得"""
|
107 |
+
try:
|
108 |
+
conn = sqlite3.connect(DB_PATH)
|
109 |
+
cursor = conn.cursor()
|
110 |
+
|
111 |
+
cursor.execute('SELECT content FROM prompts WHERE id = ?', (prompt_id,))
|
112 |
+
result = cursor.fetchone()
|
113 |
+
|
114 |
+
conn.close()
|
115 |
+
return result[0] if result else ""
|
116 |
+
except Exception as e:
|
117 |
+
print(f"プロンプト内容取得エラー: {e}")
|
118 |
+
return ""
|
119 |
+
|
120 |
+
def delete_prompt(prompt_id: int) -> str:
|
121 |
+
"""プロンプトを削除"""
|
122 |
+
try:
|
123 |
+
conn = sqlite3.connect(DB_PATH)
|
124 |
+
cursor = conn.cursor()
|
125 |
+
|
126 |
+
cursor.execute('DELETE FROM prompts WHERE id = ?', (prompt_id,))
|
127 |
+
|
128 |
+
if cursor.rowcount > 0:
|
129 |
+
conn.commit()
|
130 |
+
conn.close()
|
131 |
+
return "✅ プロンプトを削除しました"
|
132 |
+
else:
|
133 |
+
conn.close()
|
134 |
+
return "❌ プロンプトが見つかりません"
|
135 |
+
except Exception as e:
|
136 |
+
return f"❌ 削除エラー: {str(e)}"
|
137 |
+
|
138 |
+
# データベース初期化
|
139 |
+
init_db()
|
140 |
+
|
141 |
+
def load_prompt_from_db(prompt_id):
|
142 |
+
"""選択されたプロンプトを読み込み"""
|
143 |
+
if prompt_id:
|
144 |
+
content = get_prompt_content(int(prompt_id))
|
145 |
+
return content
|
146 |
+
return ""
|
147 |
+
|
148 |
+
def refresh_prompt_list():
|
149 |
+
"""プロンプト一覧を更新"""
|
150 |
+
prompts = get_prompts()
|
151 |
+
choices = []
|
152 |
+
for prompt in prompts:
|
153 |
+
id_, title, url, created_at = prompt
|
154 |
+
display_text = f"[{id_}] {title} ({created_at[:10]})"
|
155 |
+
choices.append((display_text, str(id_)))
|
156 |
+
return gr.Dropdown(choices=choices, label="📋 保存済みプロンプト一覧", value=None)
|
157 |
+
|
158 |
+
# Gradioインターフェース作成
|
159 |
+
with gr.Blocks(title="🚀 プロンプト管理 & コード生成") as gradio_interface:
|
160 |
+
gr.Markdown("# 🚀 プロンプト管理 & ドキュメントからコード生成")
|
161 |
+
|
162 |
+
with gr.Tabs():
|
163 |
+
# タブ1: プロンプト管理
|
164 |
+
with gr.TabItem("📝 プロンプト管理"):
|
165 |
+
gr.Markdown("## プロンプトの保存・管理")
|
166 |
+
|
167 |
+
with gr.Row():
|
168 |
+
with gr.Column(scale=1):
|
169 |
+
# プロンプト保存フォーム
|
170 |
+
save_title = gr.Textbox(label="📋 タイトル", placeholder="例: FastAPI + Gradio作成プロンプト")
|
171 |
+
save_url = gr.Textbox(label="🔗 参考URL (任意)", placeholder="https://example.com")
|
172 |
+
save_content = gr.Textbox(
|
173 |
+
label="📝 プロンプト内容",
|
174 |
+
lines=10,
|
175 |
+
placeholder="プロンプトの内容を入力してください..."
|
176 |
+
)
|
177 |
+
save_btn = gr.Button("💾 プロンプトを保存", variant="primary")
|
178 |
+
save_status = gr.Textbox(label="保存結果", interactive=False)
|
179 |
+
|
180 |
+
with gr.Column(scale=1):
|
181 |
+
# プロンプト一覧
|
182 |
+
prompt_dropdown = gr.Dropdown(
|
183 |
+
choices=[],
|
184 |
+
label="📋 保存済みプロンプト一覧",
|
185 |
+
interactive=True
|
186 |
+
)
|
187 |
+
refresh_btn = gr.Button("🔄 一覧を更新")
|
188 |
+
load_btn = gr.Button("📥 選択したプロンプトを読み込み", variant="secondary")
|
189 |
+
delete_btn = gr.Button("🗑️ 選択したプロンプトを削除", variant="stop")
|
190 |
+
delete_status = gr.Textbox(label="削除結果", interactive=False)
|
191 |
+
|
192 |
+
# タブ2: コード生成
|
193 |
+
with gr.TabItem("⚡ コード生成"):
|
194 |
+
gr.Markdown("## ドキュメントからコード生成")
|
195 |
+
|
196 |
+
with gr.Row():
|
197 |
+
with gr.Column():
|
198 |
+
# ファイルアップロード
|
199 |
+
input_file = gr.File(label="📄 ドキュメントファイル")
|
200 |
+
|
201 |
+
# プロンプト表示・編集エリア
|
202 |
+
current_prompt = gr.Textbox(
|
203 |
+
label="📝 現在のプロンプト",
|
204 |
+
lines=15,
|
205 |
+
value="",
|
206 |
+
placeholder="上のタブでプロンプトを選択するか、直接入力してください..."
|
207 |
+
)
|
208 |
+
|
209 |
+
with gr.Column():
|
210 |
+
# 生成設定
|
211 |
+
folder_name = gr.Textbox(label="📁 出力フォルダ名", value="generated_code")
|
212 |
+
github_token = gr.Textbox(label="🔑 GitHub Token (任意)", type="password", value="")
|
213 |
+
|
214 |
+
# 生成ボタン
|
215 |
+
generate_btn = gr.Button("🚀 コード生成実行", variant="primary", size="lg")
|
216 |
+
|
217 |
+
# 結果表示
|
218 |
+
result_output = gr.Textbox(label="📤 生成結果", lines=10, interactive=False)
|
219 |
+
|
220 |
+
# イベントハンドラー
|
221 |
+
def handle_save_prompt(title, url, content):
|
222 |
+
if not title.strip() or not content.strip():
|
223 |
+
return "❌ タイトルとプロンプト内容は必須です"
|
224 |
+
return save_prompt(title, url, content)
|
225 |
+
|
226 |
+
def handle_refresh_list():
|
227 |
+
prompts = get_prompts()
|
228 |
+
choices = []
|
229 |
+
for prompt in prompts:
|
230 |
+
id_, title, url, created_at = prompt
|
231 |
+
display_text = f"[{id_}] {title} ({created_at[:10]})"
|
232 |
+
choices.append((display_text, str(id_)))
|
233 |
+
return gr.Dropdown(choices=choices, value=None)
|
234 |
+
|
235 |
+
def handle_load_prompt(selected_prompt):
|
236 |
+
if selected_prompt:
|
237 |
+
prompt_id = selected_prompt.split(']')[0][1:] # [1] から ] までを取得してIDを抽出
|
238 |
+
content = get_prompt_content(int(prompt_id))
|
239 |
+
return content
|
240 |
+
return ""
|
241 |
+
|
242 |
+
def handle_delete_prompt(selected_prompt):
|
243 |
+
if selected_prompt:
|
244 |
+
prompt_id = selected_prompt.split(']')[0][1:] # IDを抽出
|
245 |
+
return delete_prompt(int(prompt_id))
|
246 |
+
return "❌ プロンプトが選択されていません"
|
247 |
+
|
248 |
+
def handle_generate_code(file, prompt, folder, token):
|
249 |
+
if not prompt.strip():
|
250 |
+
return "❌ プロンプトが入力されていません"
|
251 |
+
return process_file(file, prompt, folder, token)
|
252 |
+
|
253 |
+
# イベント接続
|
254 |
+
save_btn.click(
|
255 |
+
handle_save_prompt,
|
256 |
+
inputs=[save_title, save_url, save_content],
|
257 |
+
outputs=[save_status]
|
258 |
+
)
|
259 |
+
|
260 |
+
refresh_btn.click(
|
261 |
+
handle_refresh_list,
|
262 |
+
outputs=[prompt_dropdown]
|
263 |
+
)
|
264 |
+
|
265 |
+
load_btn.click(
|
266 |
+
handle_load_prompt,
|
267 |
+
inputs=[prompt_dropdown],
|
268 |
+
outputs=[current_prompt]
|
269 |
+
)
|
270 |
+
|
271 |
+
delete_btn.click(
|
272 |
+
handle_delete_prompt,
|
273 |
+
inputs=[prompt_dropdown],
|
274 |
+
outputs=[delete_status]
|
275 |
+
)
|
276 |
+
|
277 |
+
generate_btn.click(
|
278 |
+
handle_generate_code,
|
279 |
+
inputs=[input_file, current_prompt, folder_name, github_token],
|
280 |
+
outputs=[result_output]
|
281 |
+
)
|
282 |
+
|
283 |
+
# ページ読み込み時にプロンプト一覧を初期化
|
284 |
+
gradio_interface.load(
|
285 |
+
handle_refresh_list,
|
286 |
+
outputs=[prompt_dropdown]
|
287 |
+
)
|
controllers/gra_03_programfromdocgas/programfromdocAI_fixed.py
ADDED
@@ -0,0 +1,298 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from mysite.libs.utilities import chat_with_interpreter, completion, process_file, no_process_file
|
3 |
+
from interpreter import interpreter
|
4 |
+
import mysite.interpreter.interpreter_config # インポートするだけで設定が適用されます
|
5 |
+
import sqlite3
|
6 |
+
import os
|
7 |
+
from datetime import datetime
|
8 |
+
from typing import List, Tuple, Optional
|
9 |
+
|
10 |
+
# データベース設定
|
11 |
+
DB_PATH = "prompts.db"
|
12 |
+
|
13 |
+
def init_db():
|
14 |
+
"""プロンプトデータベースの初期化"""
|
15 |
+
try:
|
16 |
+
conn = sqlite3.connect(DB_PATH)
|
17 |
+
cursor = conn.cursor()
|
18 |
+
|
19 |
+
cursor.execute('''
|
20 |
+
CREATE TABLE IF NOT EXISTS prompts (
|
21 |
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
22 |
+
title TEXT NOT NULL,
|
23 |
+
url TEXT,
|
24 |
+
content TEXT NOT NULL,
|
25 |
+
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
26 |
+
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
27 |
+
)
|
28 |
+
''')
|
29 |
+
|
30 |
+
# デフォルトプロンプトの追加(初回のみ)
|
31 |
+
cursor.execute('SELECT COUNT(*) FROM prompts')
|
32 |
+
if cursor.fetchone()[0] == 0:
|
33 |
+
default_prompt = """# gradio で miiboのナレッジに登録する画面の作成
|
34 |
+
gradio_interface interfacec name
|
35 |
+
|
36 |
+
# fastapi
|
37 |
+
gradio apiに接続するAPI
|
38 |
+
router で作成
|
39 |
+
|
40 |
+
1ファイルで作成
|
41 |
+
仕様書の作成
|
42 |
+
plantumlで図にする
|
43 |
+
|
44 |
+
#sample fastapi
|
45 |
+
import requests
|
46 |
+
import json
|
47 |
+
import os
|
48 |
+
|
49 |
+
from fastapi import APIRouter, HTTPException
|
50 |
+
from gradio_client import Client
|
51 |
+
|
52 |
+
router = APIRouter(prefix="/gradio", tags=["gradio"])
|
53 |
+
@router.get("/route/gradio")
|
54 |
+
|
55 |
+
def get_senario(id,res):
|
56 |
+
table = "LOG"
|
57 |
+
client = Client("kenken999/fastapi_django_main_live")
|
58 |
+
result = client.predict(
|
59 |
+
message="Hello!!",
|
60 |
+
request=0.95,
|
61 |
+
param_3=512,
|
62 |
+
api_name="/chat"
|
63 |
+
)
|
64 |
+
return result
|
65 |
+
"""
|
66 |
+
cursor.execute(
|
67 |
+
'INSERT INTO prompts (title, url, content) VALUES (?, ?, ?)',
|
68 |
+
('デフォルト:Gradio + FastAPI作成', 'https://example.com', default_prompt)
|
69 |
+
)
|
70 |
+
|
71 |
+
conn.commit()
|
72 |
+
conn.close()
|
73 |
+
print("✅ データベース初期化完了")
|
74 |
+
except Exception as e:
|
75 |
+
print(f"❌ データベース初期化エラー: {e}")
|
76 |
+
|
77 |
+
def save_prompt(title: str, url: str, content: str) -> str:
|
78 |
+
"""プロンプトを保存"""
|
79 |
+
try:
|
80 |
+
if not title.strip() or not content.strip():
|
81 |
+
return "❌ タイトルとプロンプト内容は必須です"
|
82 |
+
|
83 |
+
conn = sqlite3.connect(DB_PATH)
|
84 |
+
cursor = conn.cursor()
|
85 |
+
|
86 |
+
cursor.execute(
|
87 |
+
'INSERT INTO prompts (title, url, content) VALUES (?, ?, ?)',
|
88 |
+
(title.strip(), url.strip(), content.strip())
|
89 |
+
)
|
90 |
+
|
91 |
+
conn.commit()
|
92 |
+
conn.close()
|
93 |
+
print(f"✅ プロンプト保存: {title}")
|
94 |
+
return f"✅ プロンプト '{title}' を保存しました!"
|
95 |
+
except Exception as e:
|
96 |
+
print(f"❌ 保存エラー: {e}")
|
97 |
+
return f"❌ エラー: {str(e)}"
|
98 |
+
|
99 |
+
def get_prompts() -> List[Tuple]:
|
100 |
+
"""全プロンプトを取得"""
|
101 |
+
try:
|
102 |
+
conn = sqlite3.connect(DB_PATH)
|
103 |
+
cursor = conn.cursor()
|
104 |
+
|
105 |
+
cursor.execute('SELECT id, title, url, created_at FROM prompts ORDER BY created_at DESC')
|
106 |
+
prompts = cursor.fetchall()
|
107 |
+
|
108 |
+
conn.close()
|
109 |
+
print(f"✅ プロンプト取得: {len(prompts)}件")
|
110 |
+
return prompts
|
111 |
+
except Exception as e:
|
112 |
+
print(f"❌ プロンプト取得エラー: {e}")
|
113 |
+
return []
|
114 |
+
|
115 |
+
def get_prompt_content(prompt_id: int) -> str:
|
116 |
+
"""指定IDのプロンプト内容を取得"""
|
117 |
+
try:
|
118 |
+
conn = sqlite3.connect(DB_PATH)
|
119 |
+
cursor = conn.cursor()
|
120 |
+
|
121 |
+
cursor.execute('SELECT content FROM prompts WHERE id = ?', (prompt_id,))
|
122 |
+
result = cursor.fetchone()
|
123 |
+
|
124 |
+
conn.close()
|
125 |
+
return result[0] if result else ""
|
126 |
+
except Exception as e:
|
127 |
+
print(f"❌ プロンプト内容取得エラー: {e}")
|
128 |
+
return ""
|
129 |
+
|
130 |
+
def delete_prompt(prompt_id: int) -> str:
|
131 |
+
"""プロンプトを削除"""
|
132 |
+
try:
|
133 |
+
conn = sqlite3.connect(DB_PATH)
|
134 |
+
cursor = conn.cursor()
|
135 |
+
|
136 |
+
cursor.execute('DELETE FROM prompts WHERE id = ?', (prompt_id,))
|
137 |
+
|
138 |
+
if cursor.rowcount > 0:
|
139 |
+
conn.commit()
|
140 |
+
conn.close()
|
141 |
+
print(f"✅ プロンプト削除: ID {prompt_id}")
|
142 |
+
return "✅ プロンプトを削除しました"
|
143 |
+
else:
|
144 |
+
conn.close()
|
145 |
+
return "❌ プロンプトが見つかりません"
|
146 |
+
except Exception as e:
|
147 |
+
print(f"❌ 削除エラー: {e}")
|
148 |
+
return f"❌ 削除エラー: {str(e)}"
|
149 |
+
|
150 |
+
# データベース初期化
|
151 |
+
print("🗄️ データベースを初期化中...")
|
152 |
+
init_db()
|
153 |
+
|
154 |
+
def refresh_prompt_list():
|
155 |
+
"""プロンプト一覧を更新"""
|
156 |
+
prompts = get_prompts()
|
157 |
+
choices = []
|
158 |
+
for prompt in prompts:
|
159 |
+
id_, title, url, created_at = prompt
|
160 |
+
display_text = f"[{id_}] {title} ({created_at[:10]})"
|
161 |
+
choices.append((display_text, str(id_)))
|
162 |
+
return choices
|
163 |
+
|
164 |
+
# Gradioインターフェース作成
|
165 |
+
with gr.Blocks(title="🚀 プロンプト管理 & コード生成", theme=gr.themes.Soft()) as gradio_interface:
|
166 |
+
gr.Markdown("# 🚀 プロンプト管理 & ドキュメントからコード生成")
|
167 |
+
|
168 |
+
with gr.Tabs():
|
169 |
+
# タブ1: プロンプト管理
|
170 |
+
with gr.TabItem("📝 プロンプト管理"):
|
171 |
+
gr.Markdown("## プロンプトの保存・管理")
|
172 |
+
|
173 |
+
with gr.Row():
|
174 |
+
with gr.Column(scale=1):
|
175 |
+
# プロンプト保存フォーム
|
176 |
+
save_title = gr.Textbox(label="📋 タイトル", placeholder="例: FastAPI + Gradio作成プロンプト")
|
177 |
+
save_url = gr.Textbox(label="🔗 参考URL (任意)", placeholder="https://example.com")
|
178 |
+
save_content = gr.Textbox(
|
179 |
+
label="📝 プロンプト内容",
|
180 |
+
lines=10,
|
181 |
+
placeholder="プロンプトの内容を入力してください..."
|
182 |
+
)
|
183 |
+
save_btn = gr.Button("💾 プロンプトを保存", variant="primary")
|
184 |
+
save_status = gr.Textbox(label="保存結果", interactive=False)
|
185 |
+
|
186 |
+
with gr.Column(scale=1):
|
187 |
+
# プロンプト一覧
|
188 |
+
prompt_dropdown = gr.Dropdown(
|
189 |
+
choices=[],
|
190 |
+
label="📋 保存済みプロンプト一覧",
|
191 |
+
interactive=True
|
192 |
+
)
|
193 |
+
refresh_btn = gr.Button("🔄 一覧を更新")
|
194 |
+
load_btn = gr.Button("📥 選択したプロンプトを読み込み", variant="secondary")
|
195 |
+
delete_btn = gr.Button("🗑️ 選択したプロンプトを削除", variant="stop")
|
196 |
+
delete_status = gr.Textbox(label="削除結果", interactive=False)
|
197 |
+
|
198 |
+
# タブ2: コード生成
|
199 |
+
with gr.TabItem("⚡ コード生成"):
|
200 |
+
gr.Markdown("## ドキュメントからコード生成")
|
201 |
+
|
202 |
+
with gr.Row():
|
203 |
+
with gr.Column():
|
204 |
+
# ファイルアップロード
|
205 |
+
input_file = gr.File(label="📄 ドキュメントファイル")
|
206 |
+
|
207 |
+
# プロンプト表示・編集エリア
|
208 |
+
current_prompt = gr.Textbox(
|
209 |
+
label="📝 現在のプロンプト",
|
210 |
+
lines=15,
|
211 |
+
value="",
|
212 |
+
placeholder="上のタブでプロンプトを選択するか、直接入力してください..."
|
213 |
+
)
|
214 |
+
|
215 |
+
with gr.Column():
|
216 |
+
# 生成設定
|
217 |
+
folder_name = gr.Textbox(label="📁 出力フォルダ名", value="generated_code")
|
218 |
+
github_token = gr.Textbox(label="🔑 GitHub Token (任意)", type="password", value="")
|
219 |
+
|
220 |
+
# 生成ボタン
|
221 |
+
generate_btn = gr.Button("🚀 コード生成実行", variant="primary", size="lg")
|
222 |
+
|
223 |
+
# 結果表示
|
224 |
+
result_output = gr.Textbox(label="📤 生成結果", lines=10, interactive=False)
|
225 |
+
|
226 |
+
# イベントハンドラー
|
227 |
+
def handle_save_prompt(title, url, content):
|
228 |
+
result = save_prompt(title, url, content)
|
229 |
+
return result
|
230 |
+
|
231 |
+
def handle_refresh_list():
|
232 |
+
choices = refresh_prompt_list()
|
233 |
+
return gr.Dropdown(choices=choices, value=None)
|
234 |
+
|
235 |
+
def handle_load_prompt(selected_prompt):
|
236 |
+
if selected_prompt:
|
237 |
+
try:
|
238 |
+
prompt_id = selected_prompt.split(']')[0][1:] # [1] から ] までを取得してIDを抽出
|
239 |
+
content = get_prompt_content(int(prompt_id))
|
240 |
+
return content
|
241 |
+
except Exception as e:
|
242 |
+
print(f"❌ プロンプト読み込みエラー: {e}")
|
243 |
+
return ""
|
244 |
+
return ""
|
245 |
+
|
246 |
+
def handle_delete_prompt(selected_prompt):
|
247 |
+
if selected_prompt:
|
248 |
+
try:
|
249 |
+
prompt_id = selected_prompt.split(']')[0][1:] # IDを抽出
|
250 |
+
return delete_prompt(int(prompt_id))
|
251 |
+
except Exception as e:
|
252 |
+
print(f"❌ プロンプト削除エラー: {e}")
|
253 |
+
return f"❌ エラー: {str(e)}"
|
254 |
+
return "❌ プロンプトが選択されていません"
|
255 |
+
|
256 |
+
def handle_generate_code(file, prompt, folder, token):
|
257 |
+
if not prompt.strip():
|
258 |
+
return "❌ プロンプトが入力されていません"
|
259 |
+
try:
|
260 |
+
return process_file(file, prompt, folder, token)
|
261 |
+
except Exception as e:
|
262 |
+
return f"❌ コード生成エラー: {str(e)}"
|
263 |
+
|
264 |
+
# イベント接続
|
265 |
+
save_btn.click(
|
266 |
+
handle_save_prompt,
|
267 |
+
inputs=[save_title, save_url, save_content],
|
268 |
+
outputs=[save_status]
|
269 |
+
)
|
270 |
+
|
271 |
+
refresh_btn.click(
|
272 |
+
handle_refresh_list,
|
273 |
+
outputs=[prompt_dropdown]
|
274 |
+
)
|
275 |
+
|
276 |
+
load_btn.click(
|
277 |
+
handle_load_prompt,
|
278 |
+
inputs=[prompt_dropdown],
|
279 |
+
outputs=[current_prompt]
|
280 |
+
)
|
281 |
+
|
282 |
+
delete_btn.click(
|
283 |
+
handle_delete_prompt,
|
284 |
+
inputs=[prompt_dropdown],
|
285 |
+
outputs=[delete_status]
|
286 |
+
)
|
287 |
+
|
288 |
+
generate_btn.click(
|
289 |
+
handle_generate_code,
|
290 |
+
inputs=[input_file, current_prompt, folder_name, github_token],
|
291 |
+
outputs=[result_output]
|
292 |
+
)
|
293 |
+
|
294 |
+
# ページ読み込み時にプロンプト一覧を初期化
|
295 |
+
gradio_interface.load(
|
296 |
+
handle_refresh_list,
|
297 |
+
outputs=[prompt_dropdown]
|
298 |
+
)
|
controllers/gra_03_programfromdocs/lavelo.py
CHANGED
@@ -6,10 +6,150 @@ import duckdb
|
|
6 |
import gradio as gr
|
7 |
import psycopg2
|
8 |
from dataclasses import dataclass, field
|
9 |
-
from typing import List, Optional
|
10 |
from mysite.interpreter.process import no_process_file,process_file,process_nofile
|
11 |
#from controllers.gra_04_database.rides import test_set_lide
|
12 |
import requests
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
13 |
|
14 |
val = """
|
15 |
# 社員がプロフィールを登録・公開し、お互いに参照できるシステム
|
@@ -106,14 +246,112 @@ def send_to_google_chat(message: str):
|
|
106 |
def process_file_and_notify(*args, **kwargs):
|
107 |
result = process_nofile(*args, **kwargs)
|
108 |
send_to_google_chat(result)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
109 |
return result
|
110 |
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6 |
import gradio as gr
|
7 |
import psycopg2
|
8 |
from dataclasses import dataclass, field
|
9 |
+
from typing import List, Optional, Tuple
|
10 |
from mysite.interpreter.process import no_process_file,process_file,process_nofile
|
11 |
#from controllers.gra_04_database.rides import test_set_lide
|
12 |
import requests
|
13 |
+
import sqlite3
|
14 |
+
import os
|
15 |
+
from datetime import datetime
|
16 |
+
|
17 |
+
# データベース設定
|
18 |
+
DB_PATH = "prompts.db"
|
19 |
+
|
20 |
+
def init_db():
|
21 |
+
"""プロンプトデータベースの初期化"""
|
22 |
+
try:
|
23 |
+
conn = sqlite3.connect(DB_PATH)
|
24 |
+
cursor = conn.cursor()
|
25 |
+
|
26 |
+
cursor.execute('''
|
27 |
+
CREATE TABLE IF NOT EXISTS prompts (
|
28 |
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
29 |
+
title TEXT NOT NULL,
|
30 |
+
url TEXT,
|
31 |
+
content TEXT NOT NULL,
|
32 |
+
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
33 |
+
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
34 |
+
)
|
35 |
+
''')
|
36 |
+
|
37 |
+
# デフォルトプロンプトの追加(初回のみ)
|
38 |
+
cursor.execute('SELECT COUNT(*) FROM prompts')
|
39 |
+
if cursor.fetchone()[0] == 0:
|
40 |
+
default_prompts = [
|
41 |
+
("社員プロフィールシステム", "", val),
|
42 |
+
("FastAPI + SQLAlchemy", "", "FastAPIとSQLAlchemyを使用したAPIの作成\n- ユーザー管理\n- 認証機能\n- CRUD操作"),
|
43 |
+
("Gradio Interface", "", "Gradioインターフェースの作成\n- ファイルアップロード\n- チャット機能\n- データ表示"),
|
44 |
+
]
|
45 |
+
|
46 |
+
for title, url, content in default_prompts:
|
47 |
+
cursor.execute(
|
48 |
+
'INSERT INTO prompts (title, url, content) VALUES (?, ?, ?)',
|
49 |
+
(title, url, content)
|
50 |
+
)
|
51 |
+
|
52 |
+
conn.commit()
|
53 |
+
conn.close()
|
54 |
+
print("✅ プロンプトデータベース初期化完了")
|
55 |
+
|
56 |
+
except Exception as e:
|
57 |
+
print(f"❌ データベース初期化エラー: {e}")
|
58 |
+
|
59 |
+
def save_prompt(title: str, content: str) -> str:
|
60 |
+
"""プロンプトを保存"""
|
61 |
+
try:
|
62 |
+
if not title.strip() or not content.strip():
|
63 |
+
return "❌ タイトルと内容は必須です"
|
64 |
+
|
65 |
+
conn = sqlite3.connect(DB_PATH)
|
66 |
+
cursor = conn.cursor()
|
67 |
+
|
68 |
+
cursor.execute(
|
69 |
+
'INSERT INTO prompts (title, url, content) VALUES (?, ?, ?)',
|
70 |
+
(title.strip(), "", content.strip())
|
71 |
+
)
|
72 |
+
|
73 |
+
conn.commit()
|
74 |
+
conn.close()
|
75 |
+
print(f"✅ プロンプト保存: {title}")
|
76 |
+
return f"✅ プロンプト「{title}」を保存しました"
|
77 |
+
|
78 |
+
except Exception as e:
|
79 |
+
print(f"❌ プロンプト保存エラー: {e}")
|
80 |
+
return f"❌ 保存エラー: {e}"
|
81 |
+
|
82 |
+
def get_prompts() -> List[Tuple]:
|
83 |
+
"""全プロンプトを取得"""
|
84 |
+
try:
|
85 |
+
conn = sqlite3.connect(DB_PATH)
|
86 |
+
cursor = conn.cursor()
|
87 |
+
|
88 |
+
cursor.execute('SELECT id, title, created_at FROM prompts ORDER BY created_at DESC')
|
89 |
+
prompts = cursor.fetchall()
|
90 |
+
|
91 |
+
conn.close()
|
92 |
+
print(f"✅ プロンプト取得: {len(prompts)}件")
|
93 |
+
return prompts
|
94 |
+
except Exception as e:
|
95 |
+
print(f"❌ プロンプト取得エラー: {e}")
|
96 |
+
return []
|
97 |
+
|
98 |
+
def get_prompt_content(prompt_id: int) -> str:
|
99 |
+
"""指定IDのプロンプト内容を取得"""
|
100 |
+
try:
|
101 |
+
conn = sqlite3.connect(DB_PATH)
|
102 |
+
cursor = conn.cursor()
|
103 |
+
|
104 |
+
cursor.execute('SELECT content FROM prompts WHERE id = ?', (prompt_id,))
|
105 |
+
result = cursor.fetchone()
|
106 |
+
|
107 |
+
conn.close()
|
108 |
+
|
109 |
+
if result:
|
110 |
+
print(f"✅ プロンプト内容取得: ID {prompt_id}")
|
111 |
+
return result[0]
|
112 |
+
else:
|
113 |
+
print(f"❌ プロンプトが見つかりません: ID {prompt_id}")
|
114 |
+
return ""
|
115 |
+
|
116 |
+
except Exception as e:
|
117 |
+
print(f"❌ プロンプト内容取得エラー: {e}")
|
118 |
+
return ""
|
119 |
+
|
120 |
+
def delete_prompt(prompt_id: int) -> str:
|
121 |
+
"""プロンプトを削除"""
|
122 |
+
try:
|
123 |
+
conn = sqlite3.connect(DB_PATH)
|
124 |
+
cursor = conn.cursor()
|
125 |
+
|
126 |
+
cursor.execute('DELETE FROM prompts WHERE id = ?', (prompt_id,))
|
127 |
+
|
128 |
+
if cursor.rowcount > 0:
|
129 |
+
conn.commit()
|
130 |
+
conn.close()
|
131 |
+
print(f"✅ プロンプト削除: ID {prompt_id}")
|
132 |
+
return f"✅ プロンプト ID {prompt_id} を削除しました"
|
133 |
+
else:
|
134 |
+
conn.close()
|
135 |
+
return f"❌ プロンプト ID {prompt_id} が見つかりません"
|
136 |
+
|
137 |
+
except Exception as e:
|
138 |
+
print(f"❌ プロンプト削除エラー: {e}")
|
139 |
+
return f"❌ 削除エラー: {e}"
|
140 |
+
|
141 |
+
def update_prompt_display():
|
142 |
+
"""プロンプト一覧の表示を更新"""
|
143 |
+
prompts = get_prompts()
|
144 |
+
if prompts:
|
145 |
+
# テーブル形式でデータを準備
|
146 |
+
table_data = []
|
147 |
+
for prompt_id, title, created_at in prompts:
|
148 |
+
# 日時の表示を短くする
|
149 |
+
date_str = created_at[:16] if created_at else ""
|
150 |
+
table_data.append([prompt_id, title, date_str])
|
151 |
+
return table_data
|
152 |
+
return []
|
153 |
|
154 |
val = """
|
155 |
# 社員がプロフィールを登録・公開し、お互いに参照できるシステム
|
|
|
246 |
def process_file_and_notify(*args, **kwargs):
|
247 |
result = process_nofile(*args, **kwargs)
|
248 |
send_to_google_chat(result)
|
249 |
+
|
250 |
+
# プロンプト実行後、内容をデータベースに保存
|
251 |
+
try:
|
252 |
+
prompt_content = args[0] if args else ""
|
253 |
+
if prompt_content.strip():
|
254 |
+
# 実行されたプロンプトのタイトルを生成(最初の行または最初の50文字)
|
255 |
+
title_lines = prompt_content.strip().split('\n')
|
256 |
+
title = title_lines[0][:50] if title_lines[0] else "実行されたプロンプト"
|
257 |
+
if title.startswith('#'):
|
258 |
+
title = title[1:].strip()
|
259 |
+
|
260 |
+
save_prompt(f"実行履歴: {title}", prompt_content)
|
261 |
+
except Exception as e:
|
262 |
+
print(f"実行履歴保存エラー: {e}")
|
263 |
+
|
264 |
return result
|
265 |
|
266 |
+
def load_prompt_to_textbox(evt: gr.SelectData):
|
267 |
+
"""テーブルクリック時にプロンプト内容をテキストボックスに読み込む"""
|
268 |
+
try:
|
269 |
+
if evt.index is not None and len(evt.index) >= 2:
|
270 |
+
# テーブルの行インデックスから prompt_id を取得
|
271 |
+
prompts = get_prompts()
|
272 |
+
if evt.index[0] < len(prompts):
|
273 |
+
prompt_id = prompts[evt.index[0]][0] # 最初の列がID
|
274 |
+
content = get_prompt_content(prompt_id)
|
275 |
+
return content
|
276 |
+
except Exception as e:
|
277 |
+
print(f"プロンプト読み込みエラー: {e}")
|
278 |
+
return ""
|
279 |
+
|
280 |
+
# データベース初期化
|
281 |
+
init_db()
|
282 |
+
|
283 |
+
with gr.Blocks() as gradio_interface:
|
284 |
+
gr.Markdown("# プロンプト管理システム")
|
285 |
+
|
286 |
+
with gr.Row():
|
287 |
+
with gr.Column(scale=1):
|
288 |
+
gr.Markdown("## 📚 プロンプト一覧")
|
289 |
+
|
290 |
+
# プロンプト一覧テーブル
|
291 |
+
prompt_table = gr.Dataframe(
|
292 |
+
headers=["ID", "タイトル", "作成日時"],
|
293 |
+
datatype=["number", "str", "str"],
|
294 |
+
value=update_prompt_display(),
|
295 |
+
interactive=False,
|
296 |
+
height=300
|
297 |
+
)
|
298 |
+
|
299 |
+
# 更新ボタン
|
300 |
+
refresh_btn = gr.Button("🔄 一覧更新", variant="secondary")
|
301 |
+
|
302 |
+
# プロンプト保存エリア
|
303 |
+
gr.Markdown("## 💾 プロンプト保存")
|
304 |
+
with gr.Row():
|
305 |
+
save_title = gr.Textbox(label="タイトル", placeholder="プロンプトのタイトルを入力")
|
306 |
+
save_btn = gr.Button("💾 保存", variant="primary")
|
307 |
+
save_result = gr.Textbox(label="保存結果", interactive=False)
|
308 |
+
|
309 |
+
with gr.Column(scale=2):
|
310 |
+
gr.Markdown("## ⚡ プロンプト実行")
|
311 |
+
|
312 |
+
# メインのプロンプト入力エリア
|
313 |
+
prompt_input = gr.Textbox(
|
314 |
+
label="プロンプト内容",
|
315 |
+
lines=15,
|
316 |
+
value=val,
|
317 |
+
placeholder="プロンプトを入力するか、左の一覧からクリックして選択してください"
|
318 |
+
)
|
319 |
+
|
320 |
+
with gr.Row():
|
321 |
+
folder_name = gr.Textbox(label="フォルダ名", value="test_folders")
|
322 |
+
github_token = gr.Textbox(label="GitHub Token", value="***********************", type="password")
|
323 |
+
|
324 |
+
execute_btn = gr.Button("🚀 実行", variant="primary", size="lg")
|
325 |
+
result_output = gr.Textbox(label="実行結果", lines=10, interactive=False)
|
326 |
+
|
327 |
+
# イベントハンドラー
|
328 |
+
prompt_table.select(
|
329 |
+
fn=load_prompt_to_textbox,
|
330 |
+
outputs=prompt_input
|
331 |
+
)
|
332 |
+
|
333 |
+
refresh_btn.click(
|
334 |
+
fn=update_prompt_display,
|
335 |
+
outputs=prompt_table
|
336 |
+
)
|
337 |
+
|
338 |
+
save_btn.click(
|
339 |
+
fn=lambda title, content: save_prompt(title, content),
|
340 |
+
inputs=[save_title, prompt_input],
|
341 |
+
outputs=save_result
|
342 |
+
).then(
|
343 |
+
fn=update_prompt_display,
|
344 |
+
outputs=prompt_table
|
345 |
+
).then(
|
346 |
+
fn=lambda: "",
|
347 |
+
outputs=save_title
|
348 |
+
)
|
349 |
+
|
350 |
+
execute_btn.click(
|
351 |
+
fn=process_file_and_notify,
|
352 |
+
inputs=[prompt_input, folder_name, github_token],
|
353 |
+
outputs=result_output
|
354 |
+
).then(
|
355 |
+
fn=update_prompt_display,
|
356 |
+
outputs=prompt_table
|
357 |
+
)
|
controllers/gradio_interface.py
ADDED
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from llamafactory.webui.interface import create_ui
|
3 |
+
|
4 |
+
def create_gradio_interface():
|
5 |
+
"""Gradio インターフェースを作成する"""
|
6 |
+
return create_ui()
|
7 |
+
|
8 |
+
# Gradio インターフェースを作成
|
9 |
+
with gr.Blocks() as gradio_interface:
|
10 |
+
# LlamaFactory UIを追加
|
11 |
+
llamafactory_demo = create_gradio_interface()
|
12 |
+
|
13 |
+
# LlamaFactory UIを現在のBlocksに統合
|
14 |
+
with gr.Row():
|
15 |
+
with gr.Column():
|
16 |
+
gr.HTML("""
|
17 |
+
<h2>🦙 LlamaFactory WebUI</h2>
|
18 |
+
<p>LlamaFactoryのWebUIインターフェースです</p>
|
19 |
+
""")
|
20 |
+
|
21 |
+
# LlamaFactory UIをマウント
|
22 |
+
llamafactory_demo.render()
|