Spaces:
Sleeping
Sleeping
Create app.py
Browse files
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()
|