File size: 4,765 Bytes
70766d2 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 |
# ContBK インターフェース統合例
## 📋 概要
`controllers/contbk_example.py` は、`contbk` フォルダーにある全てのGradioインターフェースをタブ表示で統合する例です。
## 🚀 機能
### 📝 デモ機能
- **テキスト変換**: 大文字・小文字変換、文字数カウント、逆順変換
- **計算機**: 基本的な四則演算
- **リスト生成**: テキストから番号付きリスト、ブレットリスト、チェックリストを生成
### 🔧 ContBK統合機能
- **天気予報** (`gra_09_weather.weather`)
- **フロントエンド生成** (`gra_10_frontend.frontend_generator`)
- **マルチモーダル** (`gra_11_multimodal.image_to_ui`)
## 📂 ファイル構成
```
controllers/
├── contbk_example.py # メインの統合ダッシュボード
├── contbk_dashboard.py # 旧バージョン(参考用)
└── example_gradio_interface.py # 初期バージョン(参考用)
```
## 🔧 使用方法
### 1. スタンドアロン実行
```bash
cd /workspaces/fastapi_django_main_live
python controllers/contbk_example.py
```
サーバーが http://0.0.0.0:7864 で起動します。
### 2. メインアプリケーションに統合
```python
# mysite/asgimain.py などで
# インポート
from controllers.contbk_example import gradio_interface as contbk_dashboard
# 既存のタブに追加
existing_interfaces = [demo, create_ui(), democ, democs, appdb]
existing_names = ["AIで開発", "FineTuning", "Chat", "仕様書から作成", "DataBase"]
# ContBKダッシュボードを追加
all_interfaces = existing_interfaces + [contbk_dashboard]
all_names = existing_names + ["🎯 ContBK ダッシュボード"]
# タブ付きインターフェースを作成
tabs = gr.TabbedInterface(all_interfaces, all_names)
```
### 3. 個別インターフェースとして使用
```python
from controllers.contbk_example import (
create_demo_interfaces,
load_contbk_interfaces,
create_info_tab
)
# デモ機能のみ使用
demo_interfaces, demo_names = create_demo_interfaces()
# ContBK機能のみ使用
contbk_interfaces, contbk_names = load_contbk_interfaces()
# 情報タブのみ使用
info_tab = create_info_tab()
```
## 🎯 新しいインターフェースの追加
### ContBKフォルダーに新しいインターフェースを追加する方法
1. **新しいフォルダーを作成**
```
contbk/gra_XX_mynewfeature/
```
2. **Pythonファイルを作成**
```python
# contbk/gra_XX_mynewfeature/mynewfeature.py
import gradio as gr
def my_function(input_text):
return f"処理結果: {input_text}"
gradio_interface = gr.Interface(
fn=my_function,
inputs=gr.Textbox(label="入力"),
outputs=gr.Textbox(label="出力"),
title="新機能"
)
```
3. **自動検出設定の更新**
`contbk_example.py` の `stable_modules` リストに追加:
```python
stable_modules = [
("gra_09_weather.weather", "🌤️ 天気予報"),
("gra_10_frontend.frontend_generator", "🎨 フロントエンド生成"),
("gra_11_multimodal.image_to_ui", "🖼️ マルチモーダル"),
("gra_XX_mynewfeature.mynewfeature", "🆕 新機能"), # 追加
]
```
## 🔍 トラブルシューティング
### よくある問題
1. **ModuleNotFoundError: No module named 'mysite'**
- 原因: ContBKの一部モジュールがmysiteパッケージに依存
- 解決: `stable_modules` リストから該当モジュールを除外
2. **Port already in use**
- 原因: 指定したポートが既に使用中
- 解決: 別のポートを指定 (`server_port=7865` など)
3. **gradio_interface not found**
- 原因: モジュールに `gradio_interface` 変数が定義されていない
- 解決: モジュール内で正しく `gradio_interface` を定義
### デバッグ方法
```python
# モジュールのインポートテスト
python -c "
import sys
sys.path.insert(0, '/workspaces/fastapi_django_main_live/contbk')
import gra_XX_yourmodule.yourfile
print(hasattr(gra_XX_yourmodule.yourfile, 'gradio_interface'))
"
```
## 📊 パフォーマンス
- **起動時間**: 約5-10秒(ContBKモジュールの読み込み含む)
- **メモリ使用量**: 基本的な機能で約200MB
- **同時接続**: Gradioの標準制限に従う
## 🔗 関連ファイル
- `contbk/` - 統合対象のインターフェース群
- `mysite/routers/gradio.py` - 既存の動的読み込みシステム
- `app.py` - メインアプリケーション
- `FOLDER_STRUCTURE.md` - プロジェクト全体の構成
## 📝 ライセンス
このプロジェクトのライセンスに従います。
|