Spaces:
Running
on
Zero
Running
on
Zero
test
Browse files- controllers/gra_03_programfromdoc/programfromdoc.py +1 -66
- models/__init__.py +0 -0
- models/ride.py +12 -3
- mysite/interpreter/process.py +3 -0
controllers/gra_03_programfromdoc/programfromdoc.py
CHANGED
@@ -8,75 +8,10 @@ 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 |
-
@dataclass
|
14 |
-
class Ride:
|
15 |
-
ride_id: Optional[int] = field(default=None)
|
16 |
-
rideable_type: str = ''
|
17 |
-
start_station_id: int = 0
|
18 |
-
start_station_name: str = ''
|
19 |
-
end_station_id: int = 0
|
20 |
-
end_station_name: str = ''
|
21 |
-
started_at: str = ''
|
22 |
-
ended_at: str = ''
|
23 |
-
member_casual: str = ''
|
24 |
|
25 |
-
def connect_to_db():
|
26 |
-
conn = psycopg2.connect(
|
27 |
-
dbname="neondb",
|
28 |
-
user="miyataken999",
|
29 |
-
password="yz1wPf4KrWTm",
|
30 |
-
host="ep-odd-mode-93794521.us-east-2.aws.neon.tech",
|
31 |
-
port=5432,
|
32 |
-
sslmode="require"
|
33 |
-
)
|
34 |
-
return conn
|
35 |
|
36 |
-
def create_ride(ride: Ride):
|
37 |
-
conn = connect_to_db()
|
38 |
-
cur = conn.cursor()
|
39 |
-
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",
|
40 |
-
(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))
|
41 |
-
ride_id = cur.fetchone()[0]
|
42 |
-
conn.commit()
|
43 |
-
cur.close()
|
44 |
-
conn.close()
|
45 |
-
return ride_id
|
46 |
-
|
47 |
-
def read_rides():
|
48 |
-
conn = connect_to_db()
|
49 |
-
cur = conn.cursor()
|
50 |
-
cur.execute("SELECT * FROM rides")
|
51 |
-
rides = cur.fetchall()
|
52 |
-
conn.close()
|
53 |
-
return rides
|
54 |
-
|
55 |
-
def read_ride(ride_id: int):
|
56 |
-
conn = connect_to_db()
|
57 |
-
cur = conn.cursor()
|
58 |
-
cur.execute("SELECT * FROM rides WHERE ride_id = %s", (ride_id,))
|
59 |
-
ride = cur.fetchone()
|
60 |
-
conn.close()
|
61 |
-
return ride
|
62 |
-
|
63 |
-
def update_ride(ride: Ride):
|
64 |
-
conn = connect_to_db()
|
65 |
-
cur = conn.cursor()
|
66 |
-
no_process_file(ride.start_station_name,ride.end_station_name)
|
67 |
-
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",
|
68 |
-
(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))
|
69 |
-
conn.commit()
|
70 |
-
cur.close()
|
71 |
-
conn.close()
|
72 |
-
|
73 |
-
def delete_ride(ride_id: int):
|
74 |
-
conn = connect_to_db()
|
75 |
-
cur = conn.cursor()
|
76 |
-
cur.execute("DELETE FROM rides WHERE ride_id = %s", (ride_id,))
|
77 |
-
conn.commit()
|
78 |
-
cur.close()
|
79 |
-
conn.close()
|
80 |
|
81 |
gradio_interface = gr.Interface(
|
82 |
fn=process_file,
|
|
|
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 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
14 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
15 |
|
16 |
gradio_interface = gr.Interface(
|
17 |
fn=process_file,
|
models/__init__.py
ADDED
File without changes
|
models/ride.py
CHANGED
@@ -7,8 +7,8 @@ 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 |
@dataclass
|
14 |
class Ride:
|
@@ -76,4 +76,13 @@ def delete_ride(ride_id: int):
|
|
76 |
cur.execute("DELETE FROM rides WHERE ride_id = %s", (ride_id,))
|
77 |
conn.commit()
|
78 |
cur.close()
|
79 |
-
conn.close()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
@dataclass
|
14 |
class Ride:
|
|
|
76 |
cur.execute("DELETE FROM rides WHERE ride_id = %s", (ride_id,))
|
77 |
conn.commit()
|
78 |
cur.close()
|
79 |
+
conn.close()
|
80 |
+
|
81 |
+
def test_set_lide(input="test",foldername="test"):
|
82 |
+
ride = Ride(
|
83 |
+
rideable_type="rideable_type",
|
84 |
+
start_station_name=input,
|
85 |
+
end_station_name=foldername,
|
86 |
+
)
|
87 |
+
create_ride(ride)
|
88 |
+
return [[r[0], r[1], r[2], r[3], r[4], r[5], r[6], r[7], r[8]] for r in read_rides()]
|
mysite/interpreter/process.py
CHANGED
@@ -9,6 +9,7 @@ from mysite.libs.logger import logger
|
|
9 |
import async_timeout
|
10 |
import asyncio
|
11 |
import mysite.interpreter.interpreter_config
|
|
|
12 |
|
13 |
GENERATION_TIMEOUT_SEC=60
|
14 |
BASE_PATH = "/home/user/app/controllers/"
|
@@ -86,6 +87,8 @@ def process_file(fileobj, prompt, foldername):
|
|
86 |
except Exception as e:
|
87 |
return f"Error writing prompt to file: {str(e)}"
|
88 |
time.sleep(1)
|
|
|
|
|
89 |
try:
|
90 |
proc = subprocess.Popen(
|
91 |
["make", "run", foldername],
|
|
|
9 |
import async_timeout
|
10 |
import asyncio
|
11 |
import mysite.interpreter.interpreter_config
|
12 |
+
from models.ride import test_set_lide
|
13 |
|
14 |
GENERATION_TIMEOUT_SEC=60
|
15 |
BASE_PATH = "/home/user/app/controllers/"
|
|
|
87 |
except Exception as e:
|
88 |
return f"Error writing prompt to file: {str(e)}"
|
89 |
time.sleep(1)
|
90 |
+
#foldernameの登録
|
91 |
+
test_set_lide(prompt,foldername)
|
92 |
try:
|
93 |
proc = subprocess.Popen(
|
94 |
["make", "run", foldername],
|