Quazim0t0 commited on
Commit
811c7ec
ยท
verified ยท
1 Parent(s): dddb5bd

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +46 -46
app.py CHANGED
@@ -22,7 +22,6 @@ def process_sql_file(file_path):
22
  sql_content = file.read()
23
 
24
  # Split into individual statements
25
- # This assumes statements are separated by semicolons
26
  statements = sql_content.split(';')
27
 
28
  # Clear existing database
@@ -178,8 +177,41 @@ def query_sql(user_query: str) -> str:
178
  return result
179
 
180
  with gr.Blocks() as demo:
181
- # First create both interfaces
182
- with gr.Blocks() as query_interface:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
183
  gr.Markdown("""
184
  ## Data Query Interface
185
 
@@ -232,50 +264,18 @@ with gr.Blocks() as demo:
232
  fn=update_schema,
233
  outputs=[schema_display]
234
  )
235
-
236
- # Set query interface initially invisible
237
- query_interface.visible = False
238
-
239
- # Create upload interface
240
- with gr.Blocks() as upload_interface:
241
- gr.Markdown("""
242
- # Data Query Interface
243
 
244
- Upload your data file to begin.
245
-
246
- ### Supported File Types:
247
- - SQL (.sql): SQL file containing CREATE TABLE and INSERT statements
248
- - CSV (.csv): CSV file with headers that will be automatically converted to a table
249
-
250
- ### CSV Requirements:
251
- - Must include headers
252
- - First column will be used as the primary key
253
- - Column types will be automatically detected
254
-
255
- ### SQL Requirements:
256
- - Must contain valid SQL statements
257
- - Statements must be separated by semicolons
258
- - Should include CREATE TABLE and data insertion statements
259
- """)
260
-
261
- file_input = gr.File(
262
- label="Upload Data File",
263
- file_types=[".csv", ".sql"],
264
- type="filepath"
265
- )
266
- status = gr.Textbox(label="Status", interactive=False)
267
-
268
- def handle_upload(file):
269
- success, message = process_uploaded_file(file)
270
- if success:
271
- return message, gr.Blocks.update(visible=False), gr.Blocks.update(visible=True)
272
- return message, gr.Blocks.update(visible=True), gr.Blocks.update(visible=False)
273
-
274
- file_input.upload(
275
- fn=handle_upload,
276
- inputs=[file_input],
277
- outputs=[status, upload_interface, query_interface]
278
- )
279
 
280
  if __name__ == "__main__":
281
  demo.launch(server_name="0.0.0.0", server_port=7860, share=True)
 
22
  sql_content = file.read()
23
 
24
  # Split into individual statements
 
25
  statements = sql_content.split(';')
26
 
27
  # Clear existing database
 
177
  return result
178
 
179
  with gr.Blocks() as demo:
180
+ # Create both interfaces at the top level
181
+ upload_interface = gr.Blocks()
182
+ query_interface = gr.Blocks(visible=False)
183
+
184
+ # Create upload interface content
185
+ with upload_interface:
186
+ gr.Markdown("""
187
+ # Data Query Interface
188
+
189
+ Upload your data file to begin.
190
+
191
+ ### Supported File Types:
192
+ - SQL (.sql): SQL file containing CREATE TABLE and INSERT statements
193
+ - CSV (.csv): CSV file with headers that will be automatically converted to a table
194
+
195
+ ### CSV Requirements:
196
+ - Must include headers
197
+ - First column will be used as the primary key
198
+ - Column types will be automatically detected
199
+
200
+ ### SQL Requirements:
201
+ - Must contain valid SQL statements
202
+ - Statements must be separated by semicolons
203
+ - Should include CREATE TABLE and data insertion statements
204
+ """)
205
+
206
+ file_input = gr.File(
207
+ label="Upload Data File",
208
+ file_types=[".csv", ".sql"],
209
+ type="filepath"
210
+ )
211
+ status = gr.Textbox(label="Status", interactive=False)
212
+
213
+ # Create query interface content
214
+ with query_interface:
215
  gr.Markdown("""
216
  ## Data Query Interface
217
 
 
264
  fn=update_schema,
265
  outputs=[schema_display]
266
  )
 
 
 
 
 
 
 
 
267
 
268
+ def handle_upload(file):
269
+ success, message = process_uploaded_file(file)
270
+ if success:
271
+ return message, gr.update(visible=False), gr.update(visible=True)
272
+ return message, gr.update(visible=True), gr.update(visible=False)
273
+
274
+ file_input.upload(
275
+ fn=handle_upload,
276
+ inputs=[file_input],
277
+ outputs=[status, upload_interface, query_interface]
278
+ )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
279
 
280
  if __name__ == "__main__":
281
  demo.launch(server_name="0.0.0.0", server_port=7860, share=True)