Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -86,6 +86,23 @@ def detect_plot_intent(nl_query):
|
|
86 |
plot_keywords = ['plot', 'graph', 'chart', 'distribution', 'visualize', 'trend', 'histogram', 'bar', 'line', 'scatter', 'pie']
|
87 |
return any(keyword in nl_query.lower() for keyword in plot_keywords)
|
88 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
89 |
def generate_plot(nl_query, result_df):
|
90 |
if not detect_plot_intent(nl_query):
|
91 |
return None, ""
|
|
|
86 |
plot_keywords = ['plot', 'graph', 'chart', 'distribution', 'visualize', 'trend', 'histogram', 'bar', 'line', 'scatter', 'pie']
|
87 |
return any(keyword in nl_query.lower() for keyword in plot_keywords)
|
88 |
|
89 |
+
|
90 |
+
def execute_query(sql_query):
|
91 |
+
"""
|
92 |
+
Executes the SQL query and returns the results.
|
93 |
+
"""
|
94 |
+
if sql_query.startswith("Error"):
|
95 |
+
return None, sql_query
|
96 |
+
|
97 |
+
try:
|
98 |
+
con = duckdb.connect()
|
99 |
+
con.execute(f"CREATE OR REPLACE VIEW contract_data AS SELECT * FROM '{dataset_path}'")
|
100 |
+
result_df = con.execute(sql_query).fetchdf()
|
101 |
+
con.close()
|
102 |
+
return result_df, ""
|
103 |
+
except Exception as e:
|
104 |
+
return None, f"Error executing query: {e}"
|
105 |
+
|
106 |
def generate_plot(nl_query, result_df):
|
107 |
if not detect_plot_intent(nl_query):
|
108 |
return None, ""
|