Spaces:
Running
on
Zero
Running
on
Zero
Commit
·
d8d03d3
1
Parent(s):
6fa6a4a
update
Browse files- controllers/gra_04_database/.gpteng/memory/logs/all_output.txt +0 -298
- controllers/gra_04_database/.gpteng/memory/logs/gen_entrypoint_chat.txt +0 -241
- controllers/gra_04_database/__init__.py +0 -0
- controllers/gra_04_database/models/ride.py +0 -13
- controllers/gra_04_database/prompt +0 -14
- controllers/gra_04_database/requirements.txt +0 -2
- controllers/gra_04_database/rides.py +0 -164
- controllers/gra_04_database/run.sh +0 -2
- controllers/gra_05_files/files.py +0 -79
- controllers/gra_06_video/__init__.py +0 -0
- controllers/gra_06_video/video.py +0 -140
- controllers/gra_api/__init__.py +0 -0
- controllers/gra_api/api.py +0 -14
controllers/gra_04_database/.gpteng/memory/logs/all_output.txt
DELETED
@@ -1,298 +0,0 @@
|
|
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:[email protected]/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=os.getenv("postgre_user"),
|
110 |
-
password=os.getenv("postgre_pass"),
|
111 |
-
host=os.getenv("postgre_host"),
|
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.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
controllers/gra_04_database/.gpteng/memory/logs/gen_entrypoint_chat.txt
DELETED
@@ -1,241 +0,0 @@
|
|
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=os.getenv("postgre_user"),
|
49 |
-
7 password=os.getenv("postgre_pass"),
|
50 |
-
8 host=os.getenv("postgre_host"),
|
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 |
-
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
controllers/gra_04_database/__init__.py
DELETED
File without changes
|
controllers/gra_04_database/models/ride.py
DELETED
@@ -1,13 +0,0 @@
|
|
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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
controllers/gra_04_database/prompt
DELETED
@@ -1,14 +0,0 @@
|
|
1 |
-
gradioで下記のpostgressのCRUD画面を作成して
|
2 |
-
postgresql://miyataken999:[email protected]/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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
controllers/gra_04_database/requirements.txt
DELETED
@@ -1,2 +0,0 @@
|
|
1 |
-
gradio
|
2 |
-
psycopg2-binary
|
|
|
|
|
|
controllers/gra_04_database/rides.py
DELETED
@@ -1,164 +0,0 @@
|
|
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=os.getenv("postgre_user"),
|
23 |
-
password=os.getenv("postgre_pass"),
|
24 |
-
host=os.getenv("postgre_host"),
|
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()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
controllers/gra_04_database/run.sh
DELETED
@@ -1,2 +0,0 @@
|
|
1 |
-
python -m pip install -r requirements.txt
|
2 |
-
python gradio_app.py
|
|
|
|
|
|
controllers/gra_05_files/files.py
DELETED
@@ -1,79 +0,0 @@
|
|
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)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
controllers/gra_06_video/__init__.py
DELETED
File without changes
|
controllers/gra_06_video/video.py
DELETED
@@ -1,140 +0,0 @@
|
|
1 |
-
#!/usr/bin/env python
|
2 |
-
|
3 |
-
from __future__ import annotations
|
4 |
-
import os
|
5 |
-
import random
|
6 |
-
import tempfile
|
7 |
-
import gradio as gr
|
8 |
-
import imageio
|
9 |
-
import numpy as np
|
10 |
-
import torch
|
11 |
-
from diffusers import DiffusionPipeline, DPMSolverMultistepScheduler
|
12 |
-
|
13 |
-
DESCRIPTION = '# [ModelScope Text to Video Synthesis](https://modelscope.cn/models/damo/text-to-video-synthesis/summary)'
|
14 |
-
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>'
|
15 |
-
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>'
|
16 |
-
|
17 |
-
if (SPACE_ID := os.getenv('SPACE_ID')) is not None:
|
18 |
-
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>'
|
19 |
-
|
20 |
-
MAX_NUM_FRAMES = int(os.getenv('MAX_NUM_FRAMES', '200'))
|
21 |
-
DEFAULT_NUM_FRAMES = min(MAX_NUM_FRAMES, int(os.getenv('DEFAULT_NUM_FRAMES', '16')))
|
22 |
-
|
23 |
-
# ✅ CUDA 対応修正
|
24 |
-
device = "cuda" if torch.cuda.is_available() else "cpu"
|
25 |
-
|
26 |
-
pipe = DiffusionPipeline.from_pretrained(
|
27 |
-
'damo-vilab/text-to-video-ms-1.7b',
|
28 |
-
torch_dtype=torch.float16 if torch.cuda.is_available() else torch.float32,
|
29 |
-
variant='fp16' if torch.cuda.is_available() else None
|
30 |
-
).to(device)
|
31 |
-
|
32 |
-
pipe.scheduler = DPMSolverMultistepScheduler.from_config(pipe.scheduler.config)
|
33 |
-
pipe.enable_model_cpu_offload()
|
34 |
-
pipe.enable_vae_slicing()
|
35 |
-
|
36 |
-
def to_video(frames: list[np.ndarray], fps: int) -> str:
|
37 |
-
out_file = tempfile.NamedTemporaryFile(suffix='.mp4', delete=False)
|
38 |
-
writer = imageio.get_writer(out_file.name, format='FFMPEG', fps=fps)
|
39 |
-
for frame in frames:
|
40 |
-
writer.append_data(frame)
|
41 |
-
writer.close()
|
42 |
-
return out_file.name
|
43 |
-
|
44 |
-
def generate(prompt: str, seed: int, num_frames: int, num_inference_steps: int) -> str:
|
45 |
-
if seed == -1:
|
46 |
-
seed = random.randint(0, 1000000)
|
47 |
-
generator = torch.Generator(device).manual_seed(seed)
|
48 |
-
frames = pipe(
|
49 |
-
prompt,
|
50 |
-
num_inference_steps=num_inference_steps,
|
51 |
-
num_frames=num_frames,
|
52 |
-
generator=generator
|
53 |
-
).frames
|
54 |
-
return to_video(frames, 8)
|
55 |
-
|
56 |
-
examples = [
|
57 |
-
['An astronaut riding a horse.', 0, 16, 25],
|
58 |
-
['A panda eating bamboo on a rock.', 0, 16, 25],
|
59 |
-
['Spiderman is surfing.', 0, 16, 25],
|
60 |
-
]
|
61 |
-
|
62 |
-
with gr.Blocks() as gradio_interface:
|
63 |
-
gr.Markdown(DESCRIPTION)
|
64 |
-
with gr.Group():
|
65 |
-
with gr.Column(): # ✅ `gr.Box()` → `gr.Column()` に変更
|
66 |
-
with gr.Row(elem_id='prompt-container'):
|
67 |
-
prompt = gr.Textbox( # ✅ `gr.Text()` → `gr.Textbox()` に変更
|
68 |
-
label='Prompt',
|
69 |
-
show_label=False,
|
70 |
-
max_lines=1,
|
71 |
-
placeholder='Enter your prompt',
|
72 |
-
elem_id='prompt-text-input'
|
73 |
-
)
|
74 |
-
run_button = gr.Button('Generate video') # ✅ `.style()` 削除
|
75 |
-
|
76 |
-
result = gr.Video(label='Result', show_label=False, elem_id='gallery')
|
77 |
-
|
78 |
-
with gr.Accordion('Advanced options', open=False):
|
79 |
-
seed = gr.Slider(
|
80 |
-
label='Seed',
|
81 |
-
minimum=-1,
|
82 |
-
maximum=1000000,
|
83 |
-
step=1,
|
84 |
-
value=-1,
|
85 |
-
info='If set to -1, a different seed will be used each time.'
|
86 |
-
)
|
87 |
-
num_frames = gr.Slider(
|
88 |
-
label='Number of frames',
|
89 |
-
minimum=16,
|
90 |
-
maximum=MAX_NUM_FRAMES,
|
91 |
-
step=1,
|
92 |
-
value=16,
|
93 |
-
info='Note that the content of the video also changes when you change the number of frames.'
|
94 |
-
)
|
95 |
-
num_inference_steps = gr.Slider(
|
96 |
-
label='Number of inference steps',
|
97 |
-
minimum=10,
|
98 |
-
maximum=50,
|
99 |
-
step=1,
|
100 |
-
value=25
|
101 |
-
)
|
102 |
-
|
103 |
-
inputs = [prompt, seed, num_frames, num_inference_steps]
|
104 |
-
|
105 |
-
gr.Examples(
|
106 |
-
examples=examples,
|
107 |
-
inputs=inputs,
|
108 |
-
outputs=result,
|
109 |
-
fn=generate,
|
110 |
-
cache_examples=os.getenv('SYSTEM') == 'spaces'
|
111 |
-
)
|
112 |
-
|
113 |
-
prompt.submit(fn=generate, inputs=inputs, outputs=result)
|
114 |
-
run_button.click(fn=generate, inputs=inputs, outputs=result)
|
115 |
-
|
116 |
-
with gr.Accordion(label='We are hiring (Based in Beijing / Hangzhou, China.)', open=False):
|
117 |
-
gr.HTML("""
|
118 |
-
<div class="acknowledgments">
|
119 |
-
<p>
|
120 |
-
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.
|
121 |
-
</p>
|
122 |
-
<p><b>EMAIL: [email protected]</b></p>
|
123 |
-
</div>
|
124 |
-
""")
|
125 |
-
|
126 |
-
with gr.Accordion(label='Biases and content acknowledgment', open=False):
|
127 |
-
gr.HTML("""
|
128 |
-
<div class="acknowledgments">
|
129 |
-
<h4>Biases and content acknowledgment</h4>
|
130 |
-
<p>
|
131 |
-
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.
|
132 |
-
</p>
|
133 |
-
<p>
|
134 |
-
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>.
|
135 |
-
</p>
|
136 |
-
<p>
|
137 |
-
To learn more about the model, head to its <a href="https://huggingface.co/damo-vilab/modelscope-damo-text-to-video-synthesis" target="_blank">model card</a>.
|
138 |
-
</p>
|
139 |
-
</div>
|
140 |
-
""")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
controllers/gra_api/__init__.py
DELETED
File without changes
|
controllers/gra_api/api.py
DELETED
@@ -1,14 +0,0 @@
|
|
1 |
-
import gradio as gr
|
2 |
-
|
3 |
-
# API で呼び出す関数
|
4 |
-
def chat_api(message, username, temperature):
|
5 |
-
response = f"User: {username}, Message: {message}, Temperature: {temperature}"
|
6 |
-
return response
|
7 |
-
|
8 |
-
# Gradio のインターフェース
|
9 |
-
gradio_interface = gr.Interface(
|
10 |
-
fn=chat_api, # 関数
|
11 |
-
inputs=["text", "text", "number"], # 入力タイプ
|
12 |
-
outputs="text" # 出力タイプ
|
13 |
-
)
|
14 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|