root commited on
Commit
39f951c
·
1 Parent(s): ae12b30

📝 ドキュメント更新 (README 追記 & codex-rules.md, gMaL.md 追加)

Browse files
Files changed (2) hide show
  1. codex-rules.md +34 -0
  2. gMaL.md +451 -0
codex-rules.md ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ # タスク管理
3
+ ・ユーザから依頼された際、ユーザは何を求めているのかよく考え、これからやるべきことをtodo.mdにマークダウン形式に書き起こす
4
+ ・タスクとサブタスクの数は依頼内容によって判断してください
5
+
6
+ # 重要
7
+ ・mdファイルなどテキストファイルを出力する場合は、文字エンコーディングが正しく変換してください
8
+ ・テキストファイルにはバイナリデータを混入しないでください
9
+
10
+ ~~~
11
+
12
+ # 〇〇タスク
13
+
14
+ ## タスク名1
15
+ - [ ] サブタスク1
16
+ - [ ] サブタスク2
17
+ - [ ] サブタスク3
18
+
19
+ ・そのタスクリストに沿ってタスクを実行してください、終わったタスクは
20
+ - [x] タスク のようにtodo.mdを更新すること
21
+ ~~~
22
+
23
+ ・調査タスクは調査し、実装タスクは実装してください
24
+ ・調査タスクは調査結果に基づいて、ユーザ要件を満たすために深堀りする必要がある かを考え、調査すべき内容とタスクの変更をtodo.mdに更新すること
25
+ ・更新されたタスクに基づいて続けて実施してください
26
+
27
+ # 開発環境
28
+
29
+ ・Ubuntu 22.04.5 LTS
30
+ ・node -v : v20.19.0
31
+ ・uv -V : uv 0.6.10
32
+ ・python3 -V : Python 3.12.8
33
+ ・pythonで開発する場合はuvで仮想環境を作ること
34
+
gMaL.md ADDED
@@ -0,0 +1,451 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Gradio MCP の サンプルリポジトリ: gradio-mcp-codex-template
2
+
3
+ ```plaintext
4
+ OS: posix
5
+ Directory: /root/prj/gradio-mcp-codex-template
6
+
7
+ ├── .github/
8
+ │ └── workflows/
9
+ │ └── sync-to-hf.yml
10
+ ├── .env.example
11
+ ├── .SourceSageignore
12
+ ├── app.py
13
+ ├── gMaL.md
14
+ ├── README.md
15
+ └── requirements.txt
16
+ ```
17
+
18
+ ## 📂 Gitリポジトリ情報
19
+
20
+ ### 🌐 基本情報
21
+
22
+ - 🔗 リモートURL: https://github.com/Sunwood-ai-labs/gradio-mcp-codex-template.git
23
+ - 🌿 デフォルトブランチ: main
24
+ - 🎯 現在のブランチ: main
25
+ - 📅 作成日時: 2025-05-07 13:02:45
26
+ - 📈 総コミット数: 1
27
+
28
+ ### 🔄 最新のコミット
29
+
30
+ - 📝 メッセージ: Initial commit
31
+ - 🔍 ハッシュ: 1fe9b6d7
32
+ - 👤 作者: Maki ([email protected])
33
+ - ⏰ 日時: 2025-05-07 12:58:07
34
+
35
+ ### 👥 主要コントリビューター
36
+
37
+ | 👤 名前 | 📊 コミット数 |
38
+ |---------|-------------|
39
+ | Maki | 1 |
40
+
41
+ ## 📊 プロジェクト統計
42
+
43
+ - 📅 作成日時: 2025-05-07 13:06:43
44
+ - 📁 総ディレクトリ数: 2
45
+ - 📄 総ファイル数: 7
46
+ - 📏 最大深度: 2
47
+ - 📦 最大ディレクトリ: (9 エントリ)
48
+
49
+ ### 📊 ファイルサイズと行数
50
+
51
+ | ファイル | サイズ | 行数 | 言語 |
52
+ |----------|--------|------|------|
53
+ | README.md | 4.5 KB | 138 | markdown |
54
+ | app.py | 2.5 KB | 107 | python |
55
+ | .SourceSageignore | 691.0 B | 54 | plaintext |
56
+ | .github/workflows/sync-to-hf.yml | 605.0 B | 22 | yaml |
57
+ | .env.example | 347.0 B | 12 | plaintext |
58
+ | requirements.txt | 154.0 B | 6 | plaintext |
59
+ | gMaL.md | 0.0 B | 0 | markdown |
60
+ | **合計** | | **339** | |
61
+
62
+ ### 📈 言語別統計
63
+
64
+ | 言語 | ファイル数 | 総行数 | 合計サイズ |
65
+ |------|------------|--------|------------|
66
+ | markdown | 2 | 138 | 4.5 KB |
67
+ | python | 1 | 107 | 2.5 KB |
68
+ | plaintext | 3 | 72 | 1.2 KB |
69
+ | yaml | 1 | 22 | 605.0 B |
70
+
71
+ `.SourceSageignore`
72
+
73
+ **サイズ**: 691.0 B | **行数**: 54 行
74
+ ```plaintext
75
+ # バージョン管理システム関連
76
+ .git/
77
+ .gitignore
78
+
79
+ # キャッシュファイル
80
+ __pycache__/
81
+ .pytest_cache/
82
+ **/__pycache__/**
83
+ *.pyc
84
+
85
+ # ビルド・配布関連
86
+ build/
87
+ dist/
88
+ *.egg-info/
89
+
90
+ # 一時ファイル・出力
91
+ output/
92
+ output.md
93
+ test_output/
94
+ .SourceSageAssets/
95
+ .SourceSageAssetsDemo/
96
+
97
+ # アセット
98
+ *.png
99
+ *.svg
100
+ *.jpg
101
+ *.jepg
102
+ assets/
103
+
104
+ # その他
105
+ LICENSE
106
+ example/
107
+ package-lock.json
108
+ .DS_Store
109
+
110
+ # 特定のディレクトリを除外
111
+ tests/temp/
112
+ docs/drafts/
113
+
114
+ # パターンの例外(除外対象から除外)
115
+ !docs/important.md
116
+ !.github/workflows/
117
+ repository_summary.md
118
+
119
+ # Terraform関連
120
+ .terraform
121
+ *.terraform.lock.hcl
122
+ *.backup
123
+ *.tfstate
124
+
125
+ # Python仮想環境
126
+ venv
127
+ .venv
128
+ ```
129
+
130
+ `.env.example`
131
+
132
+ **サイズ**: 347.0 B | **行数**: 12 行
133
+ ```plaintext
134
+ ### .env.example
135
+ # 環境変数のサンプルファイル
136
+
137
+ # OpenAI APIキー
138
+ OPENAI_API_KEY=your_openai_api_key
139
+
140
+ # GitHub APIトークン(省略可: GitHub Actionsでは自動で提供されます)
141
+ GITHUB_TOKEN=your_github_token
142
+
143
+ # Codex挙動の設定
144
+ # 静粛モード: 1 に設定すると余分なログ出力を抑制
145
+ CODEX_QUIET_MODE=1
146
+ ```
147
+
148
+ `README.md`
149
+
150
+ **サイズ**: 4.5 KB | **行数**: 138 行
151
+ ```markdown
152
+ ---
153
+ title: Gradio MCP Minimal
154
+ emoji: 🌍
155
+ colorFrom: blue
156
+ colorTo: blue
157
+ sdk: gradio
158
+ sdk_version: 5.26.0
159
+ app_file: app.py
160
+ pinned: false
161
+ ---
162
+
163
+ <div align="center">
164
+
165
+ ![Image](https://github.com/user-attachments/assets/89233e89-d2e4-4e29-b1b8-fc5c90a7e4b2)
166
+
167
+
168
+ # 🚀 **Gradio MCP Minimal**
169
+
170
+ <p align="center">
171
+ <a href="https://www.python.org">
172
+ <img alt="Python" src="https://img.shields.io/badge/Python-3.12-blue?logo=python&logoColor=white">
173
+ </a>
174
+ <a href="https://www.gradio.app">
175
+ <img alt="Gradio" src="https://img.shields.io/badge/Gradio-5.26.0-orange?logo=gradio">
176
+ </a>
177
+ <a href="https://github.com/makiai/gradio-mcp-minimal/blob/main/LICENSE">
178
+ <img alt="License: MIT" src="https://img.shields.io/badge/License-MIT-green">
179
+ </a>
180
+ <a href="https://github.com/makiai/gradio-mcp-minimal/stargazers">
181
+ <img alt="GitHub Stars" src="https://img.shields.io/github/stars/makiai/gradio-mcp-minimal?style=social">
182
+ </a>
183
+ <a href="https://huggingface.co/spaces/MakiAi/gradio-mcp-minimal">
184
+ <img alt="HF Spaces" src="https://img.shields.io/badge/Spaces-Live%20Demo-blueviolet?logo=huggingface&logoColor=white">
185
+ </a>
186
+ </p>
187
+ </div>
188
+
189
+ ## ✨ 概要
190
+ このリポジトリは **最小構成** で Gradio アプリを立ち上げ、同時に **MCP (Model Context Protocol) サーバー** として機能させるサンプルです。
191
+ たった 1 つのファイルを実行するだけで、Web UI と MCP SSE エンドポイントの両方が手に入ります。
192
+
193
+ ## 📄 ファイル構成
194
+ | ファイル / ディレクトリ | 役割 |
195
+ |------------------------|------|
196
+ | `app.py` | Gradio UI + MCP サーバー(`letter_counter` ツール) |
197
+ | `requirements.txt` | 依存パッケ��ジ(`gradio[mcp]` のみ) |
198
+ | `assets/header.svg` | README 用ヘッダー画像(任意) |
199
+
200
+ ## 📦 セットアップ
201
+
202
+ ### 🚀 uv を使ったクイックスタート(推奨)
203
+
204
+ ```bash
205
+ # 仮想環境の作成
206
+ uv venv
207
+ # 仮想環境の有効化
208
+ source .venv/bin/activate
209
+ # 依存インストール
210
+ uv pip install -r requirements.txt
211
+ ```
212
+
213
+ ### 🐍 標準 pip のみで実行したい場合
214
+
215
+ ```bash
216
+ python -m venv .venv
217
+ source .venv/bin/activate
218
+ pip install -r requirements.txt
219
+ ```
220
+
221
+ ## 🚀 実行
222
+ 以下のコマンドを実行でローカルサーバーが起動します。
223
+ ```bash
224
+ python app.py
225
+ ```
226
+
227
+ - Web UI: <http://127.0.0.1:7860>
228
+ - MCP SSE エンドポイント: <http://127.0.0.1:7860/gradio_api/mcp/sse>
229
+ - UI フッター → **View API** → **MCP** をクリックすると、コピペ可能な設定 JSON が表示されます。
230
+
231
+ ## ⚙️ MCP クライアント設定例
232
+ Claude Desktop / Cline などで `claude_desktop_config.json` 等に追記:
233
+ ```jsonc
234
+ {
235
+ "mcpServers": {
236
+ "gradio-local": {
237
+ "url": "http://127.0.0.1:7860/gradio_api/mcp/sse"
238
+ }
239
+ }
240
+ }
241
+ ```
242
+ クライアントを再起動すると `letter_counter` ツールが利用できるようになります 🎉
243
+
244
+ ## 🔧 仕組み
245
+ ```python
246
+ demo.launch(mcp_server=True)
247
+ ```
248
+ この 1 行で Gradio アプリが SSE ベースの MCP サーバーとして動作します。
249
+ ドキュストリングと型ヒントから自動でスキーマが生成されます。
250
+
251
+ ## 🌠 拡張方法
252
+ 1. `app.py` に関数を追加し、適切なドキュストリングを記述
253
+ 2. `Interface(...)` へ登録(または Blocks を使用)
254
+ 3. 再起動すれば新しい MCP ツールとして自動公開
255
+
256
+ ## 🛫 🤗 Spaces へ無料デプロイ
257
+ ファイル一式を Hugging Face Spaces (Gradio テンプレート) へプッシュすると、無料の公開 MCP サーバーになります:
258
+ ```
259
+ https://<your-space>.hf.space/gradio_api/mcp/sse
260
+ ```
261
+ 例)`https://makiai-gradio-mcp-minimal.hf.space/gradio_api/mcp/sse`
262
+
263
+ ## 🔗 MCP クライアント設定例 (Spaces)
264
+
265
+ Spaces で公開したサーバーを **MCP クライアント(Claude Desktop / Cline など)** から呼び出す手順です。
266
+
267
+ 1. **エンドポイント URL**
268
+ ```
269
+ https://<your-space>.hf.space/gradio_api/mcp/sse
270
+ ```
271
+ 例)`https://makiai-gradio-mcp-minimal.hf.space/gradio_api/mcp/sse`
272
+
273
+ 2. **config 追記例** (`claude_desktop_config.json` 等)
274
+ ```jsonc
275
+ {
276
+ "mcpServers": {
277
+ "gradio-space": { // 任意の名前
278
+ "url": "https://makiai-gradio-mcp-minimal.hf.space/gradio_api/mcp/sse"
279
+ }
280
+ }
281
+ }
282
+ ```
283
+
284
+ 3. **動作確認**
285
+ クライアントを再起動 → Tool Palette で `server = gradio-space` を選択 →
286
+ `letter_counter` ツールに `text: "hello"` を送信し、`length: 5` が返れば接続完了です 🎉
287
+
288
+ ## 📝 ライセンス
289
+ MIT
290
+ ```
291
+
292
+ `app.py`
293
+
294
+ **サイズ**: 2.5 KB | **行数**: 107 行
295
+ ```python
296
+ import numpy as np
297
+ import gradio as gr
298
+ import qrcode
299
+ from PIL import Image
300
+ import io # Added for parity with user-provided snippet (currently unused)
301
+
302
+
303
+ def reverse_text(text):
304
+ """
305
+ テキストを反転する。
306
+
307
+ Args:
308
+ text (str): 反転したいテキスト。
309
+
310
+ Returns:
311
+ str: 反転されたテキスト。
312
+ """
313
+ return text[::-1]
314
+
315
+
316
+ def generate_qr_code(text):
317
+ """
318
+ テキストからQRコードを生成する。
319
+
320
+ Args:
321
+ text (str): QRコードに埋め込むテキスト。
322
+
323
+ Returns:
324
+ numpy.ndarray: 生成されたQRコード画像 (RGB)。
325
+ """
326
+ qr = qrcode.QRCode(version=5, box_size=10, border=5)
327
+ qr.add_data(text)
328
+ qr.make(fit=True)
329
+ img = qr.make_image(fill_color="black", back_color="white")
330
+
331
+ # PILイメージをNumPy配列に変換
332
+ img_array = np.array(img.convert("RGB"))
333
+ return img_array
334
+
335
+
336
+ def count_words(text):
337
+ """
338
+ テキストの単語数をカウントする。
339
+
340
+ Args:
341
+ text (str): カウントしたいテキスト。
342
+
343
+ Returns:
344
+ int: 単語数。
345
+ """
346
+ if not text.strip():
347
+ return 0
348
+ return len(text.split())
349
+
350
+
351
+ def resize_image(image, width, height):
352
+ """
353
+ 画像をリサイズする。
354
+
355
+ Args:
356
+ image (numpy.ndarray): リサイズしたい画像。
357
+ width (int): 新しい幅。
358
+ height (int): 新しい高さ。
359
+
360
+ Returns:
361
+ numpy.ndarray: リサイズされた画像 (RGB)。
362
+ """
363
+ # NumPy配列からPILイメージに変換
364
+ pil_image = Image.fromarray(image)
365
+
366
+ resized_image = pil_image.resize((int(width), int(height)))
367
+ return np.array(resized_image)
368
+
369
+
370
+ # --- Interface -----------------------------------------------------------
371
+
372
+ resize_interface = gr.Interface(
373
+ fn=resize_image,
374
+ inputs=[
375
+ gr.Image(),
376
+ gr.Number(label="幅", value=300),
377
+ gr.Number(label="高さ", value=300),
378
+ ],
379
+ outputs=gr.Image(),
380
+ api_name="resize_image",
381
+ )
382
+
383
+
384
+ demo = gr.TabbedInterface(
385
+ [
386
+ gr.Interface(reverse_text, gr.Textbox(), gr.Textbox(), api_name="reverse_text"),
387
+ gr.Interface(generate_qr_code, gr.Textbox(), gr.Image(), api_name="generate_qr_code"),
388
+ gr.Interface(count_words, gr.Textbox(), gr.Number(), api_name="count_words"),
389
+ resize_interface,
390
+ ],
391
+ [
392
+ "テキスト反転",
393
+ "QRコード生成",
394
+ "単語数カウント",
395
+ "画像リサイズ",
396
+ ],
397
+ )
398
+
399
+
400
+ if __name__ == "__main__":
401
+ # mcp_server=True starts the SSE endpoint at /gradio_api/mcp/sse
402
+ demo.launch(mcp_server=True)
403
+ ```
404
+
405
+ `gMaL.md`
406
+
407
+ **サイズ**: 0.0 B | **行数**: 0 行
408
+ ```markdown
409
+ (Empty file)
410
+ ```
411
+
412
+ `requirements.txt`
413
+
414
+ **サイズ**: 154.0 B | **行数**: 6 行
415
+ ```plaintext
416
+ gradio
417
+ numpy
418
+ qrcode[pil]
419
+ pillow
420
+ mcp
421
+ https://gradio-pypi-previews.s3.amazonaws.com/3b5cace94781b90993b596a83fb39fd1584d68ee/gradio-5.26.0-py3-none-any.whl
422
+ ```
423
+
424
+ `.github/workflows/sync-to-hf.yml`
425
+
426
+ **サイズ**: 605.0 B | **行数**: 22 行
427
+ ```yaml
428
+ name: Sync to Hugging Face hub
429
+ on:
430
+ push:
431
+ branches: [main]
432
+
433
+ # to run this workflow manually from the Actions tab
434
+ workflow_dispatch:
435
+
436
+ jobs:
437
+ sync-to-hub:
438
+ runs-on: ubuntu-latest
439
+ steps:
440
+ - uses: actions/checkout@v3
441
+ with:
442
+ fetch-depth: 0
443
+ lfs: true
444
+ - name: Push to hub
445
+ env:
446
+ HF_TOKEN: ${{ secrets.HF_TOKEN }}
447
+ run: |
448
+ git fetch https://MakiAi:[email protected]/spaces/MakiAi/gradio-mcp-template main || true
449
+ git push --force https://MakiAi:[email protected]/spaces/MakiAi/gradio-mcp-template main
450
+ ```
451
+