Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -39,7 +39,7 @@ Response:
|
|
| 39 |
if model.config.decoder_start_token_id is None:
|
| 40 |
model.config.decoder_start_token_id = tokenizer.pad_token_id
|
| 41 |
|
| 42 |
-
# Generate SQL output
|
| 43 |
with torch.no_grad():
|
| 44 |
generated_ids = model.generate(
|
| 45 |
input_ids=inputs["input_ids"],
|
|
@@ -56,7 +56,29 @@ Response:
|
|
| 56 |
generated_sql = generated_sql.split(";")[0].strip() + ";" # Keep only the first valid SQL query
|
| 57 |
return generated_sql
|
| 58 |
|
| 59 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 60 |
iface = gr.Interface(
|
| 61 |
fn=generate_sql,
|
| 62 |
inputs=[
|
|
@@ -65,9 +87,10 @@ iface = gr.Interface(
|
|
| 65 |
],
|
| 66 |
outputs="text",
|
| 67 |
title="Text-to-SQL Generator",
|
| 68 |
-
description=
|
| 69 |
theme="compact",
|
| 70 |
allow_flagging="never"
|
| 71 |
)
|
| 72 |
|
| 73 |
iface.launch()
|
|
|
|
|
|
| 39 |
if model.config.decoder_start_token_id is None:
|
| 40 |
model.config.decoder_start_token_id = tokenizer.pad_token_id
|
| 41 |
|
| 42 |
+
# Generate SQL output using no_grad for optimized CPU usage.
|
| 43 |
with torch.no_grad():
|
| 44 |
generated_ids = model.generate(
|
| 45 |
input_ids=inputs["input_ids"],
|
|
|
|
| 56 |
generated_sql = generated_sql.split(";")[0].strip() + ";" # Keep only the first valid SQL query
|
| 57 |
return generated_sql
|
| 58 |
|
| 59 |
+
# Guide text with detailed instructions and an example.
|
| 60 |
+
guide_text = """
|
| 61 |
+
# Text-to-SQL Inference App Guide
|
| 62 |
+
**Overview:**
|
| 63 |
+
This app uses a fine-tuned FLAN-T5 model to generate SQL queries based on your inputs.
|
| 64 |
+
|
| 65 |
+
**How to Use:**
|
| 66 |
+
- **Context:** Enter your database schema (table definitions, DDL statements, sample data).
|
| 67 |
+
- **Query:** Enter a natural language query describing the desired SQL operation.
|
| 68 |
+
- Click **Generate SQL** to see the model-generated SQL query.
|
| 69 |
+
|
| 70 |
+
**Example:**
|
| 71 |
+
- **Context:**
|
| 72 |
+
CREATE TABLE students (id INT PRIMARY KEY, name VARCHAR(100), age INT, grade CHAR(1)); INSERT INTO students (id, name, age, grade) VALUES (1, 'Alice', 14, 'A'), (2, 'Bob', 15, 'B');
|
| 73 |
+
|
| 74 |
+
- **Query:**
|
| 75 |
+
Retrieve the names of students who are 15 years old.
|
| 76 |
+
|
| 77 |
+
The generated SQL might look like:
|
| 78 |
+
SELECT name FROM students WHERE age = 15;
|
| 79 |
+
"""
|
| 80 |
+
|
| 81 |
+
# Create Gradio interface.
|
| 82 |
iface = gr.Interface(
|
| 83 |
fn=generate_sql,
|
| 84 |
inputs=[
|
|
|
|
| 87 |
],
|
| 88 |
outputs="text",
|
| 89 |
title="Text-to-SQL Generator",
|
| 90 |
+
description=guide_text,
|
| 91 |
theme="compact",
|
| 92 |
allow_flagging="never"
|
| 93 |
)
|
| 94 |
|
| 95 |
iface.launch()
|
| 96 |
+
|