Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,21 +1,32 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
from transformers import
|
| 3 |
|
| 4 |
-
#
|
| 5 |
-
|
|
|
|
| 6 |
|
| 7 |
-
def
|
| 8 |
-
#
|
| 9 |
-
|
| 10 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
|
| 12 |
# Define the Gradio interface
|
| 13 |
iface = gr.Interface(
|
| 14 |
-
fn=
|
| 15 |
-
inputs=gr.Textbox(lines=2, placeholder="Enter
|
| 16 |
-
outputs=gr.Textbox(),
|
| 17 |
-
title="
|
| 18 |
-
description="This app uses
|
| 19 |
)
|
| 20 |
|
| 21 |
# Launch the app
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
from transformers import T5Tokenizer, T5ForConditionalGeneration
|
| 3 |
|
| 4 |
+
# Load the tokenizer and model
|
| 5 |
+
tokenizer = T5Tokenizer.from_pretrained('t5-small')
|
| 6 |
+
model = T5ForConditionalGeneration.from_pretrained('t5-small')
|
| 7 |
|
| 8 |
+
def generate_sql(question):
|
| 9 |
+
# Format the question for the model if needed. For example:
|
| 10 |
+
# input_text = f"translate English to SQL: {question}"
|
| 11 |
+
input_text = f"{question}" # Directly use the question if the model is fine-tuned for SQL generation
|
| 12 |
+
|
| 13 |
+
# Tokenize the input text
|
| 14 |
+
input_ids = tokenizer.encode(input_text, return_tensors="pt")
|
| 15 |
+
|
| 16 |
+
# Generate the output sequence
|
| 17 |
+
output_ids = model.generate(input_ids, max_length=512, num_beams=5)[0]
|
| 18 |
+
|
| 19 |
+
# Decode the generated ids to get the SQL query
|
| 20 |
+
sql_query = tokenizer.decode(output_ids, skip_special_tokens=True)
|
| 21 |
+
return sql_query
|
| 22 |
|
| 23 |
# Define the Gradio interface
|
| 24 |
iface = gr.Interface(
|
| 25 |
+
fn=generate_sql,
|
| 26 |
+
inputs=gr.Textbox(lines=2, placeholder="Enter your question here..."),
|
| 27 |
+
outputs=gr.Textbox(),
|
| 28 |
+
title="Natural Language to SQL",
|
| 29 |
+
description="This app uses a Seq2Seq model to generate SQL queries from natural language questions."
|
| 30 |
)
|
| 31 |
|
| 32 |
# Launch the app
|