kenken999 commited on
Commit
824093d
1 Parent(s): eb04712
mysite/routers/gradio.py CHANGED
@@ -9,7 +9,7 @@ import pkgutil
9
 
10
 
11
  def include_gradio_interfaces():
12
- package_dir = "/home/user/app/controllers"
13
  gradio_interfaces = []
14
  gradio_names = set()
15
 
@@ -41,7 +41,7 @@ def setup_gradio_interfaces():
41
 
42
  from babyagi.babyagi import gradio_babyagi
43
  default_interfaces = [gradio_babyagi]#,demo]
44
- default_names = ["TaskCreate","Chat","OpenInterpreter","DataBase","CreateFromDOC","babyagi"]#"demo"]
45
 
46
  gradio_interfaces, gradio_names = include_gradio_interfaces()
47
 
 
9
 
10
 
11
  def include_gradio_interfaces():
12
+ package_dir = "/home/user/app/routers"
13
  gradio_interfaces = []
14
  gradio_names = set()
15
 
 
41
 
42
  from babyagi.babyagi import gradio_babyagi
43
  default_interfaces = [gradio_babyagi]#,demo]
44
+ default_names = ["TaskCreate","Chat","OpenInterpreter","DataBase","CreateFromDOC","babyagi","FILES"]#"demo"]
45
 
46
  gradio_interfaces, gradio_names = include_gradio_interfaces()
47
 
