pup-py commited on
Commit
f469b00
·
1 Parent(s): 8f06d79
Files changed (3) hide show
  1. history.json +1 -3
  2. main.py +18 -15
  3. sql.py +3 -1
history.json CHANGED
@@ -1,6 +1,4 @@
1
  {"id": "01HWDNFA8QB96PV3RQCEPSG3C2", "q": "SELECT 42 AS answer", "alias": "example1", "template": "SELECT {x} AS {colname}", "definitions": "# Define variables: one '=' per line\nx=42\ncolname='answer'", "kwargs": {"x": 42, "colname": "answer"}, "rows": 1, "cols": 1, "source_id": null, "start": "2024-04-26 16:58:09.479", "end": "2024-04-26 16:58:09.479"}
2
  {"id": "01HWDNFA8QTEA1Y1V229501RMF", "q": "SELECT\n Symbol,\n Number,\n Mass,\n Abundance\nFROM 'https://raw.githubusercontent.com/ekwan/cctk/master/cctk/data/isotopes.csv'", "alias": "example2", "template": "SELECT\n Symbol,\n Number,\n Mass,\n Abundance\nFROM '{url}'", "definitions": "url = https://raw.githubusercontent.com/ekwan/cctk/master/cctk/data/isotopes.csv", "kwargs": {"url": "https://raw.githubusercontent.com/ekwan/cctk/master/cctk/data/isotopes.csv"}, "rows": 354, "cols": 4, "source_id": null, "start": "2024-04-26 16:58:13.425", "end": "2024-04-26 16:58:13.725"}
3
  {"id": "01HWE3CN3BPK6S4XT9B7H3GMSA", "q": "SELECT *\nFROM 'history.json'\nORDER BY id DESC", "alias": "example3", "template": "SELECT *\nFROM 'history.json'\nORDER BY id DESC", "kwargs": {}, "definitions": "", "rows": 2, "cols": 11, "source_id": null, "start": "2024-04-26 21:01:13.707", "end": "2024-04-26 21:01:13.709"}
4
- {"id": "01HWENFDHB146M2F5EBJ63J3RT", "q": "SELECT 42 AS answer", "alias": null, "template": "SELECT {x} AS {colname}", "kwargs": {"x": 42, "colname": "answer"}, "definitions": "x = 42\ncolname = 'answer'", "rows": 1, "cols": 1, "source_id": "01HWDNFA8QB96PV3RQCEPSG3C2", "start": "2024-04-27 02:17:18.635", "end": "2024-04-27 02:17:18.635"}
5
- {"id": "01HWENFH1770F6BHMT8AQ5T5P6", "q": "SELECT\n Symbol,\n Number,\n Mass,\n Abundance\nFROM 'https://raw.githubusercontent.com/ekwan/cctk/master/cctk/data/isotopes.csv'", "alias": null, "template": "SELECT\n Symbol,\n Number,\n Mass,\n Abundance\nFROM '{url}'", "kwargs": {"url": "https://raw.githubusercontent.com/ekwan/cctk/master/cctk/data/isotopes.csv"}, "definitions": "url = 'https://raw.githubusercontent.com/ekwan/cctk/master/cctk/data/isotopes.csv'", "rows": 354, "cols": 4, "source_id": "01HWDNFA8QTEA1Y1V229501RMF", "start": "2024-04-27 02:17:22.215", "end": "2024-04-27 02:17:22.597"}
6
- {"id": "01HWENFK7DG526WTNYNJ7VWW1Q", "q": "SELECT *\nFROM 'history.json'\nORDER BY id DESC", "alias": null, "template": "SELECT *\nFROM 'history.json'\nORDER BY id DESC", "kwargs": {}, "definitions": "", "rows": 5, "cols": 11, "source_id": "01HWE3CN3BPK6S4XT9B7H3GMSA", "start": "2024-04-27 02:17:24.462", "end": "2024-04-27 02:17:24.470"}
 
1
  {"id": "01HWDNFA8QB96PV3RQCEPSG3C2", "q": "SELECT 42 AS answer", "alias": "example1", "template": "SELECT {x} AS {colname}", "definitions": "# Define variables: one '=' per line\nx=42\ncolname='answer'", "kwargs": {"x": 42, "colname": "answer"}, "rows": 1, "cols": 1, "source_id": null, "start": "2024-04-26 16:58:09.479", "end": "2024-04-26 16:58:09.479"}
2
  {"id": "01HWDNFA8QTEA1Y1V229501RMF", "q": "SELECT\n Symbol,\n Number,\n Mass,\n Abundance\nFROM 'https://raw.githubusercontent.com/ekwan/cctk/master/cctk/data/isotopes.csv'", "alias": "example2", "template": "SELECT\n Symbol,\n Number,\n Mass,\n Abundance\nFROM '{url}'", "definitions": "url = https://raw.githubusercontent.com/ekwan/cctk/master/cctk/data/isotopes.csv", "kwargs": {"url": "https://raw.githubusercontent.com/ekwan/cctk/master/cctk/data/isotopes.csv"}, "rows": 354, "cols": 4, "source_id": null, "start": "2024-04-26 16:58:13.425", "end": "2024-04-26 16:58:13.725"}
3
  {"id": "01HWE3CN3BPK6S4XT9B7H3GMSA", "q": "SELECT *\nFROM 'history.json'\nORDER BY id DESC", "alias": "example3", "template": "SELECT *\nFROM 'history.json'\nORDER BY id DESC", "kwargs": {}, "definitions": "", "rows": 2, "cols": 11, "source_id": null, "start": "2024-04-26 21:01:13.707", "end": "2024-04-26 21:01:13.709"}
