omeryentur commited on
Commit
42ff3ef
·
verified ·
1 Parent(s): a696ee1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -25
app.py CHANGED
@@ -4,45 +4,40 @@ from huggingface_hub import hf_hub_download
4
  import gradio as gr
5
  import time
6
 
7
-
8
-
9
  model_path = hf_hub_download(
10
- repo_id="omeryentur/phi-3-sql",
11
- filename="phi-3-sql.Q4_K_M.gguf",
12
  use_auth_token=True
13
  )
14
 
 
15
  llm = Llama(
16
- model_path=model_path,
17
- n_ctx=512,
18
  n_threads=1,
19
  )
20
 
21
- def generate_sql_query(text_input_schema:str,text_input_question: str):
22
- global pattern_counter
23
-
24
  try:
25
- prompt = f"""<|system|>
26
- {text_input_schema}
27
-
28
- <|user|>
29
- {text_input_question}
30
-
31
- <|sql|>"""
32
 
 
33
  completion = llm(
34
- prompt,
35
- max_tokens=512,
36
- temperature=0,
37
  stop=["<end_of_turn>"]
38
  )
39
 
40
- generated_pattern = completion['choices'][0]['text'].strip()
 
41
  return generated_pattern
42
-
43
  except Exception as e:
44
- return {"error": e}
45
 
 
46
  with gr.Blocks() as demo:
47
  gr.Markdown("# Sql Query")
48
 
@@ -51,14 +46,14 @@ with gr.Blocks() as demo:
51
  text_input_schema = gr.TextArea(label="Schema")
52
  text_input_question = gr.Textbox(label="question")
53
  generate_btn = gr.Button("Create Sql Query")
54
-
55
  with gr.Row():
56
  with gr.Column():
57
  output = gr.JSON(label="Sql Query:")
58
 
59
  generate_btn.click(
60
- fn=generate_sql_query,
61
- inputs=[text_input_schema,text_input_question],
62
  outputs=[output]
63
  )
64
 
 
4
  import gradio as gr
5
  import time
6
 
7
+ # Download the model from Hugging Face
 
8
  model_path = hf_hub_download(
9
+ repo_id="omeryentur/phi-3-sql",
10
+ filename="phi-3-sql.Q4_K_M.gguf",
11
  use_auth_token=True
12
  )
13
 
14
+ # Initialize the Llama model
15
  llm = Llama(
16
+ model_path=model_path,
17
+ n_ctx=512,
18
  n_threads=1,
19
  )
20
 
21
+ def generate_sql_query(text_input_schema: str, text_input_question: str):
 
 
22
  try:
23
+ # Construct the prompt for the model
24
+ prompt = f"""<|system|> {text_input_schema} <|user|> {text_input_question} <|sql|>"""
 
 
 
 
 
25
 
26
+ # Generate SQL query
27
  completion = llm(
28
+ prompt,
29
+ max_tokens=512,
30
+ temperature=0,
31
  stop=["<end_of_turn>"]
32
  )
33
 
34
+ # Extract and return the generated SQL query
35
+ generated_pattern = completion['choices'][0]['text'].strip()
36
  return generated_pattern
 
37
  except Exception as e:
38
+ return {"error": str(e)}
39
 
40
+ # Create Gradio interface
41
  with gr.Blocks() as demo:
42
  gr.Markdown("# Sql Query")
43
 
 
46
  text_input_schema = gr.TextArea(label="Schema")
47
  text_input_question = gr.Textbox(label="question")
48
  generate_btn = gr.Button("Create Sql Query")
49
+
50
  with gr.Row():
51
  with gr.Column():
52
  output = gr.JSON(label="Sql Query:")
53
 
54
  generate_btn.click(
55
+ fn=generate_sql_query,
56
+ inputs=[text_input_schema, text_input_question],
57
  outputs=[output]
58
  )
59