routers/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)
routers/gra_01_chat/__init__.py ADDED
File without changes
routers/gra_02_openInterpreter/OpenInterpreter.py ADDED
@@ -0,0 +1,240 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ if chunk.get("start", False):
34
+ full_response += "```python\n"
35
+ if chunk.get("format", "") == "active_line":
36
+ console_content = chunk.get("content", "")
37
+ if console_content is None:
38
+ full_response += "No output available on console."
39
+ if chunk.get("format", "") == "output":
40
+ console_content = chunk.get("content", "")
41
+ full_response += console_content
42
+ if chunk.get("end", False):
43
+ full_response += "\n```\n"
44
+
45
+ # Image
46
+ if chunk["type"] == "image":
47
+ if chunk.get("start", False) or chunk.get("end", False):
48
+ full_response += "\n"
49
+ else:
50
+ image_format = chunk.get("format", "")
51
+ if image_format == "base64.png":
52
+ image_content = chunk.get("content", "")
53
+ if image_content:
54
+ image = Image.open(BytesIO(base64.b64decode(image_content)))
55
+ new_image = Image.new("RGB", image.size, "white")
56
+ new_image.paste(image, mask=image.split()[3])
57
+ buffered = BytesIO()
58
+ new_image.save(buffered, format="PNG")
59
+ img_str = base64.b64encode(buffered.getvalue()).decode()
60
+ full_response += f"![Image](data:image/png;base64,{img_str})\n"
61
+
62
+ return full_response
63
+
64
+ import sqlite3
65
+ from datetime import datetime
66
+
67
+ # SQLiteの設定
68
+ db_name = "chat_history.db"
69
+
70
+ def initialize_db():
71
+ conn = sqlite3.connect(db_name)
72
+ cursor = conn.cursor()
73
+ cursor.execute("""
74
+ CREATE TABLE IF NOT EXISTS history (
75
+ id INTEGER PRIMARY KEY AUTOINCREMENT,
76
+ role TEXT,
77
+ type TEXT,
78
+ content TEXT,
79
+ timestamp DATETIME DEFAULT CURRENT_TIMESTAMP
80
+ )
81
+ """)
82
+ conn.commit()
83
+ conn.close()
84
+
85
+ def add_message_to_db(role, message_type, content):
86
+ conn = sqlite3.connect(db_name)
87
+ cursor = conn.cursor()
88
+ cursor.execute("INSERT INTO history (role, type, content) VALUES (?, ?, ?)", (role, message_type, content))
89
+ conn.commit()
90
+ conn.close()
91
+
92
+ def get_recent_messages(limit=5):
93
+ conn = sqlite3.connect(db_name)
94
+ cursor = conn.cursor()
95
+ cursor.execute("SELECT role, type, content FROM history ORDER BY timestamp DESC LIMIT ?", (limit,))
96
+ messages = cursor.fetchall()
97
+ conn.close()
98
+ return messages[::-1] # 最新の20件を取得して逆順にする
99
+
100
+ def format_responses(chunk, full_response):
101
+ # This function will format the response from the interpreter
102
+ return full_response + chunk.get("content", "")
103
+
104
+ def chat_with_interpreter(message, history=None, a=None, b=None, c=None, d=None):
105
+ if message == "reset":
106
+ interpreter.reset()
107
+ return "Interpreter reset", history
108
+
109
+ full_response = ""
110
+ recent_messages = get_recent_messages()
111
+
112
+ for role, message_type, content in recent_messages:
113
+ entry = {"role": role, "type": message_type, "content": content}
114
+ interpreter.messages.append(entry)
115
+
116
+ user_entry = {"role": "user", "type": "message", "content": message}
117
+ interpreter.messages.append(user_entry)
118
+ add_message_to_db("user", "message", message)
119
+
120
+ for chunk in interpreter.chat(message, display=False, stream=True):
121
+ if isinstance(chunk, dict):
122
+ full_response = format_response(chunk, full_response)
123
+ else:
124
+ raise TypeError("Expected chunk to be a dictionary")
125
+ print(full_response)
126
+ yield full_response
127
+
128
+ assistant_entry = {"role": "assistant", "type": "message", "content": full_response}
129
+ interpreter.messages.append(assistant_entry)
130
+ add_message_to_db("assistant", "message", full_response)
131
+
132
+ yield full_response
133
+ return full_response, history
134
+
135
+
136
+ def chat_with_interpreter_no_stream(message, history=None, a=None, b=None, c=None, d=None):
137
+ if message == "reset":
138
+ interpreter.reset()
139
+ return "Interpreter reset", history
140
+
141
+ full_response = ""
142
+ recent_messages = get_recent_messages()
143
+
144
+ for role, message_type, content in recent_messages:
145
+ entry = {"role": role, "type": message_type, "content": content}
146
+ interpreter.messages.append(entry)
147
+
148
+ user_entry = {"role": "user", "type": "message", "content": message}
149
+ interpreter.messages.append(user_entry)
150
+ add_message_to_db("user", "message", message)
151
+
152
+ chunks = interpreter.chat(message, display=False, stream=False)
153
+ for chunk in chunks:
154
+ if isinstance(chunk, dict):
155
+ full_response = format_response(chunk, full_response)
156
+ else:
157
+ raise TypeError("Expected chunk to be a dictionary")
158
+ #yield full_response
159
+ assistant_entry = {"role": "assistant", "type": "message", "content": str(full_response)}
160
+ interpreter.messages.append(assistant_entry)
161
+ add_message_to_db("assistant", "message", str(full_response))
162
+
163
+ #yield full_response
164
+ return str(full_response), history
165
+
166
+
167
+ # 初期化
168
+ initialize_db()
169
+
170
+
171
+ PLACEHOLDER = """
172
+ <div style="padding: 30px; text-align: center; display: flex; flex-direction: column; align-items: center;">
173
+ <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; ">
174
+ <h1 style="font-size: 28px; margin-bottom: 2px; opacity: 0.55;">Meta llama3</h1>
175
+ <p style="font-size: 18px; margin-bottom: 2px; opacity: 0.65;">Ask me anything...</p>
176
+ </div>
177
+ """
178
+
179
+ chatbot = gr.Chatbot(height=450, placeholder=PLACEHOLDER, label="Gradio ChatInterface")
180
+
181
+
182
+
183
+ gradio_interfaces = gr.ChatInterface(
184
+ fn=chat_with_interpreter,
185
+ chatbot=chatbot,
186
+ fill_height=True,
187
+ additional_inputs_accordion=gr.Accordion(
188
+ label="⚙️ Parameters", open=False, render=False
189
+ ),
190
+ additional_inputs=[
191
+ gr.Slider(
192
+ minimum=0,
193
+ maximum=1,
194
+ step=0.1,
195
+ value=0.95,
196
+ label="Temperature",
197
+ render=False,
198
+ ),
199
+ gr.Slider(
200
+ minimum=128,
201
+ maximum=4096,
202
+ step=1,
203
+ value=512,
204
+ label="Max new tokens",
205
+ render=False,
206
+ ),
207
+ gr.Textbox(lines=2, placeholder="テキストを入力してください...", label="Text"),
208
+ ],
209
+ # democs,
210
+ examples=[
211
+ ["HTMLのサンプルを作成して"],
212
+ [
213
+ "CUDA_VISIBLE_DEVICES=0 llamafactory-cli train examples/lora_single_gpu/llama3_lora_sft.yaml"
214
+ ],
215
+ ],
216
+ cache_examples=False,
217
+ )
218
+
219
+ if __name__ == '__main__':
220
+ message = f"""
221
+ postgres connection is this postgresql://miyataken999:yz1wPf4KrWTm@ep-odd-mode-93794521.us-east-2.aws.neon.tech/neondb?sslmode=require
222
+ create this tabale
223
+ CREATE TABLE items (
224
+ id INT PRIMARY KEY,
225
+ brand_name VARCHAR(255),
226
+ model_name VARCHAR(255),
227
+ product_number VARCHAR(255),
228
+ purchase_store VARCHAR(255),
229
+ purchase_date DATE,
230
+ purchase_price INT,
231
+ accessories TEXT,
232
+ condition INT,
233
+ metal_type VARCHAR(255),
234
+ metal_weight DECIMAL(10, 2),
235
+ diamond_certification BLOB,
236
+ initial BOOLEAN
237
+ );
238
+
239
+ """
240
+ chat_with_interpreter(message)
routers/gra_02_openInterpreter/__init__.py ADDED
File without changes
routers/gra_02_openInterpreter/__isnit__.py ADDED
File without changes
routers/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
routers/gra_03_programfromdoc/__init__.py ADDED
File without changes
routers/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
+ )
routers/gra_04_database/.gpteng/memory/logs/all_output.txt ADDED
@@ -0,0 +1,298 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ 2024-06-07T12:30:21.592285
3
+ ================================ System Message ================================
4
+
5
+ You will get instructions for code to write.
6
+ You will write a very long answer. Make sure that every detail of the architecture is, in the end, implemented as code.
7
+ Think step by step and reason yourself to the correct decisions to make sure we get it right.
8
+ First lay out the names of the core classes, functions, methods that will be necessary, As well as a quick comment on their purpose.
9
+
10
+ You will output the content of each file necessary to achieve the goal, including ALL code.
11
+ Represent files like so:
12
+
13
+ FILENAME
14
+ ```
15
+ CODE
16
+ ```
17
+
18
+ The following tokens must be replaced like so:
19
+ FILENAME is the lowercase combined path and file name including the file extension
20
+ CODE is the code in the file
21
+
22
+ Example representation of a file:
23
+
24
+ src/hello_world.py
25
+ ```
26
+ print("Hello World")
27
+ ```
28
+
29
+ Do not comment on what every file does. Please note that the code should be fully functional. No placeholders.
30
+
31
+
32
+ You will start with the "entrypoint" file, then go to the ones that are imported by that file, and so on.
33
+ Please note that the code should be fully functional. No placeholders.
34
+
35
+ Follow a language and framework appropriate best practice file naming convention.
36
+ Make sure that files contain all imports, types etc. The code should be fully functional. Make sure that code in different files are compatible with each other.
37
+ Ensure to implement all code, if you are unsure, write a plausible implementation.
38
+ Include module dependency or package manager dependency definition file.
39
+ Before you finish, double check that all parts of the architecture is present in the files.
40
+
41
+ When you are done, write finish with "this concludes a fully working implementation".
42
+
43
+ Useful to know:
44
+ Almost always put different classes in different files.
45
+ Always use the programming language the user asks for.
46
+ For Python, you always create an appropriate requirements.txt file.
47
+ For NodeJS, you always create an appropriate package.json file.
48
+ Always add a comment briefly describing the purpose of the function definition.
49
+ Add comments explaining very complex bits of logic.
50
+ Always follow the best practices for the requested languages for folder/file structure and how to package the project.
51
+
52
+
53
+ Python toolbelt preferences:
54
+ - pytest
55
+ - dataclasses
56
+
57
+
58
+ ================================ Human Message =================================
59
+
60
+ Request: gradioで下記のpostgressのCRUD画面を作成して
61
+ postgresql://miyataken999:yz1wPf4KrWTm@ep-odd-mode-93794521.us-east-2.aws.neon.tech/neondb?sslmode=require
62
+
63
+ テーブルは下記
64
+ CREATE TABLE rides (
65
+ ride_id SERIAL PRIMARY KEY,
66
+ rideable_type VARCHAR(50) NOT NULL,
67
+ start_station_id INT,
68
+ start_station_name VARCHAR(255),
69
+ end_station_id INT,
70
+ end_station_name VARCHAR(255),
71
+ started_at VARCHAR(255),
72
+ ended_at VARCHAR(255),
73
+ member_casual VARCHAR(50) NOT NULL
74
+
75
+ ================================== Ai Message ==================================
76
+
77
+ Here is the implementation of a CRUD (Create, Read, Update, Delete) interface using Gradio and PostgreSQL.
78
+
79
+ **requirements.txt**
80
+ ```
81
+ gradio
82
+ psycopg2-binary
83
+ ```
84
+
85
+ **models/ride.py**
86
+ ```
87
+ from dataclasses import dataclass
88
+
89
+ @dataclass
90
+ class Ride:
91
+ ride_id: int
92
+ rideable_type: str
93
+ start_station_id: int
94
+ start_station_name: str
95
+ end_station_id: int
96
+ end_station_name: str
97
+ started_at: str
98
+ ended_at: str
99
+ member_casual: str
100
+ ```
101
+
102
+ **database.py**
103
+ ```
104
+ import psycopg2
105
+
106
+ def connect_to_db():
107
+ conn = psycopg2.connect(
108
+ dbname="neondb",
109
+ user="miyataken999",
110
+ password="yz1wPf4KrWTm",
111
+ host="ep-odd-mode-93794521.us-east-2.aws.neon.tech",
112
+ port=5432,
113
+ sslmode="require"
114
+ )
115
+ return conn
116
+
117
+ def create_ride(ride: Ride):
118
+ conn = connect_to_db()
119
+ cur = conn.cursor()
120
+ cur.execute("INSERT INTO rides (rideable_type, start_station_id, start_station_name, end_station_id, end_station_name, started_at, ended_at, member_casual) VALUES (%s, %s, %s, %s, %s, %s, %s, %s) RETURNING ride_id",
121
+ (ride.rideable_type, ride.start_station_id, ride.start_station_name, ride.end_station_id, ride.end_station_name, ride.started_at, ride.ended_at, ride.member_casual))
122
+ ride_id = cur.fetchone()[0]
123
+ conn.commit()
124
+ cur.close()
125
+ conn.close()
126
+ return ride_id
127
+
128
+ def read_rides():
129
+ conn = connect_to_db()
130
+ cur = conn.cursor()
131
+ cur.execute("SELECT * FROM rides")
132
+ rides = cur.fetchall()
133
+ conn.close()
134
+ return rides
135
+
136
+ def read_ride(ride_id: int):
137
+ conn = connect_to_db()
138
+ cur = conn.cursor()
139
+ cur.execute("SELECT * FROM rides WHERE ride_id = %s", (ride_id,))
140
+ ride = cur.fetchone()
141
+ conn.close()
142
+ return ride
143
+
144
+ def update_ride(ride: Ride):
145
+ conn = connect_to_db()
146
+ cur = conn.cursor()
147
+ cur.execute("UPDATE rides SET rideable_type = %s, start_station_id = %s, start_station_name = %s, end_station_id = %s, end_station_name = %s, started_at = %s, ended_at = %s, member_casual = %s WHERE ride_id = %s",
148
+ (ride.rideable_type, ride.start_station_id, ride.start_station_name, ride.end_station_id, ride.end_station_name, ride.started_at, ride.ended_at, ride.member_casual, ride.ride_id))
149
+ conn.commit()
150
+ cur.close()
151
+ conn.close()
152
+
153
+ def delete_ride(ride_id: int):
154
+ conn = connect_to_db()
155
+ cur = conn.cursor()
156
+ cur.execute("DELETE FROM rides WHERE ride_id = %s", (ride_id,))
157
+ conn.commit()
158
+ cur.close()
159
+ conn.close()
160
+ ```
161
+
162
+ **gradio_app.py**
163
+ ```
164
+ import gradio as gr
165
+ from models.ride import Ride
166
+ from database import create_ride, read_rides, read_ride, update_ride, delete_ride
167
+
168
+ def create_ride_interface():
169
+ with gr.Blocks() as create_ride_interface:
170
+ with gr.Row():
171
+ rideable_type = gr.Textbox(label="Rideable Type")
172
+ start_station_id = gr.Number(label="Start Station ID")
173
+ start_station_name = gr.Textbox(label="Start Station Name")
174
+ end_station_id = gr.Number(label="End Station ID")
175
+ end_station_name = gr.Textbox(label="End Station Name")
176
+ started_at = gr.Textbox(label="Started At")
177
+ ended_at = gr.Textbox(label="Ended At")
178
+ member_casual = gr.Textbox(label="Member Casual")
179
+ create_button = gr.Button("Create Ride")
180
+ output = gr.Textbox(label="Ride ID")
181
+
182
+ def create_ride_click(rideable_type, start_station_id, start_station_name, end_station_id, end_station_name, started_at, ended_at, member_casual):
183
+ ride = Ride(rideable_type, start_station_id, start_station_name, end_station_id, end_station_name, started_at, ended_at, member_casual)
184
+ ride_id = create_ride(ride)
185
+ return str(ride_id)
186
+
187
+ create_button.click(fn=create_ride_click, inputs=[rideable_type, start_station_id, start_station_name, end_station_id, end_station_name, started_at, ended_at, member_casual], outputs=output)
188
+
189
+ return create_ride_interface
190
+
191
+ def read_rides_interface():
192
+ with gr.Blocks() as read_rides_interface:
193
+ read_button = gr.Button("Read Rides")
194
+ output = gr.Dataframe(label="Rides")
195
+
196
+ def read_rides_click():
197
+ rides = read_rides()
198
+ return [rides]
199
+
200
+ read_button.click(fn=read_rides_click, outputs=output)
201
+
202
+ return read_rides_interface
203
+
204
+ def read_ride_interface():
205
+ with gr.Blocks() as read_ride_interface:
206
+ ride_id = gr.Number(label="Ride ID")
207
+ read_button = gr.Button("Read Ride")
208
+ output = gr.Dataframe(label="Ride")
209
+
210
+ def read_ride_click(ride_id):
211
+ ride = read_ride(ride_id)
212
+ return [ride]
213
+
214
+ read_button.click(fn=read_ride_click, inputs=[ride_id], outputs=output)
215
+
216
+ return read_ride_interface
217
+
218
+ def update_ride_interface():
219
+ with gr.Blocks() as update_ride_interface:
220
+ ride_id = gr.Number(label="Ride ID")
221
+ rideable_type = gr.Textbox(label="Rideable Type")
222
+ start_station_id = gr.Number(label="Start Station ID")
223
+ start_station_name = gr.Textbox(label="Start Station Name")
224
+ end_station_id = gr.Number(label="End Station ID")
225
+ end_station_name = gr.Textbox(label="End Station Name")
226
+ started_at = gr.Textbox(label="Started At")
227
+ ended_at = gr.Textbox(label="Ended At")
228
+ member_casual = gr.Textbox(label="Member Casual")
229
+ update_button = gr.Button("Update Ride")
230
+ output = gr.Textbox(label="Ride ID")
231
+
232
+ def update_ride_click(ride_id, rideable_type, start_station_id, start_station_name, end_station_id, end_station_name, started_at, ended_at, member_casual):
233
+ ride = Ride(ride_id, rideable_type, start_station_id, start_station_name, end_station_id, end_station_name, started_at, ended_at, member_casual)
234
+ update_ride(ride)
235
+ return str(ride_id)
236
+
237
+ update_button.click(fn=update_ride_click, inputs=[ride_id, rideable_type, start_station_id, start_station_name, end_station_id, end_station_name, started_at, ended_at, member_casual], outputs=output)
238
+
239
+ return update_ride_interface
240
+
241
+ def delete_ride_interface():
242
+ with gr.Blocks() as delete_ride_interface:
243
+ ride_id = gr.Number(label="Ride ID")
244
+ delete_button = gr.Button("Delete Ride")
245
+ output = gr.Textbox(label="Ride ID")
246
+
247
+ def delete_ride_click(ride_id):
248
+ delete_ride(ride_id)
249
+ return str(ride_id)
250
+
251
+ delete_button.click(fn=delete_ride_click, inputs=[ride_id], outputs=output)
252
+
253
+ return delete_ride_interface
254
+
255
+ if __name__ == "__main__":
256
+ create_ride_interface = create_ride_interface()
257
+ read_rides_interface = read_rides_interface()
258
+ read_ride_interface = read_ride_interface()
259
+ update_ride_interface = update_ride_interface()
260
+ delete_ride_interface = delete_ride_interface()
261
+
262
+ gr.Interface(
263
+ fn=create_ride_interface,
264
+ inputs="all",
265
+ outputs="all",
266
+ title="Create Ride"
267
+ ).launch()
268
+
269
+ gr.Interface(
270
+ fn=read_rides_interface,
271
+ inputs="all",
272
+ outputs="all",
273
+ title="Read Rides"
274
+ ).launch()
275
+
276
+ gr.Interface(
277
+ fn=read_ride_interface,
278
+ inputs="all",
279
+ outputs="all",
280
+ title="Read Ride"
281
+ ).launch()
282
+
283
+ gr.Interface(
284
+ fn=update_ride_interface,
285
+ inputs="all",
286
+ outputs="all",
287
+ title="Update Ride"
288
+ ).launch()
289
+
290
+ gr.Interface(
291
+ fn=delete_ride_interface,
292
+ inputs="all",
293
+ outputs="all",
294
+ title="Delete Ride"
295
+ ).launch()
296
+ ```
297
+
298
+ This concludes a fully working implementation.
routers/gra_04_database/.gpteng/memory/logs/gen_entrypoint_chat.txt ADDED
@@ -0,0 +1,241 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ 2024-06-07T12:30:47.038029
3
+ ================================ System Message ================================
4
+
5
+ You will get information about a codebase that is currently on disk in the current folder.
6
+ The user will ask you to write a script that runs the code in a specific way.
7
+ You will answer with code blocks that include all the necessary terminal commands.
8
+ Do not install globally. Do not use sudo.
9
+ Do not explain the code, just give the commands.
10
+ Do not use placeholders, use example values (like . for a folder argument) if necessary.
11
+
12
+
13
+ ================================ Human Message =================================
14
+
15
+
16
+ Make a unix script that
17
+ a) installs dependencies
18
+ b) runs all necessary parts of the codebase (in parallel if necessary)
19
+
20
+ Information about the codebase:
21
+
22
+ ```
23
+ File: requirements.txt
24
+ 1 gradio
25
+ 2 psycopg2-binary
26
+
27
+ File: models/ride.py
28
+ 1 from dataclasses import dataclass
29
+ 2
30
+ 3 @dataclass
31
+ 4 class Ride:
32
+ 5 ride_id: int
33
+ 6 rideable_type: str
34
+ 7 start_station_id: int
35
+ 8 start_station_name: str
36
+ 9 end_station_id: int
37
+ 10 end_station_name: str
38
+ 11 started_at: str
39
+ 12 ended_at: str
40
+ 13 member_casual: str
41
+
42
+ File: database.py
43
+ 1 import psycopg2
44
+ 2
45
+ 3 def connect_to_db():
46
+ 4 conn = psycopg2.connect(
47
+ 5 dbname="neondb",
48
+ 6 user="miyataken999",
49
+ 7 password="yz1wPf4KrWTm",
50
+ 8 host="ep-odd-mode-93794521.us-east-2.aws.neon.tech",
51
+ 9 port=5432,
52
+ 10 sslmode="require"
53
+ 11 )
54
+ 12 return conn
55
+ 13
56
+ 14 def create_ride(ride: Ride):
57
+ 15 conn = connect_to_db()
58
+ 16 cur = conn.cursor()
59
+ 17 cur.execute("INSERT INTO rides (rideable_type, start_station_id, start_station_name, end_station_id, end_station_name, started_at, ended_at, member_casual) VALUES (%s, %s, %s, %s, %s, %s, %s, %s) RETURNING ride_id",
60
+ 18 (ride.rideable_type, ride.start_station_id, ride.start_station_name, ride.end_station_id, ride.end_station_name, ride.started_at, ride.ended_at, ride.member_casual))
61
+ 19 ride_id = cur.fetchone()[0]
62
+ 20 conn.commit()
63
+ 21 cur.close()
64
+ 22 conn.close()
65
+ 23 return ride_id
66
+ 24
67
+ 25 def read_rides():
68
+ 26 conn = connect_to_db()
69
+ 27 cur = conn.cursor()
70
+ 28 cur.execute("SELECT * FROM rides")
71
+ 29 rides = cur.fetchall()
72
+ 30 conn.close()
73
+ 31 return rides
74
+ 32
75
+ 33 def read_ride(ride_id: int):
76
+ 34 conn = connect_to_db()
77
+ 35 cur = conn.cursor()
78
+ 36 cur.execute("SELECT * FROM rides WHERE ride_id = %s", (ride_id,))
79
+ 37 ride = cur.fetchone()
80
+ 38 conn.close()
81
+ 39 return ride
82
+ 40
83
+ 41 def update_ride(ride: Ride):
84
+ 42 conn = connect_to_db()
85
+ 43 cur = conn.cursor()
86
+ 44 cur.execute("UPDATE rides SET rideable_type = %s, start_station_id = %s, start_station_name = %s, end_station_id = %s, end_station_name = %s, started_at = %s, ended_at = %s, member_casual = %s WHERE ride_id = %s",
87
+ 45 (ride.rideable_type, ride.start_station_id, ride.start_station_name, ride.end_station_id, ride.end_station_name, ride.started_at, ride.ended_at, ride.member_casual, ride.ride_id))
88
+ 46 conn.commit()
89
+ 47 cur.close()
90
+ 48 conn.close()
91
+ 49
92
+ 50 def delete_ride(ride_id: int):
93
+ 51 conn = connect_to_db()
94
+ 52 cur = conn.cursor()
95
+ 53 cur.execute("DELETE FROM rides WHERE ride_id = %s", (ride_id,))
96
+ 54 conn.commit()
97
+ 55 cur.close()
98
+ 56 conn.close()
99
+
100
+ File: gradio_app.py
101
+ 1 import gradio as gr
102
+ 2 from models.ride import Ride
103
+ 3 from database import create_ride, read_rides, read_ride, update_ride, delete_ride
104
+ 4
105
+ 5 def create_ride_interface():
106
+ 6 with gr.Blocks() as create_ride_interface:
107
+ 7 with gr.Row():
108
+ 8 rideable_type = gr.Textbox(label="Rideable Type")
109
+ 9 start_station_id = gr.Number(label="Start Station ID")
110
+ 10 start_station_name = gr.Textbox(label="Start Station Name")
111
+ 11 end_station_id = gr.Number(label="End Station ID")
112
+ 12 end_station_name = gr.Textbox(label="End Station Name")
113
+ 13 started_at = gr.Textbox(label="Started At")
114
+ 14 ended_at = gr.Textbox(label="Ended At")
115
+ 15 member_casual = gr.Textbox(label="Member Casual")
116
+ 16 create_button = gr.Button("Create Ride")
117
+ 17 output = gr.Textbox(label="Ride ID")
118
+ 18
119
+ 19 def create_ride_click(rideable_type, start_station_id, start_station_name, end_station_id, end_station_name, started_at, ended_at, member_casual):
120
+ 20 ride = Ride(rideable_type, start_station_id, start_station_name, end_station_id, end_station_name, started_at, ended_at, member_casual)
121
+ 21 ride_id = create_ride(ride)
122
+ 22 return str(ride_id)
123
+ 23
124
+ 24 create_button.click(fn=create_ride_click, inputs=[rideable_type, start_station_id, start_station_name, end_station_id, end_station_name, started_at, ended_at, member_casual], outputs=output)
125
+ 25
126
+ 26 return create_ride_interface
127
+ 27
128
+ 28 def read_rides_interface():
129
+ 29 with gr.Blocks() as read_rides_interface:
130
+ 30 read_button = gr.Button("Read Rides")
131
+ 31 output = gr.Dataframe(label="Rides")
132
+ 32
133
+ 33 def read_rides_click():
134
+ 34 rides = read_rides()
135
+ 35 return [rides]
136
+ 36
137
+ 37 read_button.click(fn=read_rides_click, outputs=output)
138
+ 38
139
+ 39 return read_rides_interface
140
+ 40
141
+ 41 def read_ride_interface():
142
+ 42 with gr.Blocks() as read_ride_interface:
143
+ 43 ride_id = gr.Number(label="Ride ID")
144
+ 44 read_button = gr.Button("Read Ride")
145
+ 45 output = gr.Dataframe(label="Ride")
146
+ 46
147
+ 47 def read_ride_click(ride_id):
148
+ 48 ride = read_ride(ride_id)
149
+ 49 return [ride]
150
+ 50
151
+ 51 read_button.click(fn=read_ride_click, inputs=[ride_id], outputs=output)
152
+ 52
153
+ 53 return read_ride_interface
154
+ 54
155
+ 55 def update_ride_interface():
156
+ 56 with gr.Blocks() as update_ride_interface:
157
+ 57 ride_id = gr.Number(label="Ride ID")
158
+ 58 rideable_type = gr.Textbox(label="Rideable Type")
159
+ 59 start_station_id = gr.Number(label="Start Station ID")
160
+ 60 start_station_name = gr.Textbox(label="Start Station Name")
161
+ 61 end_station_id = gr.Number(label="End Station ID")
162
+ 62 end_station_name = gr.Textbox(label="End Station Name")
163
+ 63 started_at = gr.Textbox(label="Started At")
164
+ 64 ended_at = gr.Textbox(label="Ended At")
165
+ 65 member_casual = gr.Textbox(label="Member Casual")
166
+ 66 update_button = gr.Button("Update Ride")
167
+ 67 output = gr.Textbox(label="Ride ID")
168
+ 68
169
+ 69 def update_ride_click(ride_id, rideable_type, start_station_id, start_station_name, end_station_id, end_station_name, started_at, ended_at, member_casual):
170
+ 70 ride = Ride(ride_id, rideable_type, start_station_id, start_station_name, end_station_id, end_station_name, started_at, ended_at, member_casual)
171
+ 71 update_ride(ride)
172
+ 72 return str(ride_id)
173
+ 73
174
+ 74 update_button.click(fn=update_ride_click, inputs=[ride_id, rideable_type, start_station_id, start_station_name, end_station_id, end_station_name, started_at, ended_at, member_casual], outputs=output)
175
+ 75
176
+ 76 return update_ride_interface
177
+ 77
178
+ 78 def delete_ride_interface():
179
+ 79 with gr.Blocks() as delete_ride_interface:
180
+ 80 ride_id = gr.Number(label="Ride ID")
181
+ 81 delete_button = gr.Button("Delete Ride")
182
+ 82 output = gr.Textbox(label="Ride ID")
183
+ 83
184
+ 84 def delete_ride_click(ride_id):
185
+ 85 delete_ride(ride_id)
186
+ 86 return str(ride_id)
187
+ 87
188
+ 88 delete_button.click(fn=delete_ride_click, inputs=[ride_id], outputs=output)
189
+ 89
190
+ 90 return delete_ride_interface
191
+ 91
192
+ 92 if __name__ == "__main__":
193
+ 93 create_ride_interface = create_ride_interface()
194
+ 94 read_rides_interface = read_rides_interface()
195
+ 95 read_ride_interface = read_ride_interface()
196
+ 96 update_ride_interface = update_ride_interface()
197
+ 97 delete_ride_interface = delete_ride_interface()
198
+ 98
199
+ 99 gr.Interface(
200
+ 100 fn=create_ride_interface,
201
+ 101 inputs="all",
202
+ 102 outputs="all",
203
+ 103 title="Create Ride"
204
+ 104 ).launch()
205
+ 105
206
+ 106 gr.Interface(
207
+ 107 fn=read_rides_interface,
208
+ 108 inputs="all",
209
+ 109 outputs="all",
210
+ 110 title="Read Rides"
211
+ 111 ).launch()
212
+ 112
213
+ 113 gr.Interface(
214
+ 114 fn=read_ride_interface,
215
+ 115 inputs="all",
216
+ 116 outputs="all",
217
+ 117 title="Read Ride"
218
+ 118 ).launch()
219
+ 119
220
+ 120 gr.Interface(
221
+ 121 fn=update_ride_interface,
222
+ 122 inputs="all",
223
+ 123 outputs="all",
224
+ 124 title="Update Ride"
225
+ 125 ).launch()
226
+ 126
227
+ 127 gr.Interface(
228
+ 128 fn=delete_ride_interface,
229
+ 129 inputs="all",
230
+ 130 outputs="all",
231
+ 131 title="Delete Ride"
232
+ 132 ).launch()
233
+
234
+ ```
235
+
236
+ ================================== Ai Message ==================================
237
+
238
+ ```
239
+ python -m pip install -r requirements.txt
240
+ python gradio_app.py
241
+ ```
routers/gra_04_database/__init__.py ADDED
File without changes
routers/gra_04_database/models/ride.py ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from dataclasses import dataclass
2
+
3
+ @dataclass
4
+ class Ride:
5
+ rideable_type: str
6
+ start_station_id: int
7
+ end_station_id: int
8
+ ride_id: int = None
9
+ start_station_name: str = None
10
+ end_station_name: str = None
11
+ started_at: str = None
12
+ ended_at: str = None
13
+ member_casual: str = None
routers/gra_04_database/prompt ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ gradioで下記のpostgressのCRUD画面を作成して
2
+ postgresql://miyataken999:yz1wPf4KrWTm@ep-odd-mode-93794521.us-east-2.aws.neon.tech/neondb?sslmode=require
3
+
4
+ テーブルは下記
5
+ CREATE TABLE rides (
6
+ ride_id SERIAL PRIMARY KEY,
7
+ rideable_type VARCHAR(50) NOT NULL,
8
+ start_station_id INT,
9
+ start_station_name VARCHAR(255),
10
+ end_station_id INT,
11
+ end_station_name VARCHAR(255),
12
+ started_at VARCHAR(255),
13
+ ended_at VARCHAR(255),
14
+ member_casual VARCHAR(50) NOT NULL
routers/gra_04_database/requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ gradio
2
+ psycopg2-binary
routers/gra_04_database/rides.py ADDED
@@ -0,0 +1,164 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import psycopg2
3
+ from dataclasses import dataclass, field
4
+ from typing import List, Optional
5
+ from mysite.interpreter.process import no_process_file,process_file
6
+
7
+ @dataclass
8
+ class Ride:
9
+ ride_id: Optional[int] = field(default=None)
10
+ rideable_type: str = ''
11
+ start_station_id: int = 0
12
+ start_station_name: str = ''
13
+ end_station_id: int = 0
14
+ end_station_name: str = ''
15
+ started_at: str = ''
16
+ ended_at: str = ''
17
+ member_casual: str = ''
18
+
19
+ def connect_to_db():
20
+ conn = psycopg2.connect(
21
+ dbname="neondb",
22
+ user="miyataken999",
23
+ password="yz1wPf4KrWTm",
24
+ host="ep-odd-mode-93794521.us-east-2.aws.neon.tech",
25
+ port=5432,
26
+ sslmode="require"
27
+ )
28
+ return conn
29
+
30
+ def create_ride(ride: Ride):
31
+ conn = connect_to_db()
32
+ cur = conn.cursor()
33
+ cur.execute("INSERT INTO rides (rideable_type, start_station_id, start_station_name, end_station_id, end_station_name, started_at, ended_at, member_casual) VALUES (%s, %s, %s, %s, %s, %s, %s, %s) RETURNING ride_id",
34
+ (ride.rideable_type, ride.start_station_id, ride.start_station_name, ride.end_station_id, ride.end_station_name, ride.started_at, ride.ended_at, ride.member_casual))
35
+ ride_id = cur.fetchone()[0]
36
+ conn.commit()
37
+ cur.close()
38
+ conn.close()
39
+ return ride_id
40
+
41
+ def read_rides():
42
+ conn = connect_to_db()
43
+ cur = conn.cursor()
44
+ cur.execute("SELECT * FROM rides ORDER BY ride_id desc")
45
+ rides = cur.fetchall()
46
+ conn.close()
47
+ return rides
48
+
49
+ def read_ride(ride_id: int):
50
+ conn = connect_to_db()
51
+ cur = conn.cursor()
52
+ cur.execute("SELECT * FROM rides WHERE ride_id = %s", (ride_id,))
53
+ ride = cur.fetchone()
54
+ conn.close()
55
+ return ride
56
+
57
+ def update_ride(ride: Ride):
58
+ conn = connect_to_db()
59
+ cur = conn.cursor()
60
+ no_process_file(ride.start_station_name,ride.end_station_name)
61
+ cur.execute("UPDATE rides SET rideable_type = %s, start_station_id = %s, start_station_name = %s, end_station_id = %s, end_station_name = %s, started_at = %s, ended_at = %s, member_casual = %s WHERE ride_id = %s",
62
+ (ride.rideable_type, ride.start_station_id, ride.start_station_name, ride.end_station_id, ride.end_station_name, ride.started_at, ride.ended_at, ride.member_casual, ride.ride_id))
63
+ conn.commit()
64
+ cur.close()
65
+ conn.close()
66
+
67
+ def delete_ride(ride_id: int):
68
+ conn = connect_to_db()
69
+ cur = conn.cursor()
70
+ cur.execute("DELETE FROM rides WHERE ride_id = %s", (ride_id,))
71
+ conn.commit()
72
+ cur.close()
73
+ conn.close()
74
+
75
+ def test_set_lide(input="test",foldername="test"):
76
+ ride = Ride(
77
+ rideable_type="rideable_type",
78
+ start_station_name=input,
79
+ end_station_name=foldername,
80
+ )
81
+ create_ride(ride)
82
+ return [[r[0], r[1], r[2], r[3], r[4], r[5], r[6], r[7], r[8]] for r in read_rides()]
83
+
84
+
85
+ #def crud_interface():
86
+ with gr.Blocks() as gradio_interface:
87
+ with gr.Row():
88
+ rideable_type = gr.Textbox(label="Rideable Type")
89
+ start_station_id = gr.Number(label="Start Station ID")
90
+ start_station_name = gr.Textbox(label="Start Station Name")
91
+ end_station_id = gr.Number(label="End Station ID")
92
+ end_station_name = gr.Textbox(label="End Station Name")
93
+ started_at = gr.Textbox(label="Started At")
94
+ ended_at = gr.Textbox(label="Ended At")
95
+ member_casual = gr.Textbox(label="Member Casual")
96
+ ride_id = gr.Number(label="Ride ID (for update/delete)", value=-1, interactive=False)
97
+
98
+ create_button = gr.Button("Create Ride")
99
+ update_button = gr.Button("Update Ride")
100
+ delete_button = gr.Button("Delete Ride")
101
+ read_button = gr.Button("Read Rides")
102
+ output = gr.Dataframe(headers=["Ride ID", "Rideable Type", "Start Station ID", "Start Station Name", "End Station ID", "End Station Name", "Started At", "Ended At", "Member Casual"])
103
+
104
+ def create_ride_click(rideable_type, start_station_id, start_station_name, end_station_id, end_station_name, started_at, ended_at, member_casual):
105
+ ride = Ride(
106
+ rideable_type=rideable_type,
107
+ start_station_id=start_station_id,
108
+ start_station_name=start_station_name,
109
+ end_station_id=end_station_id,
110
+ end_station_name=end_station_name,
111
+ started_at=started_at,
112
+ ended_at=ended_at,
113
+ member_casual=member_casual
114
+ )
115
+ create_ride(ride)
116
+ return [[r[0], r[1], r[2], r[3], r[4], r[5], r[6], r[7], r[8]] for r in read_rides()]
117
+
118
+ def update_ride_click(ride_id, rideable_type, start_station_id, start_station_name, end_station_id, end_station_name, started_at, ended_at, member_casual):
119
+ ride = Ride(
120
+ ride_id=int(ride_id),
121
+ rideable_type=rideable_type,
122
+ start_station_id=start_station_id,
123
+ start_station_name=start_station_name,
124
+ end_station_id=end_station_id,
125
+ end_station_name=end_station_name,
126
+ started_at=started_at,
127
+ ended_at=ended_at,
128
+ member_casual=member_casual
129
+ )
130
+ update_ride(ride)
131
+ return [[r[0], r[1], r[2], r[3], r[4], r[5], r[6], r[7], r[8]] for r in read_rides()]
132
+
133
+ def delete_ride_click(ride_id):
134
+ delete_ride(int(ride_id))
135
+ return [[r[0], r[1], r[2], r[3], r[4], r[5], r[6], r[7], r[8]] for r in read_rides()]
136
+
137
+ def read_rides_click():
138
+ return [[r[0], r[1], r[2], r[3], r[4], r[5], r[6], r[7], r[8]] for r in read_rides()]
139
+
140
+ def load_ride_details(evt: gr.SelectData):
141
+ row_index = evt.index[0] if isinstance(evt.index, list) else evt.index
142
+ rides = read_rides()
143
+ selected_row = rides[row_index]
144
+ ride_id = selected_row[0]
145
+ ride = read_ride(ride_id)
146
+ if ride:
147
+ return ride[1], ride[2], ride[3], ride[4], ride[5], ride[6], ride[7], ride[8], ride[0]
148
+ return "", 0, "", 0, "", "", "", "", -1
149
+
150
+ create_button.click(fn=create_ride_click,
151
+ inputs=[rideable_type, start_station_id, start_station_name, end_station_id, end_station_name, started_at, ended_at, member_casual],
152
+ outputs=output)
153
+ update_button.click(fn=update_ride_click,
154
+ inputs=[ride_id, rideable_type, start_station_id, start_station_name, end_station_id, end_station_name, started_at, ended_at, member_casual],
155
+ outputs=output)
156
+ delete_button.click(fn=delete_ride_click, inputs=ride_id, outputs=output)
157
+ read_button.click(fn=read_rides_click, outputs=output)
158
+
159
+ output.select(fn=load_ride_details, inputs=None, outputs=[rideable_type, start_station_id, start_station_name, end_station_id, end_station_name, started_at, ended_at, member_casual, ride_id])
160
+
161
+ #return interface
162
+
163
+ #d1 = crud_interface()
164
+ #d1.launch()
routers/gra_04_database/run.sh ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ python -m pip install -r requirements.txt
2
+ python gradio_app.py
routers/gra_05_files/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 chat:
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)
routers/gra_05_files/files.py ADDED
@@ -0,0 +1,79 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ def list_files_in_directory(directory):
14
+ tree = []
15
+ for root, dirs, files in os.walk(directory):
16
+ path = root.split(os.sep)
17
+ for dir_name in dirs:
18
+ tree.append((os.path.join(root, dir_name), '/'.join(path + [dir_name])))
19
+ for file_name in files:
20
+ tree.append((os.path.join(root, file_name), '/'.join(path + [file_name])))
21
+ return tree
22
+
23
+ def read_file(file_path):
24
+ try:
25
+ with open(file_path, 'r', encoding='utf-8') as file:
26
+ return file.read()
27
+ except UnicodeDecodeError:
28
+ with open(file_path, 'rb') as file:
29
+ content = file.read()
30
+ try:
31
+ return content.decode('utf-8')
32
+ except UnicodeDecodeError:
33
+ try:
34
+ return content.decode('latin-1')
35
+ except UnicodeDecodeError:
36
+ return "Cannot decode file content with utf-8 or latin-1 encoding."
37
+
38
+ def save_file(file_path, content):
39
+ with open(file_path, 'w', encoding='utf-8') as file:
40
+ file.write(content)
41
+ return "File saved successfully"
42
+
43
+ def on_file_select(selected_file):
44
+ if os.path.isfile(selected_file):
45
+ return read_file(selected_file)
46
+ return ""
47
+
48
+ def build_interface(base_directory):
49
+ file_list = list_files_in_directory(base_directory)
50
+ file_display = [f[1] for f in file_list]
51
+ file_paths = {f[1]: f[0] for f in file_list}
52
+
53
+ with gr.Blocks() as demo:
54
+ gr.Markdown("## File Explorer and Editor")
55
+
56
+ file_dropdown = gr.Dropdown(label="Select a file or folder", choices=file_display)
57
+ file_editor = gr.Textbox(label="File Editor", lines=20)
58
+ save_button = gr.Button("Save File")
59
+
60
+ def update_editor(selected_display):
61
+ selected_file = file_paths.get(selected_display, "")
62
+ return on_file_select(selected_file)
63
+
64
+ def on_edit_button_click(selected_display, new_content):
65
+ selected_file = file_paths.get(selected_display, "")
66
+ if os.path.isfile(selected_file):
67
+ return save_file(selected_file, new_content)
68
+ return "File not found"
69
+
70
+ file_dropdown.change(fn=update_editor, inputs=file_dropdown, outputs=file_editor)
71
+ save_button.click(fn=on_edit_button_click, inputs=[file_dropdown, file_editor], outputs=None)
72
+
73
+ return demo
74
+
75
+
76
+
77
+
78
+ base_directory = "/home/user/app/routers" # Here you can specify any directory you want to explore
79
+ gradio_interface = build_interface(base_directory)
routers/gra_06_video/__init__.py ADDED
File without changes
routers/gra_06_video/video.py ADDED
@@ -0,0 +1,137 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python
2
+
3
+ from __future__ import annotations
4
+
5
+ import os
6
+ import random
7
+ import tempfile
8
+
9
+ import gradio as gr
10
+ import imageio
11
+ import numpy as np
12
+ import torch
13
+ from diffusers import DiffusionPipeline, DPMSolverMultistepScheduler
14
+
15
+ DESCRIPTION = '# [ModelScope Text to Video Synthesis](https://modelscope.cn/models/damo/text-to-video-synthesis/summary)'
16
+ DESCRIPTION += '\n<p>For Colab usage, you can view <a href="https://colab.research.google.com/drive/1uW1ZqswkQ9Z9bp5Nbo5z59cAn7I0hE6R?usp=sharing" style="text-decoration: underline;" target="_blank">this webpage</a>.(the latest update on 2023.03.21)</p>'
17
+ DESCRIPTION += '\n<p>This model can only be used for non-commercial purposes. To learn more about the model, take a look at the <a href="https://huggingface.co/damo-vilab/modelscope-damo-text-to-video-synthesis" style="text-decoration: underline;" target="_blank">model card</a>.</p>'
18
+ if (SPACE_ID := os.getenv('SPACE_ID')) is not None:
19
+ DESCRIPTION += f'\n<p>For faster inference without waiting in queue, you may duplicate the space and upgrade to GPU in settings. <a href="https://huggingface.co/spaces/{SPACE_ID}?duplicate=true"><img style="display: inline; margin-top: 0em; margin-bottom: 0em" src="https://bit.ly/3gLdBN6" alt="Duplicate Space" /></a></p>'
20
+
21
+ MAX_NUM_FRAMES = int(os.getenv('MAX_NUM_FRAMES', '200'))
22
+ DEFAULT_NUM_FRAMES = min(MAX_NUM_FRAMES,
23
+ int(os.getenv('DEFAULT_NUM_FRAMES', '16')))
24
+
25
+ pipe = DiffusionPipeline.from_pretrained('damo-vilab/text-to-video-ms-1.7b',
26
+ torch_dtype=torch.float16,
27
+ variant='fp16')
28
+ pipe.scheduler = DPMSolverMultistepScheduler.from_config(pipe.scheduler.config)
29
+ pipe.enable_model_cpu_offload()
30
+ pipe.enable_vae_slicing()
31
+
32
+
33
+ def to_video(frames: list[np.ndarray], fps: int) -> str:
34
+ out_file = tempfile.NamedTemporaryFile(suffix='.mp4', delete=False)
35
+ writer = imageio.get_writer(out_file.name, format='FFMPEG', fps=fps)
36
+ for frame in frames:
37
+ writer.append_data(frame)
38
+ writer.close()
39
+ return out_file.name
40
+
41
+
42
+ def generate(prompt: str, seed: int, num_frames: int,
43
+ num_inference_steps: int) -> str:
44
+ if seed == -1:
45
+ seed = random.randint(0, 1000000)
46
+ generator = torch.Generator().manual_seed(seed)
47
+ frames = pipe(prompt,
48
+ num_inference_steps=num_inference_steps,
49
+ num_frames=num_frames,
50
+ generator=generator).frames
51
+ return to_video(frames, 8)
52
+
53
+
54
+ examples = [
55
+ ['An astronaut riding a horse.', 0, 16, 25],
56
+ ['A panda eating bamboo on a rock.', 0, 16, 25],
57
+ ['Spiderman is surfing.', 0, 16, 25],
58
+ ]
59
+
60
+ with gr.Blocks(css='style.css') as gradio_interface:
61
+ gr.Markdown(DESCRIPTION)
62
+ with gr.Group():
63
+ with gr.Box():
64
+ with gr.Row(elem_id='prompt-container').style(equal_height=True):
65
+ prompt = gr.Text(
66
+ label='Prompt',
67
+ show_label=False,
68
+ max_lines=1,
69
+ placeholder='Enter your prompt',
70
+ elem_id='prompt-text-input').style(container=False)
71
+ run_button = gr.Button('Generate video').style(
72
+ full_width=False)
73
+ result = gr.Video(label='Result', show_label=False, elem_id='gallery')
74
+ with gr.Accordion('Advanced options', open=False):
75
+ seed = gr.Slider(
76
+ label='Seed',
77
+ minimum=-1,
78
+ maximum=1000000,
79
+ step=1,
80
+ value=-1,
81
+ info='If set to -1, a different seed will be used each time.')
82
+ num_frames = gr.Slider(
83
+ label='Number of frames',
84
+ minimum=16,
85
+ maximum=MAX_NUM_FRAMES,
86
+ step=1,
87
+ value=16,
88
+ info=
89
+ 'Note that the content of the video also changes when you change the number of frames.'
90
+ )
91
+ num_inference_steps = gr.Slider(label='Number of inference steps',
92
+ minimum=10,
93
+ maximum=50,
94
+ step=1,
95
+ value=25)
96
+
97
+ inputs = [
98
+ prompt,
99
+ seed,
100
+ num_frames,
101
+ num_inference_steps,
102
+ ]
103
+ gr.Examples(examples=examples,
104
+ inputs=inputs,
105
+ outputs=result,
106
+ fn=generate,
107
+ cache_examples=os.getenv('SYSTEM') == 'spaces')
108
+
109
+ prompt.submit(fn=generate, inputs=inputs, outputs=result)
110
+ run_button.click(fn=generate, inputs=inputs, outputs=result)
111
+
112
+
113
+ with gr.Accordion(label='We are hiring(Based in Beijing / Hangzhou, China.)', open=False):
114
+ gr.HTML("""<div class="acknowledgments">
115
+ <p>
116
+ If you're looking for an exciting challenge and the opportunity to work with cutting-edge technologies in AIGC and large-scale pretraining, then we are the place for you. We are looking for talented, motivated and creative individuals to join our team. If you are interested, please send your CV to us.
117
+ </p>
118
+ <p>
119
+ <b>EMAIL: yingya.zyy@alibaba-inc.com</b>.
120
+ </p>
121
+ </div>
122
+ """)
123
+
124
+ with gr.Accordion(label='Biases and content acknowledgment', open=False):
125
+ gr.HTML("""<div class="acknowledgments">
126
+ <h4>Biases and content acknowledgment</h4>
127
+ <p>
128
+ Despite how impressive being able to turn text into video is, beware to the fact that this model may output content that reinforces or exacerbates societal biases. The training data includes LAION5B, ImageNet, Webvid and other public datasets. The model was not trained to realistically represent people or events, so using it to generate such content is beyond the model's capabilities.
129
+ </p>
130
+ <p>
131
+ It is not intended to generate content that is demeaning or harmful to people or their environment, culture, religion, etc. Similarly, it is not allowed to generate pornographic, violent and bloody content generation. <b>The model is meant for research purposes</b>.
132
+ </p>
133
+ <p>
134
+ To learn more about the model, head to its <a href="https://huggingface.co/damo-vilab/modelscope-damo-text-to-video-synthesis" style="text-decoration: underline;" target="_blank">model card</a>.
135
+ </p>
136
+ </div>
137
+ """)
routers/gra_07_html/__init__.py ADDED
File without changes
routers/gra_07_html/gradio.py ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+
3
+ def display_html():
4
+ html_content = """
5
+ <h1>Hello, Gradio!</h1>
6
+ <p>This is an example of displaying HTML content using Gradio.</p>
7
+ <ul>
8
+ <li>Item 1</li>
9
+ <li>Item 2</li>
10
+ <li>Item 3</li>
11
+ <a href="test">aaa</a>
12
+ </ul>
13
+ """
14
+ return html_content
15
+
16
+ # Gradioのインターフェースを作成
17
+ gradio_interfaces = gr.Interface(
18
+ fn=display_html, # HTMLコンテンツを返す関数
19
+ inputs=[], # 入力なし
20
+ outputs=gr.HTML() # HTMLコンテンツを表示
21
+ )
22
+
23
+
24
+ # Gradioのインターフェースを作成
25
+ with gr.Blocks() as gradio_interface:
26
+ gr.HTML(display_html())
27
+ # インターフェースを起動
28
+ #iface.launch()