metadata
title: Chatbot SQL Agent with Gemini
emoji: 🔍
colorFrom: blue
colorTo: purple
sdk: gradio
sdk_version: 5.41.1
app_file: app.py
pinned: false
Chatbot SQL Agent with Gemini
A powerful chatbot that can answer questions by querying your SQL database using Google's Gemini model.
Features
- Natural language to SQL query conversion
- Interactive chat interface
- Direct database connectivity
- Powered by Google's Gemini AI
- RESTful API endpoints for integration
Setup
- Set up your environment variables in
.env
file:
DB_USER=tu_usuario
DB_PASSWORD=tu_contraseña
DB_HOST=tu_servidor
DB_NAME=tu_base_de_datos
GOOGLE_API_KEY=tu_api_key_de_google
- Install dependencies:
pip install -r requirements.txt
- Run the web interface:
python app.py
- Run the API server:
python api.py
API Usage
La API proporciona dos endpoints principales:
1. Enviar Mensaje de Usuario
Endpoint: /user_message
Método: POST
Headers:
Content-Type: application/json
Body:
{
"message": "tu pregunta aquí"
}
Respuesta exitosa:
{
"message_id": "uuid-generado",
"status": "success"
}
2. Obtener Respuesta
Endpoint: /ask
Método: POST
Headers:
Content-Type: application/json
Body:
{
"message_id": "uuid-del-mensaje"
}
Respuesta exitosa:
{
"response": "respuesta del chatbot",
"status": "success"
}
Ejemplo de uso de la API
- Primero, envía tu pregunta:
curl -X POST http://localhost:5000/user_message \
-H "Content-Type: application/json" \
-d '{"message": "¿Cuántos usuarios hay en la base de datos?"}'
- Luego, usa el message_id recibido para obtener la respuesta:
curl -X POST http://localhost:5000/ask \
-H "Content-Type: application/json" \
-d '{"message_id": "uuid-recibido"}'
Check out the configuration reference for more options.