Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -7,18 +7,16 @@ from transformers import AutoTokenizer, AutoModelForCausalLM
|
|
| 7 |
|
| 8 |
torch.set_num_threads(1)
|
| 9 |
|
| 10 |
-
#
|
| 11 |
# MODEL
|
| 12 |
-
#
|
| 13 |
BASE_MODEL = "TinyLlama/TinyLlama-1.1B-Chat-v1.0"
|
| 14 |
|
| 15 |
print("Loading model...")
|
| 16 |
|
| 17 |
model = AutoModelForCausalLM.from_pretrained(
|
| 18 |
BASE_MODEL,
|
| 19 |
-
|
| 20 |
-
torch_dtype=torch.float32,
|
| 21 |
-
low_cpu_mem_usage=True,
|
| 22 |
)
|
| 23 |
|
| 24 |
tokenizer = AutoTokenizer.from_pretrained(BASE_MODEL)
|
|
@@ -26,16 +24,16 @@ tokenizer = AutoTokenizer.from_pretrained(BASE_MODEL)
|
|
| 26 |
model.eval()
|
| 27 |
print("Model ready")
|
| 28 |
|
| 29 |
-
#
|
| 30 |
# GENERATION
|
| 31 |
-
#
|
| 32 |
def generate_sql(question):
|
| 33 |
if not question.strip():
|
| 34 |
return "Enter SQL question."
|
| 35 |
|
| 36 |
prompt = f"""
|
| 37 |
You are a SQL expert.
|
| 38 |
-
|
| 39 |
|
| 40 |
User: {question}
|
| 41 |
SQL:
|
|
@@ -56,15 +54,15 @@ SQL:
|
|
| 56 |
|
| 57 |
return text.split("SQL:")[-1].strip()
|
| 58 |
|
| 59 |
-
#
|
| 60 |
# UI
|
| 61 |
-
#
|
| 62 |
demo = gr.Interface(
|
| 63 |
fn=generate_sql,
|
| 64 |
inputs=gr.Textbox(lines=3, label="SQL Question"),
|
| 65 |
outputs=gr.Textbox(lines=8, label="Generated SQL"),
|
| 66 |
title="SQL Generator (Portfolio Demo)",
|
| 67 |
-
description="Fast CPU
|
| 68 |
examples=[
|
| 69 |
["Find duplicate emails in users table"],
|
| 70 |
["Top 5 highest paid employees"],
|
|
|
|
| 7 |
|
| 8 |
torch.set_num_threads(1)
|
| 9 |
|
| 10 |
+
# βββββββββββββββββββββββββ
|
| 11 |
# MODEL
|
| 12 |
+
# βββββββββββββββββββββββββ
|
| 13 |
BASE_MODEL = "TinyLlama/TinyLlama-1.1B-Chat-v1.0"
|
| 14 |
|
| 15 |
print("Loading model...")
|
| 16 |
|
| 17 |
model = AutoModelForCausalLM.from_pretrained(
|
| 18 |
BASE_MODEL,
|
| 19 |
+
torch_dtype=torch.float32
|
|
|
|
|
|
|
| 20 |
)
|
| 21 |
|
| 22 |
tokenizer = AutoTokenizer.from_pretrained(BASE_MODEL)
|
|
|
|
| 24 |
model.eval()
|
| 25 |
print("Model ready")
|
| 26 |
|
| 27 |
+
# βββββββββββββββββββββββββ
|
| 28 |
# GENERATION
|
| 29 |
+
# βββββββββββββββββββββββββ
|
| 30 |
def generate_sql(question):
|
| 31 |
if not question.strip():
|
| 32 |
return "Enter SQL question."
|
| 33 |
|
| 34 |
prompt = f"""
|
| 35 |
You are a SQL expert.
|
| 36 |
+
Return ONLY SQL query.
|
| 37 |
|
| 38 |
User: {question}
|
| 39 |
SQL:
|
|
|
|
| 54 |
|
| 55 |
return text.split("SQL:")[-1].strip()
|
| 56 |
|
| 57 |
+
# βββββββββββββββββββββββββ
|
| 58 |
# UI
|
| 59 |
+
# βββββββββββββββββββββββββ
|
| 60 |
demo = gr.Interface(
|
| 61 |
fn=generate_sql,
|
| 62 |
inputs=gr.Textbox(lines=3, label="SQL Question"),
|
| 63 |
outputs=gr.Textbox(lines=8, label="Generated SQL"),
|
| 64 |
title="SQL Generator (Portfolio Demo)",
|
| 65 |
+
description="Fast CPU AI SQL generator.",
|
| 66 |
examples=[
|
| 67 |
["Find duplicate emails in users table"],
|
| 68 |
["Top 5 highest paid employees"],
|