Spaces:
Runtime error
Runtime error
Caleb Fahlgren
commited on
Commit
•
91c3a02
1
Parent(s):
6d4f7ef
use smaller dataset, improve graph
Browse files
app.py
CHANGED
@@ -86,7 +86,7 @@ def generate_query(dataset_id: str, query: str) -> str:
|
|
86 |
ddl = get_dataset_ddl(dataset_id)
|
87 |
|
88 |
system_prompt = f"""
|
89 |
-
You are an expert SQL assistant with access to the following
|
90 |
|
91 |
```sql
|
92 |
{ddl}
|
@@ -116,18 +116,24 @@ def generate_query(dataset_id: str, query: str) -> str:
|
|
116 |
|
117 |
def query_dataset(dataset_id: str, query: str) -> Tuple[pd.DataFrame, str, plt.Figure]:
|
118 |
response: SQLResponse = generate_query(dataset_id, query)
|
|
|
|
|
119 |
df = conn.execute(response.sql).fetchdf()
|
120 |
|
121 |
plot = None
|
122 |
|
123 |
if response.visualization_type == OutputTypes.LINECHART:
|
124 |
plot = df.plot(
|
125 |
-
kind="line", x=response.
|
126 |
).get_figure()
|
|
|
|
|
127 |
elif response.visualization_type == OutputTypes.BARCHART:
|
128 |
plot = df.plot(
|
129 |
-
kind="bar", x=response.
|
130 |
).get_figure()
|
|
|
|
|
131 |
|
132 |
markdown_output = f"""```sql\n{response.sql}\n```"""
|
133 |
return df, markdown_output, plot
|
@@ -139,7 +145,7 @@ with gr.Blocks() as demo:
|
|
139 |
label="Hub Dataset ID",
|
140 |
placeholder="Find your favorite dataset...",
|
141 |
search_type="dataset",
|
142 |
-
value="
|
143 |
)
|
144 |
user_query = gr.Textbox("", label="Ask anything...")
|
145 |
|
|
|
86 |
ddl = get_dataset_ddl(dataset_id)
|
87 |
|
88 |
system_prompt = f"""
|
89 |
+
You are an expert SQL assistant with access to the following PostgreSQL Table:
|
90 |
|
91 |
```sql
|
92 |
{ddl}
|
|
|
116 |
|
117 |
def query_dataset(dataset_id: str, query: str) -> Tuple[pd.DataFrame, str, plt.Figure]:
|
118 |
response: SQLResponse = generate_query(dataset_id, query)
|
119 |
+
|
120 |
+
print("Querying Parquet...")
|
121 |
df = conn.execute(response.sql).fetchdf()
|
122 |
|
123 |
plot = None
|
124 |
|
125 |
if response.visualization_type == OutputTypes.LINECHART:
|
126 |
plot = df.plot(
|
127 |
+
kind="line", x=response.label_key, y=response.data_key
|
128 |
).get_figure()
|
129 |
+
plt.xticks(rotation=45, ha="right")
|
130 |
+
plt.tight_layout()
|
131 |
elif response.visualization_type == OutputTypes.BARCHART:
|
132 |
plot = df.plot(
|
133 |
+
kind="bar", x=response.label_key, y=response.data_key
|
134 |
).get_figure()
|
135 |
+
plt.xticks(rotation=45, ha="right")
|
136 |
+
plt.tight_layout()
|
137 |
|
138 |
markdown_output = f"""```sql\n{response.sql}\n```"""
|
139 |
return df, markdown_output, plot
|
|
|
145 |
label="Hub Dataset ID",
|
146 |
placeholder="Find your favorite dataset...",
|
147 |
search_type="dataset",
|
148 |
+
value="gretelai/synthetic_text_to_sql",
|
149 |
)
|
150 |
user_query = gr.Textbox("", label="Ask anything...")
|
151 |
|