Mustehson commited on
Commit
4fd7636
·
1 Parent(s): 5f1dc64

Created Full Table Path

Browse files
Files changed (1) hide show
  1. app.py +13 -7
app.py CHANGED
@@ -60,12 +60,21 @@ def update_tables(schema_name):
60
 
61
  # Get Schema
62
  def get_table_schema(table):
63
- result = conn.sql(f"SELECT sql FROM duckdb_tables() where table_name ='{table}';").df()
64
  ddl_create = result.iloc[0,0]
 
 
 
 
 
 
 
 
65
  return ddl_create
66
 
67
  # Get Prompt
68
- def get_prompt(schema, query_input):
 
69
  text = f"""
70
  ### Instruction:
71
  Your task is to generate valid duckdb SQL query to answer the following question.
@@ -98,9 +107,9 @@ def text2sql(table, query_input):
98
  result_output:pd.DataFrame([{"error": f"❌ Unable to get the SQL query based on the text. {e}"}])
99
  }
100
 
101
- schema = get_table_schema(table)
102
  print(f'Schema Generated...')
103
- prompt = get_prompt(schema, query_input)
104
  print(f'Prompt Generated...')
105
  try:
106
  print(f'Generating SQL... {model.device}')
@@ -131,9 +140,6 @@ def text2sql(table, query_input):
131
  result_output:query_result
132
  }
133
 
134
- # Load Databases Names
135
-
136
-
137
  # Custom CSS styling
138
  custom_css = """
139
  .gradio-container {
 
60
 
61
  # Get Schema
62
  def get_table_schema(table):
63
+ result = conn.sql(f"SELECT sql, database_name, schema_name FROM duckdb_tables() where table_name ='{table}';").df()
64
  ddl_create = result.iloc[0,0]
65
+ parent_database = result.iloc[0,1]
66
+ schema_name = result.iloc[0,2]
67
+ full_path = f"{parent_database}.{schema_name}.{table}"
68
+ if schema_name != "main":
69
+ old_path = f"{schema_name}.{table}"
70
+ else:
71
+ old_path = table
72
+ ddl_create = ddl_create.replace(old_path, full_path)
73
  return ddl_create
74
 
75
  # Get Prompt
76
+ def get_prompt(schema, query_input, parent_database):
77
+ schema = schema.replace()
78
  text = f"""
79
  ### Instruction:
80
  Your task is to generate valid duckdb SQL query to answer the following question.
 
107
  result_output:pd.DataFrame([{"error": f"❌ Unable to get the SQL query based on the text. {e}"}])
108
  }
109
 
110
+ schema, parent_database = get_table_schema(table)
111
  print(f'Schema Generated...')
112
+ prompt = get_prompt(schema, query_input, parent_database)
113
  print(f'Prompt Generated...')
114
  try:
115
  print(f'Generating SQL... {model.device}')
 
140
  result_output:query_result
141
  }
142
 
 
 
 
143
  # Custom CSS styling
144
  custom_css = """
145
  .gradio-container {