Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from transformers import pipeline
|
| 3 |
+
|
| 4 |
+
# Load a text-to-SQL model. Can be swapped out for better ones later.
|
| 5 |
+
generator = pipeline("text2text-generation", model="mrm8488/t5-base-finetuned-wikiSQL")
|
| 6 |
+
|
| 7 |
+
def convert_to_sql(question):
|
| 8 |
+
prompt = f"translate English to SQL: {question}"
|
| 9 |
+
result = generator(prompt, max_length=256)[0]["generated_text"]
|
| 10 |
+
return result
|
| 11 |
+
|
| 12 |
+
demo = gr.Interface(
|
| 13 |
+
fn=convert_to_sql,
|
| 14 |
+
inputs=gr.Textbox(lines=2, placeholder="Ask a question about your data..."),
|
| 15 |
+
outputs="text",
|
| 16 |
+
title="Text-to-SQL Generator",
|
| 17 |
+
description="Enter a natural language question and get the SQL query for a table named 'sales_data'."
|
| 18 |
+
)
|
| 19 |
+
|
| 20 |
+
demo.launch()
|