arinbalyan commited on
Commit
63af92e
·
verified ·
1 Parent(s): 49e3c84

Upload folder using huggingface_hub

Browse files
Files changed (3) hide show
  1. README.md +10 -6
  2. app.py +65 -0
  3. requirements.txt +3 -0
README.md CHANGED
@@ -1,13 +1,17 @@
1
  ---
2
- title: Sql Copilot Chat
3
- emoji: 👀
4
- colorFrom: red
5
- colorTo: pink
6
  sdk: gradio
7
  sdk_version: 6.19.0
8
- python_version: '3.13'
9
  app_file: app.py
10
  pinned: false
11
  ---
12
 
13
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
 
 
 
 
 
1
  ---
2
+ title: SQL Copilot
3
+ emoji: 💾
4
+ colorFrom: blue
5
+ colorTo: gray
6
  sdk: gradio
7
  sdk_version: 6.19.0
 
8
  app_file: app.py
9
  pinned: false
10
  ---
11
 
12
+ # SQL Copilot
13
+
14
+ **Model:** arinbalyan/qwen-sql-copilot
15
+
16
+ ## Links
17
+ - **HF Profile:** [arinbalyan](https://huggingface.co/arinbalyan)
app.py ADDED
@@ -0,0 +1,65 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import AutoModelForCausalLM, AutoTokenizer
3
+ import torch
4
+
5
+ MODEL_ID = "arinbalyan/qwen-sql-copilot"
6
+
7
+ tokenizer = AutoTokenizer.from_pretrained(MODEL_ID)
8
+ if tokenizer.pad_token is None:
9
+ tokenizer.pad_token = tokenizer.eos_token
10
+
11
+ model = AutoModelForCausalLM.from_pretrained(
12
+ MODEL_ID,
13
+ torch_dtype=torch.float16,
14
+ device_map="auto",
15
+ )
16
+
17
+ def generate(prompt, history):
18
+ if not prompt.strip():
19
+ return "", history
20
+ inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
21
+ with torch.no_grad():
22
+ out = model.generate(
23
+ **inputs,
24
+ max_new_tokens=200,
25
+ temperature=0.8,
26
+ do_sample=True,
27
+ pad_token_id=tokenizer.eos_token_id,
28
+ )
29
+ response = tokenizer.decode(out[0][inputs.input_ids.shape[1]:], skip_special_tokens=True)
30
+ history.append((prompt, response.strip()))
31
+ return "", history
32
+
33
+ theme = (
34
+ gr.themes.Soft(primary_hue="blue", neutral_hue="slate")
35
+ .set(
36
+ button_primary_background_fill_hover="#2563eb",
37
+ button_primary_text_color="white",
38
+ input_background_fill="#f8fafc",
39
+ input_border_color="#e2e8f0",
40
+ input_border_color_focus="#2563eb",
41
+ )
42
+ )
43
+
44
+ css = """.gradio-container { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif !important; }
45
+ .main-header { text-align: center; padding: 2rem 1rem; background: linear-gradient(135deg, #2563eb 0%, #2563ebdd 100%); color: white; border-radius: 12px; margin-bottom: 1rem; }
46
+ .main-header h1 { font-size: 2rem; font-weight: 700; margin-bottom: 0.25rem; }
47
+ .main-header p { font-size: 1rem; opacity: 0.9; }
48
+ .footer { text-align: center; padding: 1rem; color: #64748b; font-size: 0.875rem; }"""
49
+
50
+ with gr.Blocks(title="SQL Copilot") as demo:
51
+ with gr.Row():
52
+ with gr.Column():
53
+ gr.HTML(f"""<div class="main-header"><h1>💾 SQL Copilot</h1><p>Generate with AI</p></div>""")
54
+ chatbot = gr.Chatbot(height=400)
55
+ msg = gr.Textbox(label="Prompt", placeholder='e.g., Show all users older than 30', lines=2)
56
+ with gr.Row():
57
+ submit = gr.Button("Generate", variant="primary", size="lg", scale=1)
58
+ clear = gr.Button("Clear", size="lg", scale=0)
59
+ gr.Examples(examples=["Show all users older than 30", "How many orders were placed last month?", "List employees with their department names", "Find the top 5 products by sales", "Count customers from each city"], inputs=msg, label="Try these")
60
+ gr.HTML(f"""<div class="footer">Qwen2.5-1.5B on sql-create-context</div>""")
61
+ submit.click(generate, [msg, chatbot], [msg, chatbot])
62
+ clear.click(lambda: None, None, chatbot, queue=False)
63
+
64
+ if __name__ == "__main__":
65
+ demo.launch(theme=theme, css=css)
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ transformers>=4.40
2
+ torch>=2.0
3
+ accelerate>=1.0