Spaces:
Runtime error
Runtime error
Commit
·
04efaa2
1
Parent(s):
0242c9e
Upload 2 files
Browse files- app.py +36 -0
- requirements.txt +4 -0
app.py
ADDED
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# app.py
|
2 |
+
|
3 |
+
import streamlit as st
|
4 |
+
from transformers import AutoModelForSeq2SeqLM, AutoTokenizer
|
5 |
+
|
6 |
+
def main():
|
7 |
+
st.title("Hugging Face SQL Generator")
|
8 |
+
|
9 |
+
# Get user input
|
10 |
+
prompt = st.text_area("Enter your prompt:")
|
11 |
+
|
12 |
+
if st.button("Generate SQL"):
|
13 |
+
# Call a function to generate SQL using the Hugging Face model
|
14 |
+
sql_result = generate_sql(prompt)
|
15 |
+
|
16 |
+
# Display the SQL result
|
17 |
+
st.write("Generated SQL:")
|
18 |
+
st.code(sql_result, language="sql")
|
19 |
+
|
20 |
+
def generate_sql(prompt):
|
21 |
+
# Load the "NumbersStation/nsql-350M" model
|
22 |
+
model_name = "NumbersStation/nsql-350M"
|
23 |
+
model = AutoModelForSeq2SeqLM.from_pretrained(model_name)
|
24 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
25 |
+
|
26 |
+
# Tokenize and generate SQL
|
27 |
+
inputs = tokenizer(prompt, return_tensors="pt")
|
28 |
+
outputs = model(**inputs)
|
29 |
+
|
30 |
+
# Decode the generated SQL
|
31 |
+
sql_query = tokenizer.batch_decode(outputs["output_ids"], skip_special_tokens=True)[0]
|
32 |
+
|
33 |
+
return sql_query
|
34 |
+
|
35 |
+
if __name__ == "__main__":
|
36 |
+
main()
|
requirements.txt
ADDED
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#requirements.txt
|
2 |
+
|
3 |
+
streamlit
|
4 |
+
transformers
|