kenken999 commited on
Commit
94fac21
·
1 Parent(s): 3abf5d0
controllers/gra_01_chat/Chat.py ADDED
@@ -0,0 +1,115 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import shutil
2
+ import gradio as gr
3
+ from mysite.libs.utilities import chat_with_interpreter, completion, process_file
4
+ from interpreter import interpreter
5
+ import mysite.interpreter.interpreter_config # インポートするだけで設定が適用されます
6
+ import importlib
7
+ import os
8
+ import pkgutil
9
+ import async_timeout
10
+ import asyncio
11
+
12
+
13
+ DESCRIPTION = """
14
+ <div>
15
+ <h1 style="text-align: center;">develop site</h1>
16
+ <p>🦕 共同開発 AIシステム設定 LINE開発 CHATGPTS CHATGPTアシスタント設定 AI自動開発設定 APPSHEET GAS PYTHON</p>
17
+ </div>
18
+ <!-- Start of HubSpot Embed Code -->
19
+ <script type="text/javascript" id="hs-script-loader" async defer src="//js-na1.hs-scripts.com/46277896.js"></script>
20
+ <!-- End of HubSpot Embed Code -->
21
+ """
22
+
23
+ LICENSE = """
24
+ <p/>
25
+ <!-- Start of HubSpot Embed Code -->
26
+ <script type="text/javascript" id="hs-script-loader" async defer src="//js-na1.hs-scripts.com/46277896.js"></script>
27
+ <!-- End of HubSpot Embed Code -->
28
+ ---
29
+ Built with Meta Llama 3
30
+ """
31
+
32
+ PLACEHOLDER = """
33
+ <div style="padding: 30px; text-align: center; display: flex; flex-direction: column; align-items: center;">
34
+ <img src="https://ysharma-dummy-chat-app.hf.space/file=/tmp/gradio/8e75e61cc9bab22b7ce3dec85ab0e6db1da5d107/Meta_lockup_positive%20primary_RGB.jpg" style="width: 80%; max-width: 550px; height: auto; opacity: 0.55; ">
35
+ <h1 style="font-size: 28px; margin-bottom: 2px; opacity: 0.55;">Meta llama3</h1>
36
+ <p style="font-size: 18px; margin-bottom: 2px; opacity: 0.65;">Ask me anything...</p>
37
+ </div>
38
+ """
39
+
40
+
41
+ # チャットインターフェースの関数定義
42
+ # def chat_with_interpreter(message):
43
+ # return "Response: " + message
44
+
45
+
46
+ # カスタムCSSの定義
47
+ css = """
48
+ .gradio-container {
49
+ height: 100vh; /* 全体の高さを100vhに設定 */
50
+ display: flex;
51
+ flex-direction: column;
52
+ }
53
+ .gradio-tabs {
54
+ flex: 1; /* タブ全体の高さを最大に設定 */
55
+ display: flex;
56
+ flex-direction: column;
57
+ }
58
+ .gradio-tab-item {
59
+ flex: 1; /* 各タブの高さを最大に設定 */
60
+ display: flex;
61
+ flex-direction: column;
62
+ overflow: hidden; /* オーバーフローを隠す */
63
+ }
64
+ .gradio-block {
65
+ flex: 1; /* ブロックの高さを最大に設定 */
66
+ display: flex;
67
+ flex-direction: column;
68
+ }
69
+ .gradio-chatbot {
70
+ height: 100vh; /* チャットボットの高さを100vhに設定 */
71
+ overflow-y: auto; /* 縦スクロールを有効にする */
72
+ }
73
+ """
74
+ GENERATION_TIMEOUT_SEC = 60
75
+ # Gradio block
76
+ chatbot2 = gr.Chatbot(height=450, placeholder=PLACEHOLDER, label="Gradio ChatInterface")
77
+
78
+ with gr.Blocks(fill_height=True, css=css) as gradio_interface:
79
+ # gr.Markdown(DESCRIPTION)
80
+ # gr.DuplicateButton(value="Duplicate Space for private use", elem_id="duplicate-button")
81
+ gr.ChatInterface(
82
+ fn=completion,
83
+ chatbot=chatbot2,
84
+ fill_height=True,
85
+ additional_inputs_accordion=gr.Accordion(
86
+ label="⚙️ Parameters", open=False, render=False
87
+ ),
88
+ additional_inputs=[
89
+ gr.Slider(
90
+ minimum=0,
91
+ maximum=1,
92
+ step=0.1,
93
+ value=0.95,
94
+ label="Temperature",
95
+ render=False,
96
+ ),
97
+ gr.Slider(
98
+ minimum=128,
99
+ maximum=4096,
100
+ step=1,
101
+ value=512,
102
+ label="Max new tokens",
103
+ render=False,
104
+ ),
105
+ ],
106
+ examples=[
107
+ ["HTMLのサンプルを作成して"],
108
+ [
109
+ "CUDA_VISIBLE_DEVICES=0 llamafactory-cli train examples/lora_single_gpu/llama3_lora_sft.yaml"
110
+ ],
111
+ ],
112
+ cache_examples=False,
113
+ )
114
+
115
+ gr.Markdown(LICENSE)
controllers/gra_01_chat/__init__.py ADDED
File without changes
controllers/gra_02_openInterpreter/OpenInterpreter.py ADDED
@@ -0,0 +1,259 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 duckdb
6
+ #from logger import logger
7
+
8
+ def format_response(chunk, full_response):
9
+ # Message
10
+ if chunk["type"] == "message":
11
+ full_response += chunk.get("content", "")
12
+ if chunk.get("end", False):
13
+ full_response += "\n"
14
+
15
+ # Code
16
+ if chunk["type"] == "code":
17
+ if chunk.get("start", False):
18
+ full_response += "```python\n"
19
+ #full_response += chunk.get("content", "").replace("`", "")
20
+ if chunk.get("end", False):
21
+ full_response += "\n```\n"
22
+
23
+ # Output
24
+ if chunk["type"] == "confirmation":
25
+ if chunk.get("start", False):
26
+ full_response += "```python\n"
27
+ #full_response += chunk.get("content", {}).get("code", "")
28
+ if chunk.get("end", False):
29
+ full_response += "```\n"
30
+
31
+ # Console
32
+ if chunk["type"] == "console":
33
+ console_content = chunk.get("content", "")
34
+
35
+ # デバッグログ: console_content の内容と型を出力
36
+ print(f"Processing console content: {console_content}, type={type(console_content)}")
37
+
38
+ if not isinstance(console_content, str):
39
+ console_content = str(console_content)
40
+ print(f"Converted console_content to string: {console_content}")
41
+
42
+ # 不要な内容のフィルタリング
43
+ if console_content.isdigit() or console_content.strip().lower() == "none":
44
+ print(f"Skipping unwanted console content: {console_content}")
45
+ return full_response
46
+
47
+ # バッククオートを削除
48
+ console_content = console_content.replace("`", "")
49
+
50
+ # 言語タグなしでコードブロックを開始
51
+ if chunk.get("start", False):
52
+ full_response += "```python\n"
53
+
54
+ if chunk.get("format", "") == "active_line":
55
+ if not console_content.strip():
56
+ full_response += "No output available on console.\n"
57
+ else:
58
+ full_response += console_content.rstrip("\n") + "\n"
59
+ elif chunk.get("format", "") == "output":
60
+ full_response += console_content.rstrip("\n") + "\n"
61
+
62
+ if chunk.get("end", False):
63
+ full_response += "```\n"
64
+ # Image
65
+ if chunk["type"] == "image":
66
+ if chunk.get("start", False) or chunk.get("end", False):
67
+ full_response += "\n"
68
+ else:
69
+ image_format = chunk.get("format", "")
70
+ if image_format == "base64.png":
71
+ image_content = chunk.get("content", "")
72
+ if image_content:
73
+ image = Image.open(BytesIO(base64.b64decode(image_content)))
74
+ new_image = Image.new("RGB", image.size, "white")
75
+ new_image.paste(image, mask=image.split()[3])
76
+ buffered = BytesIO()
77
+ new_image.save(buffered, format="PNG")
78
+ img_str = base64.b64encode(buffered.getvalue()).decode()
79
+ full_response += f"![Image](data:image/png;base64,{img_str})\n"
80
+
81
+ return full_response
82
+
83
+ import sqlite3
84
+ from datetime import datetime
85
+
86
+ # SQLiteの設定
87
+ db_name = "chat_history.db"
88
+
89
+ def initialize_db():
90
+ conn = sqlite3.connect(db_name)
91
+ cursor = conn.cursor()
92
+ cursor.execute("""
93
+ CREATE TABLE IF NOT EXISTS history (
94
+ id INTEGER PRIMARY KEY AUTOINCREMENT,
95
+ role TEXT,
96
+ type TEXT,
97
+ content TEXT,
98
+ timestamp DATETIME DEFAULT CURRENT_TIMESTAMP
99
+ )
100
+ """)
101
+ conn.commit()
102
+ conn.close()
103
+
104
+ def add_message_to_db(role, message_type, content):
105
+ conn = sqlite3.connect(db_name)
106
+ cursor = conn.cursor()
107
+ cursor.execute("INSERT INTO history (role, type, content) VALUES (?, ?, ?)", (role, message_type, content))
108
+ conn.commit()
109
+ conn.close()
110
+
111
+ def get_recent_messages(limit=4):
112
+ conn = sqlite3.connect(db_name)
113
+ cursor = conn.cursor()
114
+ cursor.execute("SELECT role, type, content FROM history ORDER BY timestamp DESC LIMIT ?", (limit,))
115
+ messages = cursor.fetchall()
116
+ conn.close()
117
+ return messages[::-1] # 最新の20件を取得して逆順にする
118
+
119
+ def format_responses(chunk, full_response):
120
+ # This function will format the response from the interpreter
121
+ return full_response + chunk.get("content", "")
122
+
123
+ def chat_with_interpreter(message, history=None, a=None, b=None, c=None, d=None):
124
+ if message == "reset":
125
+ interpreter.reset()
126
+ return "Interpreter reset", history
127
+
128
+ full_response = ""
129
+ recent_messages = get_recent_messages(limit=4)
130
+
131
+ for role, message_type, content in recent_messages:
132
+ entry = {"role": role, "type": message_type, "content": content}
133
+ interpreter.messages.append(entry)
134
+
135
+ user_entry = {"role": "user", "type": "message", "content": message}
136
+ interpreter.messages.append(user_entry)
137
+ add_message_to_db("user", "message", message)
138
+
139
+ for chunk in interpreter.chat(message, display=False, stream=True):
140
+ if isinstance(chunk, dict):
141
+ full_response = format_response(chunk, full_response)
142
+ else:
143
+ raise TypeError("Expected chunk to be a dictionary")
144
+ print(full_response)
145
+ yield full_response
146
+
147
+ assistant_entry = {"role": "assistant", "type": "message", "content": full_response}
148
+ interpreter.messages.append(assistant_entry)
149
+ add_message_to_db("assistant", "message", full_response)
150
+
151
+ yield full_response
152
+ return full_response, history
153
+
154
+
155
+ def chat_with_interpreter_no_stream(message, history=None, a=None, b=None, c=None, d=None):
156
+ if message == "reset":
157
+ interpreter.reset()
158
+ return "Interpreter reset", history
159
+
160
+ full_response = ""
161
+ recent_messages = get_recent_messages()
162
+
163
+ for role, message_type, content in recent_messages:
164
+ entry = {"role": role, "type": message_type, "content": content}
165
+ interpreter.messages.append(entry)
166
+
167
+ user_entry = {"role": "user", "type": "message", "content": message}
168
+ interpreter.messages.append(user_entry)
169
+ add_message_to_db("user", "message", message)
170
+
171
+ chunks = interpreter.chat(message, display=False, stream=False)
172
+ for chunk in chunks:
173
+ if isinstance(chunk, dict):
174
+ full_response = format_response(chunk, full_response)
175
+ else:
176
+ raise TypeError("Expected chunk to be a dictionary")
177
+ #yield full_response
178
+ assistant_entry = {"role": "assistant", "type": "message", "content": str(full_response)}
179
+ interpreter.messages.append(assistant_entry)
180
+ add_message_to_db("assistant", "message", str(full_response))
181
+
182
+ #yield full_response
183
+ return str(full_response), history
184
+
185
+
186
+ # 初期化
187
+ initialize_db()
188
+
189
+
190
+ PLACEHOLDER = """
191
+ <div style="padding: 30px; text-align: center; display: flex; flex-direction: column; align-items: center;">
192
+ <img src="https://ysharma-dummy-chat-app.hf.space/file=/tmp/gradio/8e75e61cc9bab22b7ce3dec85ab0e6db1da5d107/Meta_lockup_positive%20primary_RGB.jpg" style="width: 80%; max-width: 550px; height: auto; opacity: 0.55; ">
193
+ <h1 style="font-size: 28px; margin-bottom: 2px; opacity: 0.55;">Meta llama3</h1>
194
+ <p style="font-size: 18px; margin-bottom: 2px; opacity: 0.65;">Ask me anything...</p>
195
+ </div>
196
+ """
197
+
198
+ chatbot = gr.Chatbot(height=450, placeholder=PLACEHOLDER, label="Gradio ChatInterface")
199
+
200
+
201
+
202
+ gradio_interface = gr.ChatInterface(
203
+ fn=chat_with_interpreter,
204
+ chatbot=chatbot,
205
+ fill_height=True,
206
+ additional_inputs_accordion=gr.Accordion(
207
+ label="⚙️ Parameters", open=False, render=False
208
+ ),
209
+ additional_inputs=[
210
+ gr.Slider(
211
+ minimum=0,
212
+ maximum=1,
213
+ step=0.1,
214
+ value=0.95,
215
+ label="Temperature",
216
+ render=False,
217
+ ),
218
+ gr.Slider(
219
+ minimum=128,
220
+ maximum=4096,
221
+ step=1,
222
+ value=512,
223
+ label="Max new tokens",
224
+ render=False,
225
+ ),
226
+
227
+ ],
228
+ # democs,
229
+ examples=[
230
+ ["HTMLのサンプルを作成して"],
231
+ [
232
+ "CUDA_VISIBLE_DEVICES=0 llamafactory-cli train examples/lora_single_gpu/llama3_lora_sft.yaml"
233
+ ],
234
+ ],
235
+ cache_examples=False,
236
+ )
237
+
238
+ if __name__ == '__main__':
239
+ message = f"""
240
+ postgres connection is this postgresql://miyataken999:[email protected]/neondb?sslmode=require
241
+ create this tabale
242
+ CREATE TABLE items (
243
+ id INT PRIMARY KEY,
244
+ brand_name VARCHAR(255),
245
+ model_name VARCHAR(255),
246
+ product_number VARCHAR(255),
247
+ purchase_store VARCHAR(255),
248
+ purchase_date DATE,
249
+ purchase_price INT,
250
+ accessories TEXT,
251
+ condition INT,
252
+ metal_type VARCHAR(255),
253
+ metal_weight DECIMAL(10, 2),
254
+ diamond_certification BLOB,
255
+ initial BOOLEAN
256
+ );
257
+
258
+ """
259
+ chat_with_interpreter(message)
controllers/gra_02_openInterpreter/__init__.py ADDED
File without changes
controllers/gra_02_openInterpreter/__isnit__.py ADDED
File without changes
controllers/gra_02_openInterpreter/chat_history.db ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:7303c1e0ea951f97da806d8ac895dfc40129da89294ae62bd8e993b45d3a6a64
3
+ size 16384
controllers/gra_03_programfromdoc/__init__.py ADDED
File without changes
controllers/gra_03_programfromdoc/programfromdoc.py ADDED
@@ -0,0 +1,103 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 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
11
+ #from controllers.gra_04_database.rides import test_set_lide
12
+
13
+ val = """
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
+ - 表示内容は、`ユーザー名`・`プロフィール`で、`プロフィール`は先頭10文字と三点リーダーを表示する。
48
+ - ユーザー名をクリックすると、そのユーザーのユーザー詳細画面へ遷移する。
49
+ - `チーム一覧へ`をクリックすると、チーム一覧画面へ遷移する。
50
+
51
+ ### ユーザー詳細画面
52
+
53
+ - 特定のユーザーの、`ユーザー名`・`所属チーム`・`プロフィール`・`タグ`が表示される。
54
+ - プロフィールの表示はマークダウンに対応させる。
55
+ - `一覧へ`リンクをクリックすると、ユーザー一覧画面へ遷移する。
56
+
57
+ ## あなたが作成するもの
58
+
59
+ バックエンドのプログラム一式を作成してください。
60
+ フロントエンドのプログラムは不要です。
61
+
62
+ - `/api`ディレクトリ以下に作成。
63
+ - Python/FastAPI/SQLAlchemyを使う。
64
+ - DBはSQLiteを使う。
65
+ - 必要に応じて外部ライブラリを使う。
66
+ - クラウドや外部サービス(外部API)は使わない。
67
+ - .gitignoreを含めること。
68
+ - バックエンド
69
+ @app.post("
70
+ def lumbda_function():
71
+
72
+ gradio_interface でメイン関数から読み込めるようにして
73
+
74
+ googleappsscript
75
+ ラインの画像検索システム
76
+
77
+ ファイルは1ファイルで作成して。
78
+ 1ファイル1機能で難しくしたくない
79
+
80
+ 1,lineからデータがくる
81
+ 2,doPostで取得
82
+ 3.typeがイメージの場合はドライブに保存
83
+ 4,保存したデータをS3にアップロード
84
+ 5.データはシークレットから取得
85
+ 6,plantumlでフローの作成
86
+ 7,システムドキュメントの作成
87
+
88
+ gradio は gradio_interface というBlock名で作成
89
+ fastapiはrouter の作成
90
+
91
+ """
92
+
93
+
94
+ gradio_interface = gr.Interface(
95
+ fn=process_file,
96
+ inputs=[
97
+ "file",
98
+ gr.Textbox(label="Additional Notes", lines=10,value=val),
99
+ gr.Textbox(label="Folder Name",value="test_folders"),
100
+ gr.Textbox(label="github token",value="***********************"),
101
+ ],
102
+ outputs="text",
103
+ )