Initial commit
Browse files- README.md +29 -3
- asistente_legal.ipynb +317 -0
- requirements.txt +3 -0
README.md
CHANGED
@@ -1,3 +1,29 @@
|
|
1 |
-
|
2 |
-
|
3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Asistente Jur铆dico Penal
|
2 |
+
|
3 |
+
Un asistente jur铆dico basado en IA que proporciona informaci贸n sobre el C贸digo Penal espa帽ol.
|
4 |
+
|
5 |
+
## Instalaci贸n
|
6 |
+
|
7 |
+
1. Clonar el repositorio:
|
8 |
+
```bash
|
9 |
+
git clone https://github.com/usuario/legal-assistant.git
|
10 |
+
|
11 |
+
2. Instalar dependencias:
|
12 |
+
```bash
|
13 |
+
pip install -r requirements.txt
|
14 |
+
|
15 |
+
3. Crear archivo .env con tu API key de OpenAI:
|
16 |
+
```bash
|
17 |
+
|
18 |
+
4. Uso:
|
19 |
+
Abrir legal_assistant.ipynb en Jupyter Notebook/Lab y ejecutar las celdas en orden.
|
20 |
+
|
21 |
+
* Licencia:
|
22 |
+
MIT License
|
23 |
+
|
24 |
+
|
25 |
+
|
26 |
+
|
27 |
+
|
28 |
+
|
29 |
+
|
asistente_legal.ipynb
ADDED
@@ -0,0 +1,317 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"cells": [
|
3 |
+
{
|
4 |
+
"cell_type": "markdown",
|
5 |
+
"id": "intro-markdown",
|
6 |
+
"metadata": {},
|
7 |
+
"source": [
|
8 |
+
"# 馃帗 Asistente Jur铆dico Penal con OpenAI y Gradio\n",
|
9 |
+
"\n",
|
10 |
+
"Este notebook implementa un asistente jur铆dico especializado en derecho penal espa帽ol utilizando la API de OpenAI y Gradio para la interfaz de usuario.\n",
|
11 |
+
"\n",
|
12 |
+
"## Requisitos\n",
|
13 |
+
"- Python 3.8+\n",
|
14 |
+
"- openai\n",
|
15 |
+
"- gradio\n",
|
16 |
+
"- python-dotenv"
|
17 |
+
]
|
18 |
+
},
|
19 |
+
{
|
20 |
+
"cell_type": "code",
|
21 |
+
"execution_count": 11,
|
22 |
+
"id": "6fc9dac1-93e9-4ecf-a1c8-809518a2b9ff",
|
23 |
+
"metadata": {},
|
24 |
+
"outputs": [
|
25 |
+
{
|
26 |
+
"name": "stdout",
|
27 |
+
"output_type": "stream",
|
28 |
+
"text": [
|
29 |
+
"Requirement already satisfied: openai in /home/v/anaconda3/lib/python3.12/site-packages (1.64.0)\n",
|
30 |
+
"Requirement already satisfied: gradio in /home/v/anaconda3/lib/python3.12/site-packages (5.17.1)\n",
|
31 |
+
"Requirement already satisfied: python-dotenv in /home/v/anaconda3/lib/python3.12/site-packages (0.21.0)\n",
|
32 |
+
"Requirement already satisfied: anyio<5,>=3.5.0 in /home/v/anaconda3/lib/python3.12/site-packages (from openai) (4.2.0)\n",
|
33 |
+
"Requirement already satisfied: distro<2,>=1.7.0 in /home/v/anaconda3/lib/python3.12/site-packages (from openai) (1.9.0)\n",
|
34 |
+
"Requirement already satisfied: httpx<1,>=0.23.0 in /home/v/anaconda3/lib/python3.12/site-packages (from openai) (0.27.0)\n",
|
35 |
+
"Requirement already satisfied: jiter<1,>=0.4.0 in /home/v/anaconda3/lib/python3.12/site-packages (from openai) (0.8.2)\n",
|
36 |
+
"Requirement already satisfied: pydantic<3,>=1.9.0 in /home/v/anaconda3/lib/python3.12/site-packages (from openai) (2.8.2)\n",
|
37 |
+
"Requirement already satisfied: sniffio in /home/v/anaconda3/lib/python3.12/site-packages (from openai) (1.3.0)\n",
|
38 |
+
"Requirement already satisfied: tqdm>4 in /home/v/anaconda3/lib/python3.12/site-packages (from openai) (4.66.5)\n",
|
39 |
+
"Requirement already satisfied: typing-extensions<5,>=4.11 in /home/v/anaconda3/lib/python3.12/site-packages (from openai) (4.11.0)\n",
|
40 |
+
"Requirement already satisfied: aiofiles<24.0,>=22.0 in /home/v/anaconda3/lib/python3.12/site-packages (from gradio) (23.2.1)\n",
|
41 |
+
"Requirement already satisfied: fastapi<1.0,>=0.115.2 in /home/v/anaconda3/lib/python3.12/site-packages (from gradio) (0.115.8)\n",
|
42 |
+
"Requirement already satisfied: ffmpy in /home/v/anaconda3/lib/python3.12/site-packages (from gradio) (0.5.0)\n",
|
43 |
+
"Requirement already satisfied: gradio-client==1.7.1 in /home/v/anaconda3/lib/python3.12/site-packages (from gradio) (1.7.1)\n",
|
44 |
+
"Requirement already satisfied: huggingface-hub>=0.28.1 in /home/v/anaconda3/lib/python3.12/site-packages (from gradio) (0.29.1)\n",
|
45 |
+
"Requirement already satisfied: jinja2<4.0 in /home/v/anaconda3/lib/python3.12/site-packages (from gradio) (3.1.4)\n",
|
46 |
+
"Requirement already satisfied: markupsafe~=2.0 in /home/v/anaconda3/lib/python3.12/site-packages (from gradio) (2.1.3)\n",
|
47 |
+
"Requirement already satisfied: numpy<3.0,>=1.0 in /home/v/anaconda3/lib/python3.12/site-packages (from gradio) (1.26.4)\n",
|
48 |
+
"Requirement already satisfied: orjson~=3.0 in /home/v/anaconda3/lib/python3.12/site-packages (from gradio) (3.10.15)\n",
|
49 |
+
"Requirement already satisfied: packaging in /home/v/anaconda3/lib/python3.12/site-packages (from gradio) (24.1)\n",
|
50 |
+
"Requirement already satisfied: pandas<3.0,>=1.0 in /home/v/anaconda3/lib/python3.12/site-packages (from gradio) (2.2.2)\n",
|
51 |
+
"Requirement already satisfied: pillow<12.0,>=8.0 in /home/v/anaconda3/lib/python3.12/site-packages (from gradio) (10.4.0)\n",
|
52 |
+
"Requirement already satisfied: pydub in /home/v/anaconda3/lib/python3.12/site-packages (from gradio) (0.25.1)\n",
|
53 |
+
"Requirement already satisfied: python-multipart>=0.0.18 in /home/v/anaconda3/lib/python3.12/site-packages (from gradio) (0.0.20)\n",
|
54 |
+
"Requirement already satisfied: pyyaml<7.0,>=5.0 in /home/v/anaconda3/lib/python3.12/site-packages (from gradio) (6.0.1)\n",
|
55 |
+
"Requirement already satisfied: ruff>=0.9.3 in /home/v/anaconda3/lib/python3.12/site-packages (from gradio) (0.9.7)\n",
|
56 |
+
"Requirement already satisfied: safehttpx<0.2.0,>=0.1.6 in /home/v/anaconda3/lib/python3.12/site-packages (from gradio) (0.1.6)\n",
|
57 |
+
"Requirement already satisfied: semantic-version~=2.0 in /home/v/anaconda3/lib/python3.12/site-packages (from gradio) (2.10.0)\n",
|
58 |
+
"Requirement already satisfied: starlette<1.0,>=0.40.0 in /home/v/anaconda3/lib/python3.12/site-packages (from gradio) (0.45.3)\n",
|
59 |
+
"Requirement already satisfied: tomlkit<0.14.0,>=0.12.0 in /home/v/anaconda3/lib/python3.12/site-packages (from gradio) (0.13.2)\n",
|
60 |
+
"Requirement already satisfied: typer<1.0,>=0.12 in /home/v/anaconda3/lib/python3.12/site-packages (from gradio) (0.15.1)\n",
|
61 |
+
"Requirement already satisfied: uvicorn>=0.14.0 in /home/v/anaconda3/lib/python3.12/site-packages (from gradio) (0.34.0)\n",
|
62 |
+
"Requirement already satisfied: fsspec in /home/v/anaconda3/lib/python3.12/site-packages (from gradio-client==1.7.1->gradio) (2024.6.1)\n",
|
63 |
+
"Requirement already satisfied: websockets<15.0,>=10.0 in /home/v/anaconda3/lib/python3.12/site-packages (from gradio-client==1.7.1->gradio) (14.2)\n",
|
64 |
+
"Requirement already satisfied: idna>=2.8 in /home/v/anaconda3/lib/python3.12/site-packages (from anyio<5,>=3.5.0->openai) (3.7)\n",
|
65 |
+
"Requirement already satisfied: certifi in /home/v/anaconda3/lib/python3.12/site-packages (from httpx<1,>=0.23.0->openai) (2024.8.30)\n",
|
66 |
+
"Requirement already satisfied: httpcore==1.* in /home/v/anaconda3/lib/python3.12/site-packages (from httpx<1,>=0.23.0->openai) (1.0.2)\n",
|
67 |
+
"Requirement already satisfied: h11<0.15,>=0.13 in /home/v/anaconda3/lib/python3.12/site-packages (from httpcore==1.*->httpx<1,>=0.23.0->openai) (0.14.0)\n",
|
68 |
+
"Requirement already satisfied: filelock in /home/v/anaconda3/lib/python3.12/site-packages (from huggingface-hub>=0.28.1->gradio) (3.13.1)\n",
|
69 |
+
"Requirement already satisfied: requests in /home/v/anaconda3/lib/python3.12/site-packages (from huggingface-hub>=0.28.1->gradio) (2.32.3)\n",
|
70 |
+
"Requirement already satisfied: python-dateutil>=2.8.2 in /home/v/anaconda3/lib/python3.12/site-packages (from pandas<3.0,>=1.0->gradio) (2.9.0.post0)\n",
|
71 |
+
"Requirement already satisfied: pytz>=2020.1 in /home/v/anaconda3/lib/python3.12/site-packages (from pandas<3.0,>=1.0->gradio) (2024.1)\n",
|
72 |
+
"Requirement already satisfied: tzdata>=2022.7 in /home/v/anaconda3/lib/python3.12/site-packages (from pandas<3.0,>=1.0->gradio) (2023.3)\n",
|
73 |
+
"Requirement already satisfied: annotated-types>=0.4.0 in /home/v/anaconda3/lib/python3.12/site-packages (from pydantic<3,>=1.9.0->openai) (0.6.0)\n",
|
74 |
+
"Requirement already satisfied: pydantic-core==2.20.1 in /home/v/anaconda3/lib/python3.12/site-packages (from pydantic<3,>=1.9.0->openai) (2.20.1)\n",
|
75 |
+
"Requirement already satisfied: click>=8.0.0 in /home/v/anaconda3/lib/python3.12/site-packages (from typer<1.0,>=0.12->gradio) (8.1.7)\n",
|
76 |
+
"Requirement already satisfied: shellingham>=1.3.0 in /home/v/anaconda3/lib/python3.12/site-packages (from typer<1.0,>=0.12->gradio) (1.5.4)\n",
|
77 |
+
"Requirement already satisfied: rich>=10.11.0 in /home/v/anaconda3/lib/python3.12/site-packages (from typer<1.0,>=0.12->gradio) (13.7.1)\n",
|
78 |
+
"Requirement already satisfied: six>=1.5 in /home/v/anaconda3/lib/python3.12/site-packages (from python-dateutil>=2.8.2->pandas<3.0,>=1.0->gradio) (1.16.0)\n",
|
79 |
+
"Requirement already satisfied: markdown-it-py>=2.2.0 in /home/v/anaconda3/lib/python3.12/site-packages (from rich>=10.11.0->typer<1.0,>=0.12->gradio) (2.2.0)\n",
|
80 |
+
"Requirement already satisfied: pygments<3.0.0,>=2.13.0 in /home/v/anaconda3/lib/python3.12/site-packages (from rich>=10.11.0->typer<1.0,>=0.12->gradio) (2.15.1)\n",
|
81 |
+
"Requirement already satisfied: charset-normalizer<4,>=2 in /home/v/anaconda3/lib/python3.12/site-packages (from requests->huggingface-hub>=0.28.1->gradio) (3.3.2)\n",
|
82 |
+
"Requirement already satisfied: urllib3<3,>=1.21.1 in /home/v/anaconda3/lib/python3.12/site-packages (from requests->huggingface-hub>=0.28.1->gradio) (2.2.3)\n",
|
83 |
+
"Requirement already satisfied: mdurl~=0.1 in /home/v/anaconda3/lib/python3.12/site-packages (from markdown-it-py>=2.2.0->rich>=10.11.0->typer<1.0,>=0.12->gradio) (0.1.0)\n"
|
84 |
+
]
|
85 |
+
}
|
86 |
+
],
|
87 |
+
"source": [
|
88 |
+
"!pip install openai gradio python-dotenv"
|
89 |
+
]
|
90 |
+
},
|
91 |
+
{
|
92 |
+
"cell_type": "code",
|
93 |
+
"execution_count": 13,
|
94 |
+
"id": "imports-cell",
|
95 |
+
"metadata": {},
|
96 |
+
"outputs": [],
|
97 |
+
"source": [
|
98 |
+
"import os\n",
|
99 |
+
"import gradio as gr\n",
|
100 |
+
"from openai import OpenAI\n",
|
101 |
+
"from dotenv import load_dotenv\n",
|
102 |
+
"\n",
|
103 |
+
"# Cargar variables de entorno\n",
|
104 |
+
"load_dotenv()\n",
|
105 |
+
"\n",
|
106 |
+
"# Configurar cliente OpenAI\n",
|
107 |
+
"client = OpenAI(\n",
|
108 |
+
" api_key=os.getenv(\"OPENAI_API_KEY\")\n",
|
109 |
+
")"
|
110 |
+
]
|
111 |
+
},
|
112 |
+
{
|
113 |
+
"cell_type": "code",
|
114 |
+
"execution_count": 15,
|
115 |
+
"id": "prompt-config",
|
116 |
+
"metadata": {},
|
117 |
+
"outputs": [],
|
118 |
+
"source": [
|
119 |
+
"# Sistema de prompt mejorado\n",
|
120 |
+
"SYSTEM_PROMPT = \"\"\"Eres un abogado penalista espa帽ol experto en el C贸digo Penal espa帽ol. \n",
|
121 |
+
"Tu objetivo es responder con precisi贸n, citando la legislaci贸n vigente y proporcionando contexto legal actualizado.\n",
|
122 |
+
"\n",
|
123 |
+
"### **Instrucciones de Respuesta:**\n",
|
124 |
+
"1. **Cita legal precisa:** \n",
|
125 |
+
" - Menciona siempre los art铆culos espec铆ficos del C贸digo Penal espa帽ol al inicio.\n",
|
126 |
+
" - Si el delito ha sido modificado en reformas recientes, indica en qu茅 consisti贸 la reforma.\n",
|
127 |
+
"\n",
|
128 |
+
"2. **Estructura clara:** \n",
|
129 |
+
" - Define el **tipo b谩sico del delito**.\n",
|
130 |
+
" - Explica los **subtipos agravados y atenuados** si existen.\n",
|
131 |
+
" - Cita los art铆culos correspondientes.\n",
|
132 |
+
"\n",
|
133 |
+
"3. **Jurisprudencia relevante:** \n",
|
134 |
+
" - Menciona sentencias recientes del Tribunal Supremo cuando sea posible.\n",
|
135 |
+
"\n",
|
136 |
+
"4. **Advertencia legal:** \n",
|
137 |
+
" - Aclara que es informaci贸n general y no constituye asesoramiento legal.\"\"\""
|
138 |
+
]
|
139 |
+
},
|
140 |
+
{
|
141 |
+
"cell_type": "code",
|
142 |
+
"execution_count": 17,
|
143 |
+
"id": "functions-cell",
|
144 |
+
"metadata": {},
|
145 |
+
"outputs": [],
|
146 |
+
"source": [
|
147 |
+
"# Historial global de chat\n",
|
148 |
+
"chat_history = []\n",
|
149 |
+
"\n",
|
150 |
+
"def consulta_penalista(mensaje, tipo_consulta):\n",
|
151 |
+
" \"\"\"Procesa una consulta jur铆dica y devuelve la respuesta del modelo.\"\"\"\n",
|
152 |
+
" global chat_history\n",
|
153 |
+
" chat_history.append({\"role\": \"user\", \"content\": f\"[{tipo_consulta}] {mensaje}\"})\n",
|
154 |
+
" \n",
|
155 |
+
" try:\n",
|
156 |
+
" respuesta = client.chat.completions.create(\n",
|
157 |
+
" model=\"gpt-4-turbo\",\n",
|
158 |
+
" messages=[{\"role\": \"system\", \"content\": SYSTEM_PROMPT}] + chat_history,\n",
|
159 |
+
" temperature=0.3\n",
|
160 |
+
" )\n",
|
161 |
+
" \n",
|
162 |
+
" respuesta_texto = respuesta.choices[0].message.content\n",
|
163 |
+
" chat_history.append({\"role\": \"assistant\", \"content\": respuesta_texto})\n",
|
164 |
+
" \n",
|
165 |
+
" historial_formateado = \"\\n\\n\".join([\n",
|
166 |
+
" f\"{'Usuario' if msg['role'] == 'user' else 'Asistente'}: {msg['content']}\"\n",
|
167 |
+
" for msg in chat_history\n",
|
168 |
+
" ])\n",
|
169 |
+
" \n",
|
170 |
+
" return respuesta_texto, historial_formateado\n",
|
171 |
+
" \n",
|
172 |
+
" except Exception as e:\n",
|
173 |
+
" return f\"Error al procesar la solicitud: {str(e)}\", \"\\n\".join(str(m) for m in chat_history)\n",
|
174 |
+
"\n",
|
175 |
+
"def limpiar_historial():\n",
|
176 |
+
" \"\"\"Limpia el historial de conversaci贸n.\"\"\"\n",
|
177 |
+
" global chat_history\n",
|
178 |
+
" chat_history = []\n",
|
179 |
+
" return \"\", \"Historial limpiado.\""
|
180 |
+
]
|
181 |
+
},
|
182 |
+
{
|
183 |
+
"cell_type": "code",
|
184 |
+
"execution_count": 19,
|
185 |
+
"id": "interface-cell",
|
186 |
+
"metadata": {},
|
187 |
+
"outputs": [
|
188 |
+
{
|
189 |
+
"name": "stdout",
|
190 |
+
"output_type": "stream",
|
191 |
+
"text": [
|
192 |
+
"* Running on local URL: http://127.0.0.1:7860\n",
|
193 |
+
"\n",
|
194 |
+
"To create a public link, set `share=True` in `launch()`.\n"
|
195 |
+
]
|
196 |
+
},
|
197 |
+
{
|
198 |
+
"data": {
|
199 |
+
"text/html": [
|
200 |
+
"<div><iframe src=\"http://127.0.0.1:7860/\" width=\"100%\" height=\"500\" allow=\"autoplay; camera; microphone; clipboard-read; clipboard-write;\" frameborder=\"0\" allowfullscreen></iframe></div>"
|
201 |
+
],
|
202 |
+
"text/plain": [
|
203 |
+
"<IPython.core.display.HTML object>"
|
204 |
+
]
|
205 |
+
},
|
206 |
+
"metadata": {},
|
207 |
+
"output_type": "display_data"
|
208 |
+
},
|
209 |
+
{
|
210 |
+
"data": {
|
211 |
+
"text/plain": []
|
212 |
+
},
|
213 |
+
"execution_count": 19,
|
214 |
+
"metadata": {},
|
215 |
+
"output_type": "execute_result"
|
216 |
+
}
|
217 |
+
],
|
218 |
+
"source": [
|
219 |
+
"# Interfaz de usuario con Gradio\n",
|
220 |
+
"interfaz = gr.Blocks()\n",
|
221 |
+
"\n",
|
222 |
+
"with interfaz:\n",
|
223 |
+
" gr.Markdown(\"# 鈿栵笍 Asistente Jur铆dico Penal\")\n",
|
224 |
+
" gr.Markdown(\"Realiza consultas sobre derecho penal y recibe respuestas fundamentadas.\")\n",
|
225 |
+
" \n",
|
226 |
+
" tipo_consulta = gr.Radio(\n",
|
227 |
+
" choices=[\"Asesor铆a General\", \"Jurisprudencia\", \"Redacci贸n de Documentos\"],\n",
|
228 |
+
" label=\"Tipo de Consulta\",\n",
|
229 |
+
" value=\"Asesor铆a General\"\n",
|
230 |
+
" )\n",
|
231 |
+
" \n",
|
232 |
+
" entrada_texto = gr.Textbox(\n",
|
233 |
+
" label=\"Pregunta Jur铆dica\",\n",
|
234 |
+
" placeholder=\"Escribe tu consulta aqu铆...\"\n",
|
235 |
+
" )\n",
|
236 |
+
" \n",
|
237 |
+
" with gr.Row():\n",
|
238 |
+
" boton_enviar = gr.Button(\"Consultar\")\n",
|
239 |
+
" boton_limpiar = gr.Button(\"Limpiar Historial\")\n",
|
240 |
+
" \n",
|
241 |
+
" salida_texto = gr.Textbox(label=\"Respuesta\")\n",
|
242 |
+
" historial_texto = gr.Textbox(\n",
|
243 |
+
" label=\"Historial de Conversaci贸n\",\n",
|
244 |
+
" interactive=False,\n",
|
245 |
+
" lines=10\n",
|
246 |
+
" )\n",
|
247 |
+
" \n",
|
248 |
+
" boton_enviar.click(\n",
|
249 |
+
" consulta_penalista,\n",
|
250 |
+
" inputs=[entrada_texto, tipo_consulta],\n",
|
251 |
+
" outputs=[salida_texto, historial_texto]\n",
|
252 |
+
" )\n",
|
253 |
+
" \n",
|
254 |
+
" boton_limpiar.click(\n",
|
255 |
+
" limpiar_historial,\n",
|
256 |
+
" outputs=[salida_texto, historial_texto]\n",
|
257 |
+
" )\n",
|
258 |
+
"\n",
|
259 |
+
"interfaz.launch()"
|
260 |
+
]
|
261 |
+
},
|
262 |
+
{
|
263 |
+
"cell_type": "code",
|
264 |
+
"execution_count": 26,
|
265 |
+
"id": "f2501b07-b488-4edd-b1d5-689a9e6f16f5",
|
266 |
+
"metadata": {},
|
267 |
+
"outputs": [
|
268 |
+
{
|
269 |
+
"name": "stdout",
|
270 |
+
"output_type": "stream",
|
271 |
+
"text": [
|
272 |
+
"Requirement already satisfied: huggingface_hub[cli] in /home/v/anaconda3/lib/python3.12/site-packages (0.29.1)\n",
|
273 |
+
"Requirement already satisfied: filelock in /home/v/anaconda3/lib/python3.12/site-packages (from huggingface_hub[cli]) (3.13.1)\n",
|
274 |
+
"Requirement already satisfied: fsspec>=2023.5.0 in /home/v/anaconda3/lib/python3.12/site-packages (from huggingface_hub[cli]) (2024.6.1)\n",
|
275 |
+
"Requirement already satisfied: packaging>=20.9 in /home/v/anaconda3/lib/python3.12/site-packages (from huggingface_hub[cli]) (24.1)\n",
|
276 |
+
"Requirement already satisfied: pyyaml>=5.1 in /home/v/anaconda3/lib/python3.12/site-packages (from huggingface_hub[cli]) (6.0.1)\n",
|
277 |
+
"Requirement already satisfied: requests in /home/v/anaconda3/lib/python3.12/site-packages (from huggingface_hub[cli]) (2.32.3)\n",
|
278 |
+
"Requirement already satisfied: tqdm>=4.42.1 in /home/v/anaconda3/lib/python3.12/site-packages (from huggingface_hub[cli]) (4.66.5)\n",
|
279 |
+
"Requirement already satisfied: typing-extensions>=3.7.4.3 in /home/v/anaconda3/lib/python3.12/site-packages (from huggingface_hub[cli]) (4.11.0)\n",
|
280 |
+
"Requirement already satisfied: InquirerPy==0.3.4 in /home/v/anaconda3/lib/python3.12/site-packages (from huggingface_hub[cli]) (0.3.4)\n",
|
281 |
+
"Requirement already satisfied: pfzy<0.4.0,>=0.3.1 in /home/v/anaconda3/lib/python3.12/site-packages (from InquirerPy==0.3.4->huggingface_hub[cli]) (0.3.4)\n",
|
282 |
+
"Requirement already satisfied: prompt-toolkit<4.0.0,>=3.0.1 in /home/v/anaconda3/lib/python3.12/site-packages (from InquirerPy==0.3.4->huggingface_hub[cli]) (3.0.43)\n",
|
283 |
+
"Requirement already satisfied: charset-normalizer<4,>=2 in /home/v/anaconda3/lib/python3.12/site-packages (from requests->huggingface_hub[cli]) (3.3.2)\n",
|
284 |
+
"Requirement already satisfied: idna<4,>=2.5 in /home/v/anaconda3/lib/python3.12/site-packages (from requests->huggingface_hub[cli]) (3.7)\n",
|
285 |
+
"Requirement already satisfied: urllib3<3,>=1.21.1 in /home/v/anaconda3/lib/python3.12/site-packages (from requests->huggingface_hub[cli]) (2.2.3)\n",
|
286 |
+
"Requirement already satisfied: certifi>=2017.4.17 in /home/v/anaconda3/lib/python3.12/site-packages (from requests->huggingface_hub[cli]) (2024.8.30)\n",
|
287 |
+
"Requirement already satisfied: wcwidth in /home/v/anaconda3/lib/python3.12/site-packages (from prompt-toolkit<4.0.0,>=3.0.1->InquirerPy==0.3.4->huggingface_hub[cli]) (0.2.5)\n"
|
288 |
+
]
|
289 |
+
}
|
290 |
+
],
|
291 |
+
"source": [
|
292 |
+
"!pip install -U \"huggingface_hub[cli]\""
|
293 |
+
]
|
294 |
+
}
|
295 |
+
],
|
296 |
+
"metadata": {
|
297 |
+
"kernelspec": {
|
298 |
+
"display_name": "Python 3 (ipykernel)",
|
299 |
+
"language": "python",
|
300 |
+
"name": "python3"
|
301 |
+
},
|
302 |
+
"language_info": {
|
303 |
+
"codemirror_mode": {
|
304 |
+
"name": "ipython",
|
305 |
+
"version": 3
|
306 |
+
},
|
307 |
+
"file_extension": ".py",
|
308 |
+
"mimetype": "text/x-python",
|
309 |
+
"name": "python",
|
310 |
+
"nbconvert_exporter": "python",
|
311 |
+
"pygments_lexer": "ipython3",
|
312 |
+
"version": "3.12.7"
|
313 |
+
}
|
314 |
+
},
|
315 |
+
"nbformat": 4,
|
316 |
+
"nbformat_minor": 5
|
317 |
+
}
|
requirements.txt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
openai>=1.0.0
|
2 |
+
gradio>=4.0.0
|
3 |
+
python-dotenv>=1.0.0
|