Sid26Roy commited on
Commit
82a8738
·
verified ·
1 Parent(s): 9e5b30e

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -0
app.py ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import torch
3
+ from transformers import T5Tokenizer, T5ForConditionalGeneration
4
+
5
+ # Load model and tokenizer from local files
6
+ model_path = "./"
7
+ tokenizer = T5Tokenizer.from_pretrained(model_path)
8
+ model = T5ForConditionalGeneration.from_pretrained(model_path)
9
+ device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
10
+ model = model.to(device)
11
+ model.eval()
12
+
13
+ def generate_sql(user_input):
14
+ inputs = tokenizer(user_input, return_tensors="pt", truncation=True, padding=True).to(device)
15
+ with torch.no_grad():
16
+ outputs = model.generate(**inputs, max_length=512)
17
+ return tokenizer.decode(outputs[0], skip_special_tokens=True)
18
+
19
+ gr.Interface(
20
+ fn=generate_sql,
21
+ inputs=gr.Textbox(lines=15, placeholder="Paste your full SQL prompt here..."),
22
+ outputs=gr.Textbox(label="Generated SQL Query"),
23
+ title="HISAB AI – Text2SQL Generator",
24
+ description="Paste your schema + user query + instructions. Model returns a PostgreSQL query."
25
+ ).launch()