Spaces:
Running
Running
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import torch
|
| 3 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 4 |
+
|
| 5 |
+
MODEL_ID = "melihemin/qwen2.5-0.5b-text2sql-full"
|
| 6 |
+
|
| 7 |
+
tokenizer = AutoTokenizer.from_pretrained(MODEL_ID)
|
| 8 |
+
model = AutoModelForCausalLM.from_pretrained(
|
| 9 |
+
MODEL_ID,
|
| 10 |
+
torch_dtype=torch.float16,
|
| 11 |
+
device_map="auto"
|
| 12 |
+
)
|
| 13 |
+
|
| 14 |
+
def text_to_sql(question):
|
| 15 |
+
prompt = f"""### Question:
|
| 16 |
+
{question}
|
| 17 |
+
|
| 18 |
+
### SQL:
|
| 19 |
+
"""
|
| 20 |
+
inputs = tokenizer(prompt, return_tensors="pt")
|
| 21 |
+
outputs = model.generate(
|
| 22 |
+
**inputs,
|
| 23 |
+
max_new_tokens=128,
|
| 24 |
+
do_sample=False
|
| 25 |
+
)
|
| 26 |
+
return tokenizer.decode(outputs[0], skip_special_tokens=True)
|
| 27 |
+
|
| 28 |
+
demo = gr.Interface(
|
| 29 |
+
fn=text_to_sql,
|
| 30 |
+
inputs=gr.Textbox(
|
| 31 |
+
lines=4,
|
| 32 |
+
placeholder="How many heads of the departments are older than 56?"
|
| 33 |
+
),
|
| 34 |
+
outputs="text",
|
| 35 |
+
title="Text to SQL Demo",
|
| 36 |
+
description="Qwen2.5-0.5B fine-tuned for Text-to-SQL"
|
| 37 |
+
)
|
| 38 |
+
|
| 39 |
+
demo.launch()
|