Update app.py
Browse files
app.py
CHANGED
|
@@ -1,38 +1,33 @@
|
|
| 1 |
-
import gradio
|
| 2 |
from transformers import AutoModelForCausalLM, AutoTokenizer
|
|
|
|
| 3 |
|
| 4 |
-
#
|
| 5 |
model_id = "HridaAI/Hrida-T2SQL-3B-128k-V0.1"
|
| 6 |
tokenizer = AutoTokenizer.from_pretrained(model_id, trust_remote_code=True)
|
| 7 |
model = AutoModelForCausalLM.from_pretrained(model_id, torch_dtype=torch.float16, trust_remote_code=True)
|
| 8 |
|
| 9 |
-
# Define the
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
FOREIGN KEY (DepartmentID) REFERENCES Departments(DepartmentID)
|
| 22 |
-
);
|
| 23 |
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
# Prepare the input
|
| 33 |
-
messages = [{"role": "user", "content": prompt}]
|
| 34 |
-
inputs = tokenizer.apply_chat_template(messages, return_tensors="pt", add_generation_prompt=True)
|
| 35 |
|
| 36 |
-
#
|
| 37 |
-
|
| 38 |
-
print(tokenizer.decode(outputs[0]))
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 3 |
+
import torch
|
| 4 |
|
| 5 |
+
# Load the pre-trained model and tokenizer from Hugging Face Model Hub
|
| 6 |
model_id = "HridaAI/Hrida-T2SQL-3B-128k-V0.1"
|
| 7 |
tokenizer = AutoTokenizer.from_pretrained(model_id, trust_remote_code=True)
|
| 8 |
model = AutoModelForCausalLM.from_pretrained(model_id, torch_dtype=torch.float16, trust_remote_code=True)
|
| 9 |
|
| 10 |
+
# Define the function to generate SQL query from natural language input
|
| 11 |
+
def generate_sql(query):
|
| 12 |
+
# Tokenize input
|
| 13 |
+
inputs = tokenizer(query, return_tensors="pt")
|
| 14 |
+
|
| 15 |
+
# Generate the SQL query
|
| 16 |
+
outputs = model.generate(**inputs, max_new_tokens=256)
|
| 17 |
+
|
| 18 |
+
# Decode the generated output into a string
|
| 19 |
+
sql_query = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
| 20 |
+
|
| 21 |
+
return sql_query
|
|
|
|
|
|
|
| 22 |
|
| 23 |
+
# Create the Gradio interface
|
| 24 |
+
iface = gr.Interface(
|
| 25 |
+
fn=generate_sql,
|
| 26 |
+
inputs=gr.Textbox(lines=2, placeholder="Enter your natural language question here..."),
|
| 27 |
+
outputs="text",
|
| 28 |
+
title="Text to SQL Converter",
|
| 29 |
+
description="Convert natural language questions into SQL queries using the Hrida-T2SQL-3B model."
|
| 30 |
+
)
|
|
|
|
|
|
|
|
|
|
| 31 |
|
| 32 |
+
# Launch the interface
|
| 33 |
+
iface.launch()
|
|
|