| --- |
| 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. |
| |