Svngoku commited on
Commit
d8dc116
1 Parent(s): f3e875e

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +40 -0
app.py ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+
3
+
4
+ def generate_sql(schema, query):
5
+ messages = [
6
+ {"role": "system", "content": f"""You are a SQL assistant. Use the following database schema to answer the user's questions:\n{schema}"""},
7
+ {"role": "user", "content": query},
8
+ ]
9
+ inputs = tokenizer.apply_chat_template(
10
+ messages,
11
+ tokenize=True,
12
+ add_generation_prompt=True,
13
+ return_tensors="pt",
14
+ ).to("cuda")
15
+
16
+ text_streamer = TextStreamer(tokenizer, skip_prompt=True)
17
+ outputs = model.generate(
18
+ input_ids=inputs,
19
+ streamer=text_streamer,
20
+ max_new_tokens=400,
21
+ use_cache=True,
22
+ temperature=0.1, # Adjust temperature as needed
23
+ min_p=0.1,
24
+ )
25
+ generated_text = tokenizer.batch_decode(outputs)[0]
26
+ return generated_text
27
+
28
+
29
+ iface = gr.Interface(
30
+ fn=generate_sql,
31
+ inputs=[
32
+ gr.Textbox(label="Database Schema", lines=5),
33
+ gr.Textbox(label="SQL Query"),
34
+ ],
35
+ outputs=gr.Textbox(label="Generated SQL"),
36
+ title="SQL Assistant",
37
+ description="Enter a database schema and a SQL query to get the corresponding SQL code.",
38
+ )
39
+
40
+ iface.launch()