streamlit_app / app.py
McAwesomeville's picture
Update app.py
6d96c10
raw
history blame
1.08 kB
# app.py
import subprocess
subprocess.run(["pip", "install", "-r", "requirements.txt"])
import streamlit as st
from transformers import AutoModelForSeq2SeqLM
def main():
st.title("Hugging Face SQL Generator")
# Get user input
prompt = st.text_area("Enter your prompt:")
if st.button("Generate SQL"):
# Call a function to generate SQL using the Hugging Face model
sql_result = generate_sql(prompt)
# Display the SQL result
st.write("Generated SQL:")
st.code(sql_result, language="sql")
def generate_sql(prompt):
# Load the "NumbersStation/nsql-350M" model
model_name = "NumbersStation/nsql-350M"
model = AutoModelForSeq2SeqLM.from_pretrained(model_name)
tokenizer = AutoTokenizer.from_pretrained(model_name)
# Tokenize and generate SQL
inputs = tokenizer(prompt, return_tensors="pt")
outputs = model(**inputs)
# Decode the generated SQL
sql_query = tokenizer.batch_decode(outputs["output_ids"], skip_special_tokens=True)[0]
return sql_query
if __name__ == "__main__":
main()