Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,23 +1,29 @@
|
|
1 |
import gradio as gr
|
2 |
-
from transformers import AutoTokenizer,
|
3 |
|
4 |
# Carregar o modelo e o tokenizador
|
5 |
-
tokenizer = AutoTokenizer.from_pretrained("
|
6 |
-
model =
|
7 |
|
8 |
# Função para gerar SQL a partir de linguagem natural
|
9 |
def gerar_sql(consulta_natural):
|
|
|
10 |
inputs = tokenizer(consulta_natural, return_tensors="pt", max_length=512, truncation=True)
|
|
|
|
|
11 |
outputs = model.generate(**inputs, max_length=512)
|
|
|
|
|
12 |
sql_gerado = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
|
|
13 |
return sql_gerado
|
14 |
|
15 |
-
# Interface Gradio
|
16 |
interface = gr.Interface(
|
17 |
fn=gerar_sql,
|
18 |
inputs="text",
|
19 |
outputs="text",
|
20 |
-
title="Gerador de SQL",
|
21 |
description="Digite uma consulta em linguagem natural e gere a consulta SQL correspondente."
|
22 |
)
|
23 |
|
|
|
1 |
import gradio as gr
|
2 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM
|
3 |
|
4 |
# Carregar o modelo e o tokenizador
|
5 |
+
tokenizer = AutoTokenizer.from_pretrained("defog/sqlcoder")
|
6 |
+
model = AutoModelForCausalLM.from_pretrained("defog/sqlcoder")
|
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 com SQLCoder",
|
27 |
description="Digite uma consulta em linguagem natural e gere a consulta SQL correspondente."
|
28 |
)
|
29 |
|