Elyad commited on
Commit
c0c7d37
·
verified ·
1 Parent(s): 8f1b91c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +37 -4
app.py CHANGED
@@ -1,5 +1,38 @@
1
- # Load model directly
2
- from transformers import AutoTokenizer, AutoModelForCausalLM
3
 
4
- tokenizer = AutoTokenizer.from_pretrained("HridaAI/Hrida-T2SQL-3B-128k-V0.1", trust_remote_code=True)
5
- model = AutoModelForCausalLM.from_pretrained("HridaAI/Hrida-T2SQL-3B-128k-V0.1", trust_remote_code=True)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import torch
2
+ from transformers import AutoModelForCausalLM, AutoTokenizer
3
 
4
+ # Define the model and tokenizer
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 context and prompt
10
+ prompt = """
11
+ Answer to the query will be in the form of an SQL query.
12
+ ### Context: CREATE TABLE Employees (
13
+ EmployeeID INT PRIMARY KEY,
14
+ FirstName VARCHAR(50),
15
+ LastName VARCHAR(50),
16
+ Age INT,
17
+ DepartmentID INT,
18
+ Salary DECIMAL(10, 2),
19
+ DateHired DATE,
20
+ Active BOOLEAN,
21
+ FOREIGN KEY (DepartmentID) REFERENCES Departments(DepartmentID)
22
+ );
23
+
24
+ CREATE TABLE Departments (
25
+ DepartmentID INT PRIMARY KEY,
26
+ DepartmentName VARCHAR(100),
27
+ Location VARCHAR(100)
28
+ );
29
+ ### Input: Write a SQL query to select all the employees who are active.
30
+ ### Response:
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
+ # Generate the output
37
+ outputs = model.generate(inputs, max_length=300)
38
+ print(tokenizer.decode(outputs[0]))