abhishek23HF commited on
Commit
43ac4b3
1 Parent(s): 3250872

Upload 2 files

Browse files
Files changed (2) hide show
  1. app (1).py +49 -0
  2. requirements (1).txt +3 -0
app (1).py ADDED
@@ -0,0 +1,49 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ import streamlit as st
3
+
4
+ import torch
5
+ from peft import PeftModel, PeftConfig
6
+ from transformers import AutoModelForCausalLM, AutoTokenizer
7
+ model_name = "NL2SQL_BLOOMZ-3B"
8
+ HUGGING_FACE_USER_NAME = "abhishek23HF"
9
+
10
+ peft_model_id = f"{HUGGING_FACE_USER_NAME}/{model_name}"
11
+ config = PeftConfig.from_pretrained(peft_model_id)
12
+ model = AutoModelForCausalLM.from_pretrained(config.base_model_name_or_path, return_dict=True, load_in_8bit=False)
13
+ tokenizer = AutoTokenizer.from_pretrained(config.base_model_name_or_path)
14
+
15
+ # Load the Lora model
16
+ model = PeftModel.from_pretrained(model, peft_model_id)
17
+
18
+
19
+ # from IPython.display import display, Markdown
20
+
21
+ def make_inference(db_id, question):
22
+ batch = tokenizer(f"""
23
+ ### INSTRUCTION\n
24
+ Below is a User Question for a SQL DATABASE. Your job is to write a SQL Query for the given question from the user for that particular Database.
25
+ \n\n
26
+ ### DATABASE_ID:\n{db_id}\n
27
+ ### USER QUESTION:\n{question}\n\n
28
+ ### SQL QUERY:\n
29
+ """, return_tensors='pt')
30
+
31
+ with torch.cuda.amp.autocast():
32
+ output_tokens = model.generate(**batch, max_new_tokens=200)
33
+
34
+ return tokenizer.decode(output_tokens[0], skip_special_tokens=True)
35
+
36
+
37
+
38
+ # Create two text input boxes
39
+ text_input_db_id= st.text_input("DB ID")
40
+ text_input_question = st.text_input("User Query")
41
+
42
+ # make_inference(your_db_id_here, your_db_query_here)
43
+
44
+ # Display the text input boxes
45
+
46
+ if st.button('Submit'):
47
+ st.write(make_inference(text_input_db_id, text_input_question))
48
+
49
+
requirements (1).txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ peft
2
+ torch
3
+ transformers @ git+https://github.com/huggingface/transformers