File size: 2,060 Bytes
578017a dadc6d1 578017a dadc6d1 578017a a2670ba 578017a dadc6d1 0f16c64 dadc6d1 0f16c64 dadc6d1 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
---
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
1. Set up your environment variables in `.env` file:
```env
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
```
2. Install dependencies:
```bash
pip install -r requirements.txt
```
3. Run the web interface:
```bash
python app.py
```
4. Run the API server:
```bash
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:**
```json
{
"message": "tu pregunta aquí"
}
```
**Respuesta exitosa:**
```json
{
"message_id": "uuid-generado",
"status": "success"
}
```
### 2. Obtener Respuesta
**Endpoint:** `/ask`
**Método:** POST
**Headers:**
```
Content-Type: application/json
```
**Body:**
```json
{
"message_id": "uuid-del-mensaje"
}
```
**Respuesta exitosa:**
```json
{
"response": "respuesta del chatbot",
"status": "success"
}
```
## Ejemplo de uso de la API
1. Primero, envía tu pregunta:
```bash
curl -X POST http://localhost:5000/user_message \
-H "Content-Type: application/json" \
-d '{"message": "¿Cuántos usuarios hay en la base de datos?"}'
```
2. Luego, usa el message_id recibido para obtener la respuesta:
```bash
curl -X POST http://localhost:5000/ask \
-H "Content-Type: application/json" \
-d '{"message_id": "uuid-recibido"}'
```
Check out the [configuration reference](https://huggingface.co/docs/hub/spaces-config-reference) for more options.
|