Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,29 +1,25 @@
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
-
from
|
| 3 |
|
| 4 |
-
#
|
| 5 |
-
|
| 6 |
-
|
|
|
|
|
|
|
| 7 |
|
| 8 |
# Função para gerar SQL a partir de linguagem natural
|
| 9 |
def gerar_sql(consulta_natural):
|
| 10 |
-
#
|
| 11 |
-
|
| 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 |
|
|
|
|
| 1 |
+
import os
|
| 2 |
import gradio as gr
|
| 3 |
+
from huggingface_hub import InferenceClient
|
| 4 |
|
| 5 |
+
# Acessar a chave de API do secret
|
| 6 |
+
API_TOKEN = os.environ.get("HF_TOKEN")
|
| 7 |
+
|
| 8 |
+
# Inicialize o InferenceClient
|
| 9 |
+
client = InferenceClient(model="defog/sqlcoder", token=API_TOKEN)
|
| 10 |
|
| 11 |
# Função para gerar SQL a partir de linguagem natural
|
| 12 |
def gerar_sql(consulta_natural):
|
| 13 |
+
# Envia a consulta para a API
|
| 14 |
+
resposta = client.text_generation(prompt=consulta_natural, max_new_tokens=100)
|
| 15 |
+
return resposta
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
|
| 17 |
# Interface Gradio
|
| 18 |
interface = gr.Interface(
|
| 19 |
fn=gerar_sql,
|
| 20 |
inputs="text",
|
| 21 |
outputs="text",
|
| 22 |
+
title="Gerador de SQL",
|
| 23 |
description="Digite uma consulta em linguagem natural e gere a consulta SQL correspondente."
|
| 24 |
)
|
| 25 |
|