Spaces:
Running
on
Zero
Running
on
Zero
fa
Browse files- babyagi/prompt.txt +1 -1
- chat_history.db +2 -2
- command/line/get_user_profile.py +17 -0
- controllers/gpt_enginner20240626043057 +1 -0
- controllers/gpt_enginner20240626044249 +1 -0
- gradios/gra_01_chat/Chat.py +115 -0
- gradios/gra_01_chat/__init__.py +0 -0
- gradios/gra_02_openInterpreter/OpenInterpreter.py +239 -0
- gradios/gra_02_openInterpreter/__init__.py +0 -0
- gradios/gra_02_openInterpreter/__isnit__.py +0 -0
- gradios/gra_02_openInterpreter/chat_history.db +3 -0
- gradios/gra_03_programfromdoc/__init__.py +0 -0
- gradios/gra_03_programfromdoc/programfromdoc.py +103 -0
- gradios/gra_04_database/.gpteng/memory/logs/all_output.txt +298 -0
- gradios/gra_04_database/.gpteng/memory/logs/gen_entrypoint_chat.txt +241 -0
- gradios/gra_04_database/__init__.py +0 -0
- gradios/gra_04_database/models/ride.py +13 -0
- gradios/gra_04_database/prompt +14 -0
- gradios/gra_04_database/requirements.txt +2 -0
- gradios/gra_04_database/rides.py +164 -0
- gradios/gra_04_database/run.sh +2 -0
- gradios/gra_05_files/chat.py +115 -0
- gradios/gra_05_files/files.py +79 -0
- gradios/gra_06_video/__init__.py +0 -0
- gradios/gra_06_video/video.py +137 -0
- gradios/gra_07_html/__init__.py +0 -0
- gradios/gra_07_html/gradio.py +28 -0
- mysite/routers/fastapi.py +1 -0
- routers/appsheet.py +55 -0
- routers/webhook.py +367 -0
- workspace/appraisal_project/appraisal_api/__init__.py +0 -0
- workspace/appraisal_project/appraisal_api/admin.py +3 -0
- workspace/appraisal_project/appraisal_api/apps.py +6 -0
- workspace/appraisal_project/appraisal_api/migrations/__init__.py +0 -0
- workspace/appraisal_project/appraisal_api/models.py +3 -0
- workspace/appraisal_project/appraisal_api/tests.py +3 -0
- workspace/appraisal_project/appraisal_api/views.py +3 -0
- workspace/appraisal_project/appraisal_project/__init__.py +0 -0
- workspace/appraisal_project/appraisal_project/asgi.py +16 -0
- workspace/appraisal_project/appraisal_project/settings.py +123 -0
- workspace/appraisal_project/appraisal_project/urls.py +22 -0
- workspace/appraisal_project/appraisal_project/wsgi.py +16 -0
- workspace/appraisal_project/manage.py +22 -0
babyagi/prompt.txt
CHANGED
@@ -1 +1 @@
|
|
1 |
-
|
|
|
1 |
+
よろしくお願い致します。の質問 についてチャットボットでよりよく対応するプランを日本語で作成して
|
chat_history.db
CHANGED
@@ -1,3 +1,3 @@
|
|
1 |
version https://git-lfs.github.com/spec/v1
|
2 |
-
oid sha256:
|
3 |
-
size
|
|
|
1 |
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:b19cf1ae2d0c3b61a24489a91ccefd9a10318c58dc75956e97a67f2e157c3e39
|
3 |
+
size 1540096
|
command/line/get_user_profile.py
ADDED
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import requests
|
2 |
+
|
3 |
+
def get_user_profile(user_id, access_token):
|
4 |
+
url = f'https://api.line.me/v2/bot/profile/{user_id}'
|
5 |
+
headers = {
|
6 |
+
'Authorization': f'Bearer {access_token}'
|
7 |
+
}
|
8 |
+
|
9 |
+
response = requests.get(url, headers=headers)
|
10 |
+
if response.status_code == 200:
|
11 |
+
profile = response.json()
|
12 |
+
user_name = profile.get('displayName')
|
13 |
+
user_thumbnail = profile.get('pictureUrl')
|
14 |
+
return user_name, user_thumbnail
|
15 |
+
else:
|
16 |
+
print(f"Failed to get user profile: {response.status_code}, {response.text}")
|
17 |
+
return None, None
|
controllers/gpt_enginner20240626043057
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
Subproject commit 74be3290e7b4fd50805033d999064a5ac27a353b
|
controllers/gpt_enginner20240626044249
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
Subproject commit 90b27ecef033b1fe1ff83bdacb22cc281e5287ac
|
gradios/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)
|
gradios/gra_01_chat/__init__.py
ADDED
File without changes
|
gradios/gra_02_openInterpreter/OpenInterpreter.py
ADDED
@@ -0,0 +1,239 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
+
],
|
208 |
+
# democs,
|
209 |
+
examples=[
|
210 |
+
["HTMLのサンプルを作成して"],
|
211 |
+
[
|
212 |
+
"CUDA_VISIBLE_DEVICES=0 llamafactory-cli train examples/lora_single_gpu/llama3_lora_sft.yaml"
|
213 |
+
],
|
214 |
+
],
|
215 |
+
cache_examples=False,
|
216 |
+
)
|
217 |
+
|
218 |
+
if __name__ == '__main__':
|
219 |
+
message = f"""
|
220 |
+
postgres connection is this postgresql://miyataken999:yz1wPf4KrWTm@ep-odd-mode-93794521.us-east-2.aws.neon.tech/neondb?sslmode=require
|
221 |
+
create this tabale
|
222 |
+
CREATE TABLE items (
|
223 |
+
id INT PRIMARY KEY,
|
224 |
+
brand_name VARCHAR(255),
|
225 |
+
model_name VARCHAR(255),
|
226 |
+
product_number VARCHAR(255),
|
227 |
+
purchase_store VARCHAR(255),
|
228 |
+
purchase_date DATE,
|
229 |
+
purchase_price INT,
|
230 |
+
accessories TEXT,
|
231 |
+
condition INT,
|
232 |
+
metal_type VARCHAR(255),
|
233 |
+
metal_weight DECIMAL(10, 2),
|
234 |
+
diamond_certification BLOB,
|
235 |
+
initial BOOLEAN
|
236 |
+
);
|
237 |
+
|
238 |
+
"""
|
239 |
+
chat_with_interpreter(message)
|
gradios/gra_02_openInterpreter/__init__.py
ADDED
File without changes
|
gradios/gra_02_openInterpreter/__isnit__.py
ADDED
File without changes
|
gradios/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
|
gradios/gra_03_programfromdoc/__init__.py
ADDED
File without changes
|
gradios/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 |
+
)
|
gradios/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.
|
gradios/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 |
+
```
|
gradios/gra_04_database/__init__.py
ADDED
File without changes
|
gradios/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
|
gradios/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
|
gradios/gra_04_database/requirements.txt
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
gradio
|
2 |
+
psycopg2-binary
|
gradios/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()
|
gradios/gra_04_database/run.sh
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
python -m pip install -r requirements.txt
|
2 |
+
python gradio_app.py
|
gradios/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)
|
gradios/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)
|
gradios/gra_06_video/__init__.py
ADDED
File without changes
|
gradios/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 |
+
""")
|
gradios/gra_07_html/__init__.py
ADDED
File without changes
|
gradios/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()
|
mysite/routers/fastapi.py
CHANGED
@@ -19,6 +19,7 @@ from mysite.appsheet.appsheet import get_senario
|
|
19 |
import asyncio
|
20 |
logger = logging.getLogger(__name__)
|
21 |
|
|
|
22 |
"""
|
23 |
router
|
24 |
"""
|
|
|
19 |
import asyncio
|
20 |
logger = logging.getLogger(__name__)
|
21 |
|
22 |
+
|
23 |
"""
|
24 |
router
|
25 |
"""
|
routers/appsheet.py
ADDED
@@ -0,0 +1,55 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import requests
|
2 |
+
import json
|
3 |
+
import os
|
4 |
+
# current_user: User = Depends(get_current_active_user)):
|
5 |
+
# oauth2_scheme = OAuth2PasswordBearer(tokenUrl="/token")
|
6 |
+
# current_user: User = Depends(get_current_active_user)):
|
7 |
+
# oauth2_scheme = OAuth2PasswordBearer(tokenUrl="/token")
|
8 |
+
|
9 |
+
from fastapi import APIRouter, HTTPException
|
10 |
+
|
11 |
+
#router = APIRouter()
|
12 |
+
router = APIRouter(prefix="/appsheet", tags=["appsheet"])
|
13 |
+
@router.get("/route/appsheet")
|
14 |
+
|
15 |
+
def get_senario(id,res):
|
16 |
+
table = "LOG"
|
17 |
+
|
18 |
+
APPSHEET_APPID = os.getenv("APPSHEET_APPID")
|
19 |
+
APPSHEET_KEY = os.getenv("APPSHEET_KEY")
|
20 |
+
url = f"https://api.appsheet.com/api/v2/apps/{APPSHEET_APPID}/tables/{table}/Action"
|
21 |
+
|
22 |
+
payload = {
|
23 |
+
"Action": "Add",
|
24 |
+
"Properties": {},
|
25 |
+
"Rows":[
|
26 |
+
{
|
27 |
+
"コメント":res,
|
28 |
+
"イメージID":"12121",
|
29 |
+
"USERNAME":id,
|
30 |
+
"ユーザーIMG":"122",
|
31 |
+
}
|
32 |
+
]}
|
33 |
+
headers = {
|
34 |
+
"contentType": "application/json",
|
35 |
+
"ApplicationAccessKey": APPSHEET_KEY,
|
36 |
+
"Content-Type": "application/json",
|
37 |
+
}
|
38 |
+
messages = []
|
39 |
+
response = requests.request("POST", url, headers=headers, data=json.dumps(payload))
|
40 |
+
# print(response)
|
41 |
+
#print(response)
|
42 |
+
for key in response:
|
43 |
+
print(key)
|
44 |
+
#print(response.text)
|
45 |
+
print(response.json)
|
46 |
+
return response.text#.json()
|
47 |
+
|
48 |
+
# main input
|
49 |
+
#res = get_senario("LOG")
|
50 |
+
#print(res)
|
51 |
+
#return res
|
52 |
+
|
53 |
+
#print(response.json())
|
54 |
+
if __name__ == "__main__":
|
55 |
+
get_senario("test","test")
|
routers/webhook.py
ADDED
@@ -0,0 +1,367 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
|
2 |
+
from fastapi import APIRouter, HTTPException
|
3 |
+
|
4 |
+
#router = APIRouter()
|
5 |
+
router = APIRouter(prefix="/testcc", tags=["leatestccning"])
|
6 |
+
@router.get("/route/webhooks")
|
7 |
+
async def webhook(request: Request):
|
8 |
+
#return
|
9 |
+
#logger.info("[Start] ====== LINE webhook ======")
|
10 |
+
body = await request.body()
|
11 |
+
received_headers = dict(request.headers)
|
12 |
+
body_str = body.decode("utf-8")
|
13 |
+
logger.info("Received Body: %s", body_str)
|
14 |
+
body_json = json.loads(body_str)
|
15 |
+
events = body_json.get("events", [])
|
16 |
+
|
17 |
+
webhook_url = os.getenv("chat_url")
|
18 |
+
token = os.getenv("token")
|
19 |
+
ChannelAccessToken = os.getenv('ChannelAccessToken')
|
20 |
+
|
21 |
+
|
22 |
+
|
23 |
+
|
24 |
+
thread_name=""
|
25 |
+
#return
|
26 |
+
#url = github(token,foldername)
|
27 |
+
try:
|
28 |
+
DEBUG=0
|
29 |
+
for event in events:
|
30 |
+
if event["type"] == "message" and event["message"]["type"] == "text":
|
31 |
+
user_id = event["source"]["userId"]
|
32 |
+
text = event["message"]["text"]
|
33 |
+
user_name,thmbnail = get_user_profile(user_id,ChannelAccessToken)
|
34 |
+
|
35 |
+
logger.info("Received Headers: %s", user_name)
|
36 |
+
logger.info("Received Headers: %s", thmbnail)
|
37 |
+
|
38 |
+
#logger.info("------------------------------------------")
|
39 |
+
first_line = text.split('\n')[0]
|
40 |
+
#logger.info(f"User ID: {user_id}, Text: {text}")
|
41 |
+
prompt = """
|
42 |
+
1, Q&Aのテーブルを作成してください DBはpostgress pk はPostgresのAutoIncrementの serialでの自動追加
|
43 |
+
2, 質問が来た際には、まず質問に対しての答えを過去のデータから探します
|
44 |
+
3, Q&Aから役割を作成します
|
45 |
+
質問に対しての答えを出す、シナリオを考える
|
46 |
+
4, 実際にテストして正しい答えがでるか確認
|
47 |
+
5, 出ない場合は再度作成しなおします
|
48 |
+
1から6を繰り返し、答えが出たプロンプトを登録します
|
49 |
+
7, 成功した場合それを保存します
|
50 |
+
8, 同じ質問が来たら質問別にプロンプトを変更します
|
51 |
+
9, 上記をラインの質問に内部の方が納得いくまで、日々修正していきます
|
52 |
+
"""
|
53 |
+
prompt2 = f"""
|
54 |
+
# 返信について日本語で必ず答えて下さい
|
55 |
+
# 役割
|
56 |
+
あなたはリファスタという会社のアシスタントです
|
57 |
+
金、ダイヤモンド、商品を売りにきた顧客います
|
58 |
+
売りに来た顧客の質問内容は {text}
|
59 |
+
この質問を買取店の査定人に対して、理解がしやすい わかりやすい質問に変更してください
|
60 |
+
|
61 |
+
会社にはデータベースがあり質問内容から、商品を検索するSQLを作成してください
|
62 |
+
必要なテーブルのCreate文も作成してして下さい
|
63 |
+
pk は postgress なので 自動連番のserialにして下さい
|
64 |
+
質問の内容をそのテーブルにいれるインサート文も作成してくさい
|
65 |
+
|
66 |
+
ほかに、良い提案があればして下さい。こうしたらもっと、良くなるよなど。
|
67 |
+
## リファスタの住所
|
68 |
+
〒170-0013 東京都豊島区東池袋1丁目25−14 アルファビルディング 4F
|
69 |
+
## 買取ダイヤテンプレート
|
70 |
+
- price,
|
71 |
+
- carat,
|
72 |
+
- cut,
|
73 |
+
- color,
|
74 |
+
- clarity,
|
75 |
+
- depth,
|
76 |
+
- diamondprice.table,
|
77 |
+
- x,
|
78 |
+
- y,
|
79 |
+
- z
|
80 |
+
## 買取ブランドテンプレート
|
81 |
+
・ブランド名:
|
82 |
+
・モデル名:
|
83 |
+
・型番や品番:
|
84 |
+
・購入店:
|
85 |
+
・購入時期:
|
86 |
+
・購入金額:
|
87 |
+
・付属品:
|
88 |
+
・コンディション:
|
89 |
+
(10段階評価厳しめ)
|
90 |
+
・貴金属品位:
|
91 |
+
・貴金属重量:
|
92 |
+
(キッチンスケールでも(sparkle))
|
93 |
+
・ダイヤや宝石の鑑定書はお写真で!
|
94 |
+
・イニシャル:あり なし
|
95 |
+
## リファスタのサイト
|
96 |
+
(monitor)24h対応事前査定
|
97 |
+
https://kinkaimasu.jp/estimate/?openExternalBrowser=1&utm_source=LINE
|
98 |
+
|
99 |
+
(open book)買取システムナビ
|
100 |
+
https://kinkaimasu.jp/system/?openExternalBrowser=1&utm_source=LINE
|
101 |
+
|
102 |
+
(car)店舗アクセス
|
103 |
+
https://goo.gl/veQZ03
|
104 |
+
|
105 |
+
(?)よくある質問
|
106 |
+
https://kinkaimasu.jp/faq/?openExternalBrowser=1&utm_source=LINE"
|
107 |
+
User,hibiki,2024/06/16,21:53:47,"まだ買取をするか未定ですが、
|
108 |
+
一度査定をよろしくお願いします。"
|
109 |
+
Account,応答メッセージ,2024/06/16,21:53:47,"(clock)ただ今対応時間外(clock)
|
110 |
+
営業時間:11:00~20:00
|
111 |
+
※年中無休
|
112 |
+
翌営業日に順次対応致しますので、お写真や情報はいつでもお送りください(moon wink)
|
113 |
+
|
114 |
+
|
115 |
+
(monitor)24h対応事前査定
|
116 |
+
https://kinkaimasu.jp/estimate/?openExternalBrowser=1&utm_source=LINE
|
117 |
+
|
118 |
+
(open book)買取システムナビ
|
119 |
+
https://kinkaimasu.jp/system/?openExternalBrowser=1&utm_source=LINE
|
120 |
+
|
121 |
+
(car)店舗アクセス
|
122 |
+
https://goo.gl/veQZ03
|
123 |
+
|
124 |
+
(?)よくある質問
|
125 |
+
https://kinkaimasu.jp/faq/?openExternalBrowser=1&utm_source=LINE"
|
126 |
+
## サービス
|
127 |
+
## フリーダイヤル
|
128 |
+
お気軽にお電話くださいませ(sparkle)
|
129 |
+
10:30〜20:00 年中無休
|
130 |
+
|
131 |
+
オンライン買取も受付中
|
132 |
+
https://kinkaimasu.jp/online-promise/?openExternalBrowser=1&utm_source=LINE
|
133 |
+
|
134 |
+
## (smartphone) 電話番号
|
135 |
+
0120-954-679
|
136 |
+
|
137 |
+
## (LINE messenger) LINE通話
|
138 |
+
https://lin.ee/c6inM4V
|
139 |
+
|
140 |
+
"""
|
141 |
+
# 査定用のプロンプト
|
142 |
+
promps,prompt_res = prompt_genalate("返信は日本語で答えて下さい "+text,prompt2)
|
143 |
+
|
144 |
+
#test_set_lide(text,"a1")
|
145 |
+
#no_process_file(text, "ai")
|
146 |
+
#\r\m
|
147 |
+
#########################################################################
|
148 |
+
#user_name,thmbnail#
|
149 |
+
title = f""" {user_name}様から下記の質問があります"""
|
150 |
+
subtitle = f"""<b>ユーザーID</b> {user_id}\r\n <b>質問内容</b>\r\n {text}"""
|
151 |
+
link_text = "\r\n<b>チャットボット設定用シート</b>\r\n シート用のアプリはチャットから\r\n @リファペディア\r\n と打ち込むと開きます"
|
152 |
+
link_url = "https://docs.google.com/spreadsheets/d/13pqP-Ywo5eRlZBsYX2m3ChARG38EoIYOowFd3cWij1c/edit?gid=283940886#gid=283940886"
|
153 |
+
#test_set_lide(subtitle, text)
|
154 |
+
thread_name = send_google_chat_card(webhook_url, title, subtitle, link_text, link_url,thmbnail)
|
155 |
+
from command.n8n import post_data
|
156 |
+
import time
|
157 |
+
n8nurl = os.getenv("n8nhook")
|
158 |
+
post_data(n8nurl,text,thread_name)
|
159 |
+
time.sleep(10)
|
160 |
+
#########################################################################
|
161 |
+
title = f""" プロンプト作成 {promps}"""
|
162 |
+
subtitle = f"""userid {user_id}\r\n chatid {thread_name}\r\n{prompt_res}"""
|
163 |
+
link_text = "データを確認する"
|
164 |
+
link_url = "https://kenken999-php.hf.space/diamondprice_list.php"
|
165 |
+
#test_set_lide(subtitle, text)
|
166 |
+
if DEBUG==0:
|
167 |
+
thread_name = send_google_chat_card_thread(webhook_url, title, subtitle, link_text, link_url,thread_name)
|
168 |
+
|
169 |
+
#thread_name = send_google_chat_card_thread(webhook_url, title, subtitle, link_text, link_url,thread_name)
|
170 |
+
#return
|
171 |
+
#test case
|
172 |
+
#########################################################################
|
173 |
+
first_line = text.split('\n')[0]
|
174 |
+
#test_prompt
|
175 |
+
res = test_prompt("返信は必ず日本語でして下さい \r\n"+prompt_res,text)
|
176 |
+
if DEBUG==0:
|
177 |
+
thread_name = send_google_chat_card_thread(webhook_url, "プロンプトテスト "+first_line, str(res), link_text, link_url,thread_name)
|
178 |
+
#thread_name = send_google_chat_card_thread(webhook_url, title, subtitle, link_text, link_url,thread_name)
|
179 |
+
now = datetime.now()
|
180 |
+
yyyymmddhis = now.strftime('%Y%m%d%H%M%S')
|
181 |
+
|
182 |
+
prompt_for_create_system = """
|
183 |
+
下記の質問に対応するコードをdjangoでアプリを作成 プロジェクトはいりません
|
184 |
+
fastapiでrouter部分を作成 組み込みはメイン部分でします
|
185 |
+
フロントエンドをgradioで作成
|
186 |
+
#google apps script frontend
|
187 |
+
googleappsscript doGet でのgradioの表示処理を作成 google.script.runで関数は呼び出し
|
188 |
+
#google apps script backend
|
189 |
+
frontendからの呼び出し用のバックエンドスクリプト
|
190 |
+
仕様書の��成
|
191 |
+
PlantUMLでシーケンス図の作成
|
192 |
+
Markdownでのプログラム殺名
|
193 |
+
#下記参考にAPIも作成しておいて
|
194 |
+
action insert list edit update でCRUDがかわる
|
195 |
+
同じようにGASのAPIも作成しておいて
|
196 |
+
|
197 |
+
def create_vector():
|
198 |
+
inputs = tokenizer(result, return_tensors="pt", max_length=512, truncation=True)
|
199 |
+
outputs = model(**inputs)
|
200 |
+
# [CLS]トークンの出力を取得
|
201 |
+
embeddings = outputs.last_hidden_state[:,0,:].squeeze().detach().cpu().numpy().tolist()
|
202 |
+
print(embeddings)
|
203 |
+
import requests
|
204 |
+
|
205 |
+
url = "https://kenken999-php.hf.space/api/v1.php"
|
206 |
+
|
207 |
+
payload = "model_name={embeddings}&vector_text={result}&table=products&action=insert""
|
208 |
+
headers = {
|
209 |
+
'X-Auth-Token': 'admin',
|
210 |
+
'Content-Type': 'application/x-www-form-urlencoded',
|
211 |
+
'Cookie': 'runnerSession=muvclb78zpsdjbm7y9c3; pD1lszvk6ratOZhmmgvkp=13767810ebf0782b0b51bf72dedb63b3'
|
212 |
+
}
|
213 |
+
|
214 |
+
response = requests.request("POST", url, headers=headers, data=payload)
|
215 |
+
|
216 |
+
print(response.text)
|
217 |
+
return True
|
218 |
+
|
219 |
+
下記の質問 作成対応内容
|
220 |
+
|
221 |
+
"""
|
222 |
+
#########################################################################
|
223 |
+
## excute create program
|
224 |
+
res_no_process = no_process_file(prompt_for_create_system+res, "gpt_enginner"+ yyyymmddhis,thread_name)
|
225 |
+
# execute open interpreter
|
226 |
+
#########################################################################
|
227 |
+
full_response,history = chat_with_interpreter_no_stream(prompt_for_create_system+"\r\n"+res)
|
228 |
+
if DEBUG==1:
|
229 |
+
thread_name = send_google_chat_card_thread(webhook_url, f"自動設定開始 {res}", str(full_response), link_text, link_url,thread_name)
|
230 |
+
#########################################################################
|
231 |
+
#ダイヤ金額計算
|
232 |
+
from babyagi.classesa.diamond import calculate
|
233 |
+
title = f""" ダイヤ予測計算の実行 類似5件表示 {text}
|
234 |
+
id,price,carat, cut, color, clarity, depth, diamondprice.table, x, y, z 類似度"""
|
235 |
+
res_calculate = calculate(text)
|
236 |
+
subtitle = res_calculate
|
237 |
+
link_text = "データを確認する"
|
238 |
+
link_url = "https://kenken999-php.hf.space/diamondprice_list.php"
|
239 |
+
#test_set_lide(subtitle, text)
|
240 |
+
if DEBUG==0:
|
241 |
+
thread_name = send_google_chat_card_thread(webhook_url, title, subtitle, link_text, link_url,thread_name)
|
242 |
+
#########################################################################
|
243 |
+
from babyagi.babyagi import completion
|
244 |
+
#import tempfile
|
245 |
+
text = text.replace("\r\n","")
|
246 |
+
# コマンドを構築
|
247 |
+
command = f"""make runbabyagi "{text}に対して、より良いチャットボットでのQAプランデータ設定の提案を日本語で作成してください" {thread_name}"""
|
248 |
+
|
249 |
+
with open('/home/user/app/babyagi/prompt.txt', 'w') as file:
|
250 |
+
file.write(f"""{text}の質問 についてチャットボットでよりよく対応するプランを日本語で作成して""")
|
251 |
+
|
252 |
+
#
|
253 |
+
proc = subprocess.Popen(
|
254 |
+
["make", "runbabyagi", thread_name],
|
255 |
+
stdin=subprocess.PIPE,
|
256 |
+
stdout=subprocess.PIPE,
|
257 |
+
stderr=subprocess.PIPE,
|
258 |
+
text=True,
|
259 |
+
)
|
260 |
+
#await asyncio.sleep(30)
|
261 |
+
"""
|
262 |
+
proc = subprocess.Popen(
|
263 |
+
command,
|
264 |
+
stdin=subprocess.PIPE,
|
265 |
+
stdout=subprocess.PIPE,
|
266 |
+
stderr=subprocess.PIPE,
|
267 |
+
text=True,
|
268 |
+
shell=True
|
269 |
+
)
|
270 |
+
"""
|
271 |
+
|
272 |
+
|
273 |
+
#prompt_res_agi = completion("日本語で下記のプランを考えて "+res)
|
274 |
+
#thread_name = send_google_chat_card_thread(webhook_url, title, prompt_res_agi, link_text, link_url,thread_name)
|
275 |
+
#title = f""" タスク作成 再度考える {promps}"""
|
276 |
+
#subtitle = prompt_res_agi
|
277 |
+
#link_text = "データを確認する"
|
278 |
+
#link_url = "https://kenken999-php.hf.space/diamondprice_list.php"
|
279 |
+
#thread_name = send_google_chat_card_thread(webhook_url, title, prompt_res_agi, link_text, link_url,thread_name)
|
280 |
+
|
281 |
+
#send_google_chat_card(webhook_url, title, subtitle, link_text, link_url)
|
282 |
+
|
283 |
+
#return
|
284 |
+
#return
|
285 |
+
#return
|
286 |
+
"""
|
287 |
+
for event in events:
|
288 |
+
if event["type"] == "message" and event["message"]["type"] == "text":
|
289 |
+
user_id = event["source"]["userId"]
|
290 |
+
text = event["message"]["text"]
|
291 |
+
logger.info(event)
|
292 |
+
logger.info(f"User ID: {user_id}, Text: {text}")
|
293 |
+
now = datetime.now().strftime("%Y%m%d%H%M%S")
|
294 |
+
title = text[:10]
|
295 |
+
user_id_with_timestamp = title#f"{now}_{title}_{user_id}"
|
296 |
+
no_process_file(text, user_id_with_timestamp)
|
297 |
+
#db登録
|
298 |
+
test_set_lide(text, user_id_with_timestamp)
|
299 |
+
"""
|
300 |
+
logger.info("Received Headers: %s", received_headers)
|
301 |
+
logger.info("Received Body: %s", body.decode("utf-8"))
|
302 |
+
###############################################################################
|
303 |
+
#send to appsheet
|
304 |
+
get_senario("user_id",str(body))
|
305 |
+
#apps script send
|
306 |
+
headers = {
|
307 |
+
"Content-Type": "application/json",
|
308 |
+
}
|
309 |
+
logger.info("Received Body: %s", "send data to appsheet ")
|
310 |
+
#response = requests.post(os.getenv("WEBHOOK_URL"), headers=headers, data=body)
|
311 |
+
# check signature
|
312 |
+
line_signature = received_headers.get("x-line-signature")
|
313 |
+
logger.info("Received Body: %s", "start send messages ")
|
314 |
+
#headers = {
|
315 |
+
# "Content-Type": "application/json",
|
316 |
+
# "X-Line-Signature": line_signature,
|
317 |
+
# "Authorization": f"Bearer {os.getenv('ChannelAccessToken')}",
|
318 |
+
# }
|
319 |
+
#r#esponse = requests.post(os.getenv("WEBHOOK_URL"), headers=headers, data=body)
|
320 |
+
if not line_signature:
|
321 |
+
raise HTTPException(status_code=400, detail="X-Line-Signature header is missing.")
|
322 |
+
|
323 |
+
if not validate_signature(body.decode("utf-8"), line_signature, os.getenv("ChannelSecret")):
|
324 |
+
raise HTTPException(status_code=400, detail="Invalid signature.")
|
325 |
+
|
326 |
+
if not os.getenv("WEBHOOK_URL") or not os.getenv("WEBHOOK_URL").startswith("https://"):
|
327 |
+
raise HTTPException(status_code=400, detail="Invalid webhook URL")
|
328 |
+
|
329 |
+
headers = {
|
330 |
+
"Content-Type": "application/json",
|
331 |
+
"X-Line-Signature": line_signature,
|
332 |
+
"Authorization": f"Bearer {os.getenv('ChannelAccessToken')}",
|
333 |
+
}
|
334 |
+
|
335 |
+
logger.info("Forwarding to URL: %s", os.getenv("WEBHOOK_URL"))
|
336 |
+
logger.info("Forwarding Headers: %s", headers)
|
337 |
+
logger.info("Forwarding Body: %s", body.decode("utf-8"))
|
338 |
+
|
339 |
+
#response = requests.post(os.getenv("WEBHOOK_URL"), headers=headers, data=body)
|
340 |
+
responses = requests.post(os.getenv("WEBHOOK_GAS"), headers=headers, data=body)
|
341 |
+
logger.info("Response Code: %s", response.status_code)
|
342 |
+
logger.info("Response Content: %s", response.text)
|
343 |
+
logger.info("Response Headers: %s", response.headers)
|
344 |
+
|
345 |
+
return {"status": "success", "response_content": response.text}#, response.status_code
|
346 |
+
|
347 |
+
except Exception as e:
|
348 |
+
error_file = os.path.basename(__file__) # ファイル名を取得
|
349 |
+
error_line = sys._getframe(1).f_lineno # 行番号を取得
|
350 |
+
print(f"Error occurred at file {error_file} on line {error_line}: {str(e)}")
|
351 |
+
#エラー内容の分析
|
352 |
+
promps,res = prompt_genalate(str(e))
|
353 |
+
#test_set_lide(text,"a1")
|
354 |
+
#no_process_file(text, "ai")
|
355 |
+
custormer_supportpage = "\r\n カスタマーサポートはこちらから \r\n https://bpmboxesscom-46463613.hubspotpagebuilder.com/ja \r\n "
|
356 |
+
title = f"""エラーが起こりました -+errer file is {error_file} error line is {error_line} {str(e)} 自動修復の開始 """
|
357 |
+
subtitle = custormer_supportpage+res
|
358 |
+
link_text = "test"
|
359 |
+
link_url = "url"
|
360 |
+
#test_set_lide(subtitle, text)
|
361 |
+
logger.error(res)
|
362 |
+
#send error to google chat
|
363 |
+
send_google_chat_card_thread(webhook_url, title, subtitle, link_text, link_url,thread_name)
|
364 |
+
logger.error("Error: %s", str(e))
|
365 |
+
#raise するとシステムとまるのでアンコメント
|
366 |
+
#raise HTTPException(status_code=500, detail=str(e))
|
367 |
+
return {"status": "success", "response_content": str(e)}#, response.status_code
|
workspace/appraisal_project/appraisal_api/__init__.py
ADDED
File without changes
|
workspace/appraisal_project/appraisal_api/admin.py
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
from django.contrib import admin
|
2 |
+
|
3 |
+
# Register your models here.
|
workspace/appraisal_project/appraisal_api/apps.py
ADDED
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from django.apps import AppConfig
|
2 |
+
|
3 |
+
|
4 |
+
class AppraisalApiConfig(AppConfig):
|
5 |
+
default_auto_field = 'django.db.models.BigAutoField'
|
6 |
+
name = 'appraisal_api'
|
workspace/appraisal_project/appraisal_api/migrations/__init__.py
ADDED
File without changes
|
workspace/appraisal_project/appraisal_api/models.py
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
from django.db import models
|
2 |
+
|
3 |
+
# Create your models here.
|
workspace/appraisal_project/appraisal_api/tests.py
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
from django.test import TestCase
|
2 |
+
|
3 |
+
# Create your tests here.
|
workspace/appraisal_project/appraisal_api/views.py
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
from django.shortcuts import render
|
2 |
+
|
3 |
+
# Create your views here.
|
workspace/appraisal_project/appraisal_project/__init__.py
ADDED
File without changes
|
workspace/appraisal_project/appraisal_project/asgi.py
ADDED
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
"""
|
2 |
+
ASGI config for appraisal_project project.
|
3 |
+
|
4 |
+
It exposes the ASGI callable as a module-level variable named ``application``.
|
5 |
+
|
6 |
+
For more information on this file, see
|
7 |
+
https://docs.djangoproject.com/en/5.0/howto/deployment/asgi/
|
8 |
+
"""
|
9 |
+
|
10 |
+
import os
|
11 |
+
|
12 |
+
from django.core.asgi import get_asgi_application
|
13 |
+
|
14 |
+
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'appraisal_project.settings')
|
15 |
+
|
16 |
+
application = get_asgi_application()
|
workspace/appraisal_project/appraisal_project/settings.py
ADDED
@@ -0,0 +1,123 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
"""
|
2 |
+
Django settings for appraisal_project project.
|
3 |
+
|
4 |
+
Generated by 'django-admin startproject' using Django 5.0.4.
|
5 |
+
|
6 |
+
For more information on this file, see
|
7 |
+
https://docs.djangoproject.com/en/5.0/topics/settings/
|
8 |
+
|
9 |
+
For the full list of settings and their values, see
|
10 |
+
https://docs.djangoproject.com/en/5.0/ref/settings/
|
11 |
+
"""
|
12 |
+
|
13 |
+
from pathlib import Path
|
14 |
+
|
15 |
+
# Build paths inside the project like this: BASE_DIR / 'subdir'.
|
16 |
+
BASE_DIR = Path(__file__).resolve().parent.parent
|
17 |
+
|
18 |
+
|
19 |
+
# Quick-start development settings - unsuitable for production
|
20 |
+
# See https://docs.djangoproject.com/en/5.0/howto/deployment/checklist/
|
21 |
+
|
22 |
+
# SECURITY WARNING: keep the secret key used in production secret!
|
23 |
+
SECRET_KEY = 'django-insecure-rg^m9vp=ab_)*3-v2i&*+xch0_fpggkv+)ej+tci6h++aa%)et'
|
24 |
+
|
25 |
+
# SECURITY WARNING: don't run with debug turned on in production!
|
26 |
+
DEBUG = True
|
27 |
+
|
28 |
+
ALLOWED_HOSTS = []
|
29 |
+
|
30 |
+
|
31 |
+
# Application definition
|
32 |
+
|
33 |
+
INSTALLED_APPS = [
|
34 |
+
'django.contrib.admin',
|
35 |
+
'django.contrib.auth',
|
36 |
+
'django.contrib.contenttypes',
|
37 |
+
'django.contrib.sessions',
|
38 |
+
'django.contrib.messages',
|
39 |
+
'django.contrib.staticfiles',
|
40 |
+
]
|
41 |
+
|
42 |
+
MIDDLEWARE = [
|
43 |
+
'django.middleware.security.SecurityMiddleware',
|
44 |
+
'django.contrib.sessions.middleware.SessionMiddleware',
|
45 |
+
'django.middleware.common.CommonMiddleware',
|
46 |
+
'django.middleware.csrf.CsrfViewMiddleware',
|
47 |
+
'django.contrib.auth.middleware.AuthenticationMiddleware',
|
48 |
+
'django.contrib.messages.middleware.MessageMiddleware',
|
49 |
+
'django.middleware.clickjacking.XFrameOptionsMiddleware',
|
50 |
+
]
|
51 |
+
|
52 |
+
ROOT_URLCONF = 'appraisal_project.urls'
|
53 |
+
|
54 |
+
TEMPLATES = [
|
55 |
+
{
|
56 |
+
'BACKEND': 'django.template.backends.django.DjangoTemplates',
|
57 |
+
'DIRS': [],
|
58 |
+
'APP_DIRS': True,
|
59 |
+
'OPTIONS': {
|
60 |
+
'context_processors': [
|
61 |
+
'django.template.context_processors.debug',
|
62 |
+
'django.template.context_processors.request',
|
63 |
+
'django.contrib.auth.context_processors.auth',
|
64 |
+
'django.contrib.messages.context_processors.messages',
|
65 |
+
],
|
66 |
+
},
|
67 |
+
},
|
68 |
+
]
|
69 |
+
|
70 |
+
WSGI_APPLICATION = 'appraisal_project.wsgi.application'
|
71 |
+
|
72 |
+
|
73 |
+
# Database
|
74 |
+
# https://docs.djangoproject.com/en/5.0/ref/settings/#databases
|
75 |
+
|
76 |
+
DATABASES = {
|
77 |
+
'default': {
|
78 |
+
'ENGINE': 'django.db.backends.sqlite3',
|
79 |
+
'NAME': BASE_DIR / 'db.sqlite3',
|
80 |
+
}
|
81 |
+
}
|
82 |
+
|
83 |
+
|
84 |
+
# Password validation
|
85 |
+
# https://docs.djangoproject.com/en/5.0/ref/settings/#auth-password-validators
|
86 |
+
|
87 |
+
AUTH_PASSWORD_VALIDATORS = [
|
88 |
+
{
|
89 |
+
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
|
90 |
+
},
|
91 |
+
{
|
92 |
+
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
|
93 |
+
},
|
94 |
+
{
|
95 |
+
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
|
96 |
+
},
|
97 |
+
{
|
98 |
+
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
|
99 |
+
},
|
100 |
+
]
|
101 |
+
|
102 |
+
|
103 |
+
# Internationalization
|
104 |
+
# https://docs.djangoproject.com/en/5.0/topics/i18n/
|
105 |
+
|
106 |
+
LANGUAGE_CODE = 'en-us'
|
107 |
+
|
108 |
+
TIME_ZONE = 'UTC'
|
109 |
+
|
110 |
+
USE_I18N = True
|
111 |
+
|
112 |
+
USE_TZ = True
|
113 |
+
|
114 |
+
|
115 |
+
# Static files (CSS, JavaScript, Images)
|
116 |
+
# https://docs.djangoproject.com/en/5.0/howto/static-files/
|
117 |
+
|
118 |
+
STATIC_URL = 'static/'
|
119 |
+
|
120 |
+
# Default primary key field type
|
121 |
+
# https://docs.djangoproject.com/en/5.0/ref/settings/#default-auto-field
|
122 |
+
|
123 |
+
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
|
workspace/appraisal_project/appraisal_project/urls.py
ADDED
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
"""
|
2 |
+
URL configuration for appraisal_project project.
|
3 |
+
|
4 |
+
The `urlpatterns` list routes URLs to views. For more information please see:
|
5 |
+
https://docs.djangoproject.com/en/5.0/topics/http/urls/
|
6 |
+
Examples:
|
7 |
+
Function views
|
8 |
+
1. Add an import: from my_app import views
|
9 |
+
2. Add a URL to urlpatterns: path('', views.home, name='home')
|
10 |
+
Class-based views
|
11 |
+
1. Add an import: from other_app.views import Home
|
12 |
+
2. Add a URL to urlpatterns: path('', Home.as_view(), name='home')
|
13 |
+
Including another URLconf
|
14 |
+
1. Import the include() function: from django.urls import include, path
|
15 |
+
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
|
16 |
+
"""
|
17 |
+
from django.contrib import admin
|
18 |
+
from django.urls import path
|
19 |
+
|
20 |
+
urlpatterns = [
|
21 |
+
path('admin/', admin.site.urls),
|
22 |
+
]
|
workspace/appraisal_project/appraisal_project/wsgi.py
ADDED
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
"""
|
2 |
+
WSGI config for appraisal_project project.
|
3 |
+
|
4 |
+
It exposes the WSGI callable as a module-level variable named ``application``.
|
5 |
+
|
6 |
+
For more information on this file, see
|
7 |
+
https://docs.djangoproject.com/en/5.0/howto/deployment/wsgi/
|
8 |
+
"""
|
9 |
+
|
10 |
+
import os
|
11 |
+
|
12 |
+
from django.core.wsgi import get_wsgi_application
|
13 |
+
|
14 |
+
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'appraisal_project.settings')
|
15 |
+
|
16 |
+
application = get_wsgi_application()
|
workspace/appraisal_project/manage.py
ADDED
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#!/usr/bin/env python
|
2 |
+
"""Django's command-line utility for administrative tasks."""
|
3 |
+
import os
|
4 |
+
import sys
|
5 |
+
|
6 |
+
|
7 |
+
def main():
|
8 |
+
"""Run administrative tasks."""
|
9 |
+
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'appraisal_project.settings')
|
10 |
+
try:
|
11 |
+
from django.core.management import execute_from_command_line
|
12 |
+
except ImportError as exc:
|
13 |
+
raise ImportError(
|
14 |
+
"Couldn't import Django. Are you sure it's installed and "
|
15 |
+
"available on your PYTHONPATH environment variable? Did you "
|
16 |
+
"forget to activate a virtual environment?"
|
17 |
+
) from exc
|
18 |
+
execute_from_command_line(sys.argv)
|
19 |
+
|
20 |
+
|
21 |
+
if __name__ == '__main__':
|
22 |
+
main()
|