Spaces:
Runtime error
Runtime error
Commit
·
306462a
1
Parent(s):
fb100ca
Delete app.py
Browse files
app.py
DELETED
|
@@ -1,29 +0,0 @@
|
|
| 1 |
-
from flask import Flask, render_template, request, jsonify
|
| 2 |
-
from transformers import T5ForConditionalGeneration, T5Tokenizer
|
| 3 |
-
|
| 4 |
-
app = Flask(__name__)
|
| 5 |
-
|
| 6 |
-
# Load the trained model
|
| 7 |
-
model = T5ForConditionalGeneration.from_pretrained("text2sql")
|
| 8 |
-
tokenizer = T5Tokenizer.from_pretrained("t5-small")
|
| 9 |
-
|
| 10 |
-
@app.route('/')
|
| 11 |
-
def home():
|
| 12 |
-
return render_template('index.html')
|
| 13 |
-
|
| 14 |
-
@app.route('/predict', methods=['POST'])
|
| 15 |
-
def predict():
|
| 16 |
-
if request.method == 'POST':
|
| 17 |
-
input_text = request.form['input_text']
|
| 18 |
-
|
| 19 |
-
# Preprocess input
|
| 20 |
-
input_ids = tokenizer(input_text, return_tensors="pt", padding=True, truncation=True).input_ids
|
| 21 |
-
|
| 22 |
-
# Generate SQL query
|
| 23 |
-
output = model.generate(input_ids)
|
| 24 |
-
predicted_sql = tokenizer.decode(output[0], skip_special_tokens=True)
|
| 25 |
-
|
| 26 |
-
return render_template('index.html', input_text=input_text, predicted_sql=predicted_sql)
|
| 27 |
-
|
| 28 |
-
if __name__ == '__main__':
|
| 29 |
-
app.run()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|