SiddharthHanje commited on
Commit
5506729
·
1 Parent(s): fa50899

Adding model to my space

Browse files
Files changed (2) hide show
  1. app.py +36 -0
  2. requirments.txt +2 -0
app.py ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
3
+
4
+ # Load model + tokenizer
5
+ model_name = "tscholak/cxmefzzi"
6
+ tokenizer = AutoTokenizer.from_pretrained(model_name)
7
+ model = AutoModelForSeq2SeqLM.from_pretrained(model_name)
8
+
9
+ def text_to_sql(question, schema=""):
10
+ """
11
+ Convert natural language question into SQL query.
12
+ Schema can be passed as a string (table + column names).
13
+ """
14
+ # Format input as Spider expects
15
+ if schema:
16
+ prompt = f"{schema} {question}"
17
+ else:
18
+ prompt = question
19
+
20
+ inputs = tokenizer(prompt, return_tensors="pt", truncation=True)
21
+ outputs = model.generate(**inputs, max_length=256)
22
+ sql_query = tokenizer.decode(outputs[0], skip_special_tokens=True)
23
+ return sql_query
24
+
25
+ # Define API endpoint (no UI)
26
+ iface = gr.Interface(
27
+ fn=text_to_sql,
28
+ inputs=[
29
+ gr.Textbox(label="Question"),
30
+ gr.Textbox(label="Schema (optional)", placeholder="table: columns, ...")
31
+ ],
32
+ outputs="text",
33
+ )
34
+
35
+ # Launch API (set share=True for external URL)
36
+ iface.launch()
requirments.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ gradio
2
+ transformers