Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -60,12 +60,14 @@ def text2sql(dataset_name, query_input):
|
|
| 60 |
first_parquet = get_first_parquet(dataset_name)
|
| 61 |
except Exception as error:
|
| 62 |
return {
|
|
|
|
|
|
|
| 63 |
query_output: "",
|
| 64 |
df:pd.DataFrame([{"error": f"❌ Could not get dataset schema. {error=}"}])
|
| 65 |
}
|
| 66 |
|
| 67 |
first_parquet_url = first_parquet["url"]
|
| 68 |
-
print(first_parquet_url)
|
| 69 |
con = duckdb.connect()
|
| 70 |
con.execute("INSTALL 'httpfs'; LOAD httpfs;")
|
| 71 |
# could get from Parquet instead?
|
|
@@ -89,6 +91,8 @@ def text2sql(dataset_name, query_input):
|
|
| 89 |
sql_output = query_remote_model(text)
|
| 90 |
except Exception as error:
|
| 91 |
return {
|
|
|
|
|
|
|
| 92 |
query_output: "",
|
| 93 |
df:pd.DataFrame([{"error": f"❌ Unable to get the SQL query based on the text. {error=}"}])
|
| 94 |
}
|
|
@@ -100,6 +104,8 @@ def text2sql(dataset_name, query_input):
|
|
| 100 |
finally:
|
| 101 |
con.close()
|
| 102 |
return {
|
|
|
|
|
|
|
| 103 |
query_output:sql_output,
|
| 104 |
df:query_result
|
| 105 |
}
|
|
@@ -112,7 +118,9 @@ with gr.Blocks() as demo:
|
|
| 112 |
dataset_name = gr.Textbox("sksayril/medicine-info", label="Dataset Name")
|
| 113 |
query_input = gr.Textbox("How many rows there are?", label="Ask something about your data")
|
| 114 |
btn = gr.Button("Generate SQL")
|
|
|
|
|
|
|
| 115 |
query_output = gr.Textbox(label="Output SQL", interactive= False)
|
| 116 |
df = gr.DataFrame(datatype="markdown")
|
| 117 |
-
btn.click(text2sql, inputs=[dataset_name, query_input], outputs=[query_output,df])
|
| 118 |
demo.launch(debug=True)
|
|
|
|
| 60 |
first_parquet = get_first_parquet(dataset_name)
|
| 61 |
except Exception as error:
|
| 62 |
return {
|
| 63 |
+
schema_output: "",
|
| 64 |
+
prompt_output: "",
|
| 65 |
query_output: "",
|
| 66 |
df:pd.DataFrame([{"error": f"❌ Could not get dataset schema. {error=}"}])
|
| 67 |
}
|
| 68 |
|
| 69 |
first_parquet_url = first_parquet["url"]
|
| 70 |
+
print(f"getting schema from {first_parquet_url}")
|
| 71 |
con = duckdb.connect()
|
| 72 |
con.execute("INSTALL 'httpfs'; LOAD httpfs;")
|
| 73 |
# could get from Parquet instead?
|
|
|
|
| 91 |
sql_output = query_remote_model(text)
|
| 92 |
except Exception as error:
|
| 93 |
return {
|
| 94 |
+
schema_output: ddl_create,
|
| 95 |
+
prompt_output: text,
|
| 96 |
query_output: "",
|
| 97 |
df:pd.DataFrame([{"error": f"❌ Unable to get the SQL query based on the text. {error=}"}])
|
| 98 |
}
|
|
|
|
| 104 |
finally:
|
| 105 |
con.close()
|
| 106 |
return {
|
| 107 |
+
schema_output: ddl_create,
|
| 108 |
+
prompt_output: text,
|
| 109 |
query_output:sql_output,
|
| 110 |
df:query_result
|
| 111 |
}
|
|
|
|
| 118 |
dataset_name = gr.Textbox("sksayril/medicine-info", label="Dataset Name")
|
| 119 |
query_input = gr.Textbox("How many rows there are?", label="Ask something about your data")
|
| 120 |
btn = gr.Button("Generate SQL")
|
| 121 |
+
schema_output = gr.Textbox(label="Parquet Schema as CREATE DDL", interactive= False)
|
| 122 |
+
prompt_output = gr.Textbox(label="Generated prompt", interactive= False)
|
| 123 |
query_output = gr.Textbox(label="Output SQL", interactive= False)
|
| 124 |
df = gr.DataFrame(datatype="markdown")
|
| 125 |
+
btn.click(text2sql, inputs=[dataset_name, query_input], outputs=[schema_output, prompt_output, query_output,df])
|
| 126 |
demo.launch(debug=True)
|