JeffersonCorreiax commited on
Commit
6189794
·
verified ·
1 Parent(s): 2413e26

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +31 -0
app.py ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
3
+
4
+ # Carregar o modelo e o tokenizador
5
+ tokenizer = AutoTokenizer.from_pretrained("t5-small")
6
+ model = AutoModelForSeq2SeqLM.from_pretrained("t5-small")
7
+
8
+ # Função para gerar SQL a partir de linguagem natural
9
+ def gerar_sql(consulta_natural):
10
+ # Tokenizar a consulta em linguagem natural
11
+ inputs = tokenizer(consulta_natural, return_tensors="pt", max_length=512, truncation=True)
12
+
13
+ # Gerar a consulta SQL
14
+ outputs = model.generate(**inputs, max_length=512)
15
+
16
+ # Decodificar a saída para texto
17
+ sql_gerado = tokenizer.decode(outputs[0], skip_special_tokens=True)
18
+
19
+ return sql_gerado
20
+
21
+ # Interface Gradio
22
+ interface = gr.Interface(
23
+ fn=gerar_sql,
24
+ inputs="text",
25
+ outputs="text",
26
+ title="Gerador de SQL",
27
+ description="Digite uma consulta em linguagem natural e gere a consulta SQL correspondente."
28
+ )
29
+
30
+ # Iniciar a interface
31
+ interface.launch()