Team Ai
Apppublic

Jason990407/text-2-sql

sourceHugging Faceupdated 3y agoView on Hugging Face
0likes
app.py64 linesDownload Raw Back to root
1import streamlit as st2import torch3from transformers import pipeline4from transformers import AutoTokenizer, AutoModelForCausalLM5 6model = pipeline(7    model = "Jason990407/llama2-7b-text2sql",8    # torch_dtype = torch.float16,9    # device_map = "auto",10)11 12st.title("Llama2-7b-text2sql Demo ๐Ÿ™ƒ")13 14# Create an input text box15input_text = st.text_input("Enter your text for converting to SQL", "")16 17# Create a button to trigger model inference18if st.button("Generate"):19    # Perform inference using the loaded model20    result = model("""You are a powerful text-to-SQL model. Your job is to answer questions about a database. You are given a question and context regarding one or more tables.21 22You must output the SQL query that answers the question."23### Input:" + 24 25input_text +26 27"### Response:28"""29, max_new_tokens=100)30    st.write("Prediction:", result)31 32# model = AutoModelForCausalLM.from_pretrained(33#     "Jason990407/llama2-7b-text2sql",34#     low_cpu_mem_usage=True,35#     device_map = "auto",36#     offload_folder="offload",37# )38 39# tokenizer = AutoTokenizer.from_pretrained("Jason990407/llama2-7b-text2sql")40# tokenizer.add_eos_token = True41# tokenizer.pad_token_id = 042# tokenizer.padding_side = "left"43 44# st.title("Llama2-7b-text2sql Demo ๐Ÿ™ƒ")45 46# input_text = st.text_input("Enter your text for converting to SQL", "")47 48# encoded_prompt = tokenizer("""You are a powerful text-to-SQL model. Your job is to answer questions about a database. You are given a question and context regarding one or more tables.49 50# You must output the SQL query that answers the question."51# ### Input:" + 52 53# input_text +54 55# "### Response:56# """57# )58 59# if st.button("Generate"):60#     output = model.generate(61#         input_ids = encoded_prompt,62#         max_new_tokens=100,63#     )64#     st.write(tokenizer.decode(output)[0])