richardr1126 commited on
Commit
80be5da
1 Parent(s): 8a0ec5f
Files changed (2) hide show
  1. app.py +10 -1
  2. requirements.txt +1 -2
app.py CHANGED
@@ -9,6 +9,7 @@ from transformers import (
9
  )
10
  import gradio as gr
11
  import torch
 
12
 
13
  model_name = os.getenv("HF_MODEL_NAME", None)
14
  tok = AutoTokenizer.from_pretrained(model_name)
@@ -74,8 +75,16 @@ def bot(input_message: str, db_info="", temperature=0.1, top_p=0.9, top_k=0, rep
74
 
75
  # Split the text by "|", and get the last element in the list which should be the final query
76
  final_query = partial_text.split("|")[1].strip()
 
 
 
 
 
 
 
 
77
  # Convert SQL to markdown (not required, but just to show how to use the markdown module)
78
- final_query_markdown = f"```sql\n{final_query}\n```"
79
  return final_query_markdown
80
 
81
  with gr.Blocks(css_theme="light") as demo:
 
9
  )
10
  import gradio as gr
11
  import torch
12
+ import sqlparse
13
 
14
  model_name = os.getenv("HF_MODEL_NAME", None)
15
  tok = AutoTokenizer.from_pretrained(model_name)
 
75
 
76
  # Split the text by "|", and get the last element in the list which should be the final query
77
  final_query = partial_text.split("|")[1].strip()
78
+
79
+ try:
80
+ # Attempt to format SQL query using sqlparse
81
+ formatted_query = sqlparse.format(final_query, reindent=True, keyword_case='upper')
82
+ except Exception:
83
+ # If formatting fails, use the original, unformatted query
84
+ formatted_query = final_query
85
+
86
  # Convert SQL to markdown (not required, but just to show how to use the markdown module)
87
+ final_query_markdown = f"```sql\n{formatted_query}\n```"
88
  return final_query_markdown
89
 
90
  with gr.Blocks(css_theme="light") as demo:
requirements.txt CHANGED
@@ -7,5 +7,4 @@ bitsandbytes
7
  scipy
8
  transformers
9
  accelerate
10
- huggingface_hub
11
- markdown
 
7
  scipy
8
  transformers
9
  accelerate
10
+ sqlparse