Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -11,10 +11,10 @@ def generate_sql(payload):
|
|
11 |
schema = payload.get("schema", "")
|
12 |
sample_rows = payload.get("sample_rows", [])
|
13 |
|
14 |
-
# Convert sample rows
|
15 |
rows_text = " ".join([str(row) for row in sample_rows]) if sample_rows else ""
|
16 |
|
17 |
-
# Construct prompt
|
18 |
prompt = (
|
19 |
f"You are a SQL expert.\n"
|
20 |
f"Schema: {schema}\n"
|
@@ -23,9 +23,8 @@ def generate_sql(payload):
|
|
23 |
f"Generate SQL:"
|
24 |
)
|
25 |
|
26 |
-
# Tokenize and generate SQL
|
27 |
input_ids = tokenizer(prompt, return_tensors="pt").input_ids
|
28 |
-
outputs = model.generate(input_ids, max_length=256, temperature=0.
|
29 |
sql = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
30 |
|
31 |
return sql
|
@@ -35,7 +34,8 @@ demo = gr.Interface(
|
|
35 |
inputs=gr.JSON(label="JSON (question, schema, sample_rows)"),
|
36 |
outputs="text",
|
37 |
title="FLAN-T5 Text-to-SQL",
|
38 |
-
description="Using FLAN-T5 to generate SQL from natural language and tabular schema."
|
|
|
39 |
)
|
40 |
|
41 |
demo.launch()
|
|
|
11 |
schema = payload.get("schema", "")
|
12 |
sample_rows = payload.get("sample_rows", [])
|
13 |
|
14 |
+
# Convert sample rows to a flat string
|
15 |
rows_text = " ".join([str(row) for row in sample_rows]) if sample_rows else ""
|
16 |
|
17 |
+
# Construct the prompt
|
18 |
prompt = (
|
19 |
f"You are a SQL expert.\n"
|
20 |
f"Schema: {schema}\n"
|
|
|
23 |
f"Generate SQL:"
|
24 |
)
|
25 |
|
|
|
26 |
input_ids = tokenizer(prompt, return_tensors="pt").input_ids
|
27 |
+
outputs = model.generate(input_ids, max_length=256, temperature=0.7)
|
28 |
sql = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
29 |
|
30 |
return sql
|
|
|
34 |
inputs=gr.JSON(label="JSON (question, schema, sample_rows)"),
|
35 |
outputs="text",
|
36 |
title="FLAN-T5 Text-to-SQL",
|
37 |
+
description="Using FLAN-T5 to generate SQL from natural language and tabular schema.",
|
38 |
+
allow_flagging="never"
|
39 |
)
|
40 |
|
41 |
demo.launch()
|