4
+ {"id": "01HWK493FKWHNGN8PTZJ4JCVZT", "q": "SELECT nothing", "alias": "bad_example", "template": "SELECT nothing", "kwargs": {}, "definitions": "", "rows": null, "cols": null, "source_id": null, "start": "2024-04-28 19:53:11.444", "end": "2024-04-28 19:53:11.444"}
 
 
main.py CHANGED
@@ -95,6 +95,8 @@ def query_from_request(sql_input, definitions, request: gr.Request):
95
  url_query_params = dict(request.query_params)
96
  query_id = url_query_params.get("q")
97
  alias = url_query_params.get("alias")
 
 
98
  q = Q.from_history(query_id=query_id, alias=alias)
99
  iframe_src = f"/q?query_id={q.source_id}"
100
  else:
@@ -118,7 +120,7 @@ def query_from_request(sql_input, definitions, request: gr.Request):
118
  sql_input = q.template
119
  definitions = f"{q.definitions}"
120
  editor_url = "".join([
121
- f"http://{host}/sql?",
122
  f"q={query_id}" if query_id else "",
123
  f"&alias={alias}" if alias else "",
124
  ])
@@ -135,9 +137,10 @@ with gr.Blocks(
135
  with gr.Column(scale=2, min_width=450):
136
  caption1 = gr.Markdown("# SQL Editor\nClick buttons below to see examples")
137
  with gr.Row():
138
- ex1_button = gr.Button("Variables", link="/sql?alias=example1")
139
- ex2_button = gr.Button("URL", link="/sql?alias=example2")
140
- ex3_button = gr.Button("Local File", link="/sql?alias=example3")
 
141
  definitions = gr.Code(label="Definitions", lines=2, interactive=True)
142
  sql_input = gr.Code(label="SQL Query", language="sql", lines=25, interactive=True)
143
  run_button = gr.Button("run", variant="primary")
@@ -167,18 +170,18 @@ def change_hf_host(request: gr.Request):
167
  return host
168
 
169
 
170
- app = gr.mount_gradio_app(app, gradio_sql_interface, path="/sql")
171
 
172
- @app.get("/")
173
- # def redirect_hack():
174
- # return RedirectResponse("/redirecting")
175
 
176
- # @app.get("/redirecting")
177
- def redirect_to_example():
178
- hf_space_host = getenv("SPACE_HOST")
179
- if hf_space_host:
180
- return RedirectResponse(f"https://{hf_space_host}/sql?alias=example1")
181
- else:
182
- return RedirectResponse("/sql?alias=example1")
183
 
184
  # return RedirectResponse("/sql?alias=example1")
 
95
  url_query_params = dict(request.query_params)
96
  query_id = url_query_params.get("q")
97
  alias = url_query_params.get("alias")
98
+ if not query_id and not alias:
99
+ alias = "example1"
100
  q = Q.from_history(query_id=query_id, alias=alias)
101
  iframe_src = f"/q?query_id={q.source_id}"
102
  else:
 
120
  sql_input = q.template
121
  definitions = f"{q.definitions}"
122
  editor_url = "".join([
123
+ f"http://{host}/?",
124
  f"q={query_id}" if query_id else "",
125
  f"&alias={alias}" if alias else "",
126
  ])
 
137
  with gr.Column(scale=2, min_width=450):
138
  caption1 = gr.Markdown("# SQL Editor\nClick buttons below to see examples")
139
  with gr.Row():
140
+ ex1_button = gr.Button("Variables", link="/?alias=example1")
141
+ ex2_button = gr.Button("URL", link="/?alias=example2")
142
+ ex3_button = gr.Button("Local File", link="/?alias=example3")
143
+ ex4_button = gr.Button("Bad Query", link="/?alias=bad_example")
144
  definitions = gr.Code(label="Definitions", lines=2, interactive=True)
145
  sql_input = gr.Code(label="SQL Query", language="sql", lines=25, interactive=True)
146
  run_button = gr.Button("run", variant="primary")
 
170
  return host
171
 
172
 
173
+ app = gr.mount_gradio_app(app, gradio_sql_interface, path="/")
174
 
175
+ # @app.get("/")
176
+ # # def redirect_hack():
177
+ # # return RedirectResponse("/redirecting")
178
 
179
+ # # @app.get("/redirecting")
180
+ # def redirect_to_example():
181
+ # hf_space_host = getenv("SPACE_HOST")
182
+ # if hf_space_host:
183
+ # return RedirectResponse(f"https://{hf_space_host}/sql?alias=example1")
184
+ # else:
185
+ # return RedirectResponse("/sql?alias=example1")
186
 
187
  # return RedirectResponse("/sql?alias=example1")
sql.py CHANGED
@@ -174,9 +174,11 @@ EX2 = Q(
174
 
175
  EX3 = Q(
176
  """
177
- SELECT /
178
  FROM 'history.json'
179
  ORDER BY id DESC
180
  """,
181
  alias="example3",
182
  )
 
 
 
174
 
175
  EX3 = Q(
176
  """
177
+ SELECT *
178
  FROM 'history.json'
179
  ORDER BY id DESC
180
  """,
181
  alias="example3",
182
  )
183
+
184
+ EX4 = Q("SELECT nothing", alias="bad_example")