nesanchezo commited on
Commit
0e689a8
·
1 Parent(s): fac4d1a

primer commit

Browse files
Files changed (41) hide show
  1. .DS_Store +0 -0
  2. Dockerfile +14 -0
  3. botpdfs/__init__.py +0 -0
  4. botpdfs/__pycache__/__init__.cpython-311.pyc +0 -0
  5. botpdfs/__pycache__/__init__.cpython-37.pyc +0 -0
  6. botpdfs/__pycache__/settings.cpython-311.pyc +0 -0
  7. botpdfs/__pycache__/settings.cpython-37.pyc +0 -0
  8. botpdfs/__pycache__/urls.cpython-311.pyc +0 -0
  9. botpdfs/__pycache__/urls.cpython-37.pyc +0 -0
  10. botpdfs/__pycache__/wsgi.cpython-311.pyc +0 -0
  11. botpdfs/__pycache__/wsgi.cpython-37.pyc +0 -0
  12. botpdfs/asgi.py +16 -0
  13. botpdfs/settings.py +129 -0
  14. botpdfs/urls.py +29 -0
  15. botpdfs/wsgi.py +16 -0
  16. chatbot/.env +1 -0
  17. chatbot/__init__.py +0 -0
  18. chatbot/__pycache__/__init__.cpython-311.pyc +0 -0
  19. chatbot/__pycache__/__init__.cpython-37.pyc +0 -0
  20. chatbot/__pycache__/admin.cpython-311.pyc +0 -0
  21. chatbot/__pycache__/admin.cpython-37.pyc +0 -0
  22. chatbot/__pycache__/apps.cpython-311.pyc +0 -0
  23. chatbot/__pycache__/apps.cpython-37.pyc +0 -0
  24. chatbot/__pycache__/models.cpython-311.pyc +0 -0
  25. chatbot/__pycache__/models.cpython-37.pyc +0 -0
  26. chatbot/__pycache__/views.cpython-311.pyc +0 -0
  27. chatbot/__pycache__/views.cpython-37.pyc +0 -0
  28. chatbot/admin.py +3 -0
  29. chatbot/apps.py +6 -0
  30. chatbot/migrations/__init__.py +0 -0
  31. chatbot/migrations/__pycache__/__init__.cpython-311.pyc +0 -0
  32. chatbot/migrations/__pycache__/__init__.cpython-37.pyc +0 -0
  33. chatbot/models.py +3 -0
  34. chatbot/templates/chatbot.html +76 -0
  35. chatbot/templates/pdf_template.html +64 -0
  36. chatbot/templates/resumen.html +101 -0
  37. chatbot/tests.py +3 -0
  38. chatbot/views.py +183 -0
  39. db.sqlite3 +0 -0
  40. manage.py +22 -0
  41. requirements.txt +16 -0
.DS_Store ADDED
Binary file (6.15 kB). View file
 
Dockerfile ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ FROM python:3.8
2
+
3
+ ENV PYTHONUNBUFFERED=1
4
+
5
+ WORKDIR /app
6
+
7
+ COPY requirements.txt ./
8
+
9
+ RUN pip install --upgrade pip
10
+ RUN pip install --no-cache-dir -r requirements.txt
11
+
12
+ COPY . .
13
+
14
+ CMD ["python", "manage.py", "runserver", "0.0.0.0:8000"]
botpdfs/__init__.py ADDED
File without changes
botpdfs/__pycache__/__init__.cpython-311.pyc ADDED
Binary file (183 Bytes). View file
 
botpdfs/__pycache__/__init__.cpython-37.pyc ADDED
Binary file (161 Bytes). View file
 
botpdfs/__pycache__/settings.cpython-311.pyc ADDED
Binary file (2.92 kB). View file
 
botpdfs/__pycache__/settings.cpython-37.pyc ADDED
Binary file (2.42 kB). View file
 
botpdfs/__pycache__/urls.cpython-311.pyc ADDED
Binary file (1.65 kB). View file
 
botpdfs/__pycache__/urls.cpython-37.pyc ADDED
Binary file (1.17 kB). View file
 
botpdfs/__pycache__/wsgi.cpython-311.pyc ADDED
Binary file (705 Bytes). View file
 
botpdfs/__pycache__/wsgi.cpython-37.pyc ADDED
Binary file (564 Bytes). View file
 
botpdfs/asgi.py ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ ASGI config for botpdfs project.
3
+
4
+ It exposes the ASGI callable as a module-level variable named ``application``.
5
+
6
+ For more information on this file, see
7
+ https://docs.djangoproject.com/en/3.2/howto/deployment/asgi/
8
+ """
9
+
10
+ import os
11
+
12
+ from django.core.asgi import get_asgi_application
13
+
14
+ os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'botpdfs.settings')
15
+
16
+ application = get_asgi_application()
botpdfs/settings.py ADDED
@@ -0,0 +1,129 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ Django settings for botpdfs project.
3
+
4
+ Generated by 'django-admin startproject' using Django 3.2.8.
5
+
6
+ For more information on this file, see
7
+ https://docs.djangoproject.com/en/3.2/topics/settings/
8
+
9
+ For the full list of settings and their values, see
10
+ https://docs.djangoproject.com/en/3.2/ref/settings/
11
+ """
12
+
13
+ from pathlib import Path
14
+ import os
15
+
16
+ # Build paths inside the project like this: BASE_DIR / 'subdir'.
17
+ BASE_DIR = Path(__file__).resolve().parent.parent
18
+
19
+
20
+ # Quick-start development settings - unsuitable for production
21
+ # See https://docs.djangoproject.com/en/3.2/howto/deployment/checklist/
22
+
23
+ # SECURITY WARNING: keep the secret key used in production secret!
24
+ SECRET_KEY = 'django-insecure-sv0!42$7^1$0l8v8b-=!*w^$2)x758@5#4#fh27g8qojrhb30q'
25
+
26
+ # SECURITY WARNING: don't run with debug turned on in production!
27
+ DEBUG = True
28
+
29
+ ALLOWED_HOSTS = ['0.0.0.0']
30
+
31
+
32
+ # Application definition
33
+
34
+ INSTALLED_APPS = [
35
+ 'django.contrib.admin',
36
+ 'django.contrib.auth',
37
+ 'django.contrib.contenttypes',
38
+ 'django.contrib.sessions',
39
+ 'django.contrib.messages',
40
+ 'django.contrib.staticfiles',
41
+ 'chatbot'
42
+ ]
43
+
44
+ MIDDLEWARE = [
45
+ 'django.middleware.security.SecurityMiddleware',
46
+ 'django.contrib.sessions.middleware.SessionMiddleware',
47
+ 'django.middleware.common.CommonMiddleware',
48
+ 'django.middleware.csrf.CsrfViewMiddleware',
49
+ 'django.contrib.auth.middleware.AuthenticationMiddleware',
50
+ 'django.contrib.messages.middleware.MessageMiddleware',
51
+ 'django.middleware.clickjacking.XFrameOptionsMiddleware',
52
+ ]
53
+
54
+ ROOT_URLCONF = 'botpdfs.urls'
55
+
56
+ TEMPLATES = [
57
+ {
58
+ 'BACKEND': 'django.template.backends.django.DjangoTemplates',
59
+ 'DIRS': [],
60
+ 'APP_DIRS': True,
61
+ 'OPTIONS': {
62
+ 'context_processors': [
63
+ 'django.template.context_processors.debug',
64
+ 'django.template.context_processors.request',
65
+ 'django.contrib.auth.context_processors.auth',
66
+ 'django.contrib.messages.context_processors.messages',
67
+ ],
68
+ },
69
+ },
70
+ ]
71
+
72
+ WSGI_APPLICATION = 'botpdfs.wsgi.application'
73
+
74
+
75
+ # Database
76
+ # https://docs.djangoproject.com/en/3.2/ref/settings/#databases
77
+
78
+ DATABASES = {
79
+ 'default': {
80
+ 'ENGINE': 'django.db.backends.sqlite3',
81
+ 'NAME': BASE_DIR / 'db.sqlite3',
82
+ }
83
+ }
84
+
85
+
86
+ # Password validation
87
+ # https://docs.djangoproject.com/en/3.2/ref/settings/#auth-password-validators
88
+
89
+ AUTH_PASSWORD_VALIDATORS = [
90
+ {
91
+ 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
92
+ },
93
+ {
94
+ 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
95
+ },
96
+ {
97
+ 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
98
+ },
99
+ {
100
+ 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
101
+ },
102
+ ]
103
+
104
+ TEMP_UPLOAD_DIR = os.path.join(BASE_DIR, 'temp_uploads')
105
+
106
+ # Internationalization
107
+ # https://docs.djangoproject.com/en/3.2/topics/i18n/
108
+
109
+ LANGUAGE_CODE = 'en-us'
110
+
111
+ TIME_ZONE = 'UTC'
112
+
113
+ USE_I18N = True
114
+
115
+ USE_L10N = True
116
+
117
+ USE_TZ = True
118
+
119
+
120
+ # Static files (CSS, JavaScript, Images)
121
+ # https://docs.djangoproject.com/en/3.2/howto/static-files/
122
+
123
+ STATIC_URL = 'static/'
124
+ STATICFILES_DIRS = (os.path.join(BASE_DIR,'chatbot/static'),)
125
+
126
+ # Default primary key field type
127
+ # https://docs.djangoproject.com/en/3.2/ref/settings/#default-auto-field
128
+
129
+ DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
botpdfs/urls.py ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """botpdfs URL Configuration
2
+
3
+ The `urlpatterns` list routes URLs to views. For more information please see:
4
+ https://docs.djangoproject.com/en/3.2/topics/http/urls/
5
+ Examples:
6
+ Function views
7
+ 1. Add an import: from my_app import views
8
+ 2. Add a URL to urlpatterns: path('', views.home, name='home')
9
+ Class-based views
10
+ 1. Add an import: from other_app.views import Home
11
+ 2. Add a URL to urlpatterns: path('', Home.as_view(), name='home')
12
+ Including another URLconf
13
+ 1. Import the include() function: from django.urls import include, path
14
+ 2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
15
+ """
16
+ from django.contrib import admin
17
+ from django.urls import path
18
+ from django.conf import settings
19
+ from django.conf.urls.static import static
20
+ from chatbot.views import chatbot,resumen, generar_pdf_view
21
+
22
+
23
+ urlpatterns = [
24
+ path('admin/', admin.site.urls),
25
+ path('', chatbot, name='chatBot'),
26
+ path('generar-pdf/', generar_pdf_view, name='generar_pdf'),
27
+ path('resumen/', resumen, name='resumen')
28
+ ]+ static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
29
+
botpdfs/wsgi.py ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ WSGI config for botpdfs project.
3
+
4
+ It exposes the WSGI callable as a module-level variable named ``application``.
5
+
6
+ For more information on this file, see
7
+ https://docs.djangoproject.com/en/3.2/howto/deployment/wsgi/
8
+ """
9
+
10
+ import os
11
+
12
+ from django.core.wsgi import get_wsgi_application
13
+
14
+ os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'botpdfs.settings')
15
+
16
+ application = get_wsgi_application()
chatbot/.env ADDED
@@ -0,0 +1 @@
 
 
1
+ OPENAI_API_KEY=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
chatbot/__init__.py ADDED
File without changes
chatbot/__pycache__/__init__.cpython-311.pyc ADDED
Binary file (183 Bytes). View file
 
chatbot/__pycache__/__init__.cpython-37.pyc ADDED
Binary file (161 Bytes). View file
 
chatbot/__pycache__/admin.cpython-311.pyc ADDED
Binary file (238 Bytes). View file
 
chatbot/__pycache__/admin.cpython-37.pyc ADDED
Binary file (202 Bytes). View file
 
chatbot/__pycache__/apps.cpython-311.pyc ADDED
Binary file (556 Bytes). View file
 
chatbot/__pycache__/apps.cpython-37.pyc ADDED
Binary file (436 Bytes). View file
 
chatbot/__pycache__/models.cpython-311.pyc ADDED
Binary file (235 Bytes). View file
 
chatbot/__pycache__/models.cpython-37.pyc ADDED
Binary file (199 Bytes). View file
 
chatbot/__pycache__/views.cpython-311.pyc ADDED
Binary file (9.9 kB). View file
 
chatbot/__pycache__/views.cpython-37.pyc ADDED
Binary file (1.16 kB). View file
 
chatbot/admin.py ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ from django.contrib import admin
2
+
3
+ # Register your models here.
chatbot/apps.py ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ from django.apps import AppConfig
2
+
3
+
4
+ class ChatbotConfig(AppConfig):
5
+ default_auto_field = 'django.db.models.BigAutoField'
6
+ name = 'chatbot'
chatbot/migrations/__init__.py ADDED
File without changes
chatbot/migrations/__pycache__/__init__.cpython-311.pyc ADDED
Binary file (194 Bytes). View file
 
chatbot/migrations/__pycache__/__init__.cpython-37.pyc ADDED
Binary file (172 Bytes). View file
 
chatbot/models.py ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ from django.db import models
2
+
3
+ # Create your models here.
chatbot/templates/chatbot.html ADDED
@@ -0,0 +1,76 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <meta charset="utf-8">
5
+ <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.0.0/dist/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
6
+ <script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
7
+ <script src="https://cdn.jsdelivr.net/npm/popper.js@1.12.9/dist/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
8
+ <script src="https://cdn.jsdelivr.net/npm/bootstrap@4.0.0/dist/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
9
+
10
+ {% load static %}
11
+ <link href="{% static 'css/style.css' %}" rel="stylesheet">
12
+ <title>Auto Resumen</title>
13
+ </head>
14
+ <body>
15
+
16
+ <div class="container">
17
+ <nav class="navbar navbar-expand-lg navbar-light bg-light">
18
+ <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNavAltMarkup" aria-controls="navbarNavAltMarkup" aria-expanded="false" aria-label="Toggle navigation">
19
+ <span class="navbar-toggler-icon"></span>
20
+ </button>
21
+ <div class="collapse navbar-collapse" id="navbarNavAltMarkup">
22
+ <div class="navbar-nav">
23
+ <a class="nav-item nav-link active" href="">Home</a>
24
+ </div>
25
+ </div>
26
+ </nav>
27
+ </div>
28
+
29
+ <div class="container">
30
+ <h1 align="center">Auto Resumen.</h1>
31
+ </div>
32
+ </div>
33
+
34
+ <div class="container">
35
+ <form method="post" enctype="multipart/form-data">
36
+ {% csrf_token %}
37
+ <div class="form-group">
38
+ <div class="custom-file">
39
+ <input type="file" class="custom-file-input" id="customFile" name="pdf_file" accept=".pdf">
40
+ <label class="custom-file-label" for="customFile">Seleccionar archivo PDF</label>
41
+ </div>
42
+ </div>
43
+ <button type="submit" class="btn btn-primary">Cargar PDF</button>
44
+ </form>
45
+ </div>
46
+
47
+ <div class="container">
48
+ {% if chatbot_response %}
49
+ <div class="card mt-3">
50
+ <div class="card-body">
51
+ <p><strong>Respuesta del Chatbot:</strong></p>
52
+ <p>{{ chatbot_response }}</p>
53
+ </div>
54
+ </div>
55
+ {% endif %}
56
+ </div>
57
+
58
+ <p></p>
59
+
60
+ <div class="container">
61
+ {% if archivo_cargado %}
62
+ <div class="alert alert-success" role="alert">
63
+ ¡El archivo se ha cargado exitosamente!
64
+ </div>
65
+ {% endif %}
66
+ </div>
67
+
68
+ <p></p>
69
+
70
+ <div class="container">
71
+ <a href="{% url 'resumen' %}" class="btn btn-primary btn-lg active" role="button" aria-pressed="true">Obtener resumen</a>
72
+ </div>
73
+
74
+
75
+ </body>
76
+ </html>
chatbot/templates/pdf_template.html ADDED
@@ -0,0 +1,64 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <title>Recomendaciones</title>
6
+ </head>
7
+ <body>
8
+
9
+ <div class="container">
10
+ <div class="row mt-5 mb-5 ms-5 me-5">
11
+ <h2 align="center">Reporte recomendaciones estudiante</h2>
12
+ </div>
13
+ </div>
14
+
15
+ <div class="container">
16
+ <h3>{{ resumen.titulo_invitacion }}</h3>
17
+
18
+ <h3>Objeto Contrato</h3>
19
+ <p>{{ resumen.objeto_contrato}}</p>
20
+
21
+ <h3>Requerimientos Técnicos</h3>
22
+ <ul>
23
+ {% for requerimiento in resumen.requerimientos_tecnicos %}
24
+ <li>{{ requerimiento }}</li>
25
+ {% endfor %}
26
+ </ul>
27
+
28
+ <h3>Plazo de ejecución</h3>
29
+ <p>{{ resumen.plazo}}</p>
30
+
31
+ <h3>Presupuesto</h3>
32
+ <p>{{ resumen.presupuesto}}</p>
33
+
34
+ <h3>Causales de Rechazo</h3>
35
+ <ul>
36
+ {% for causal in resumen.causales_rechazo %}
37
+ <li>{{ causal }}</li>
38
+ {% endfor %}
39
+ </ul>
40
+
41
+ <h3>Capacidad Juridica</h3>
42
+ <ul>
43
+ {% for capacidad in resumen.capacidad_juridica %}
44
+ <li>{{ capacidad }}</li>
45
+ {% endfor %}
46
+ </ul>
47
+
48
+ <h3>Garantias</h3>
49
+ <ul>
50
+ {% for garantia in resumen.garantias %}
51
+ <li>{{ garantia }}</li>
52
+ {% endfor %}
53
+ </ul>
54
+
55
+ <h3>Anexos</h3>
56
+ <ul>
57
+ {% for anexo in resumen.anexos %}
58
+ <li>{{ anexo }}</li>
59
+ {% endfor %}
60
+ </ul>
61
+ </div>
62
+
63
+ </body>
64
+ </html>
chatbot/templates/resumen.html ADDED
@@ -0,0 +1,101 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <meta charset="utf-8">
5
+ <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.0.0/dist/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
6
+ <script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
7
+ <script src="https://cdn.jsdelivr.net/npm/popper.js@1.12.9/dist/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
8
+ <script src="https://cdn.jsdelivr.net/npm/bootstrap@4.0.0/dist/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
9
+
10
+ {% load static %}
11
+ <link href="{% static 'css/style.css' %}" rel="stylesheet">
12
+ <title>RESUMEN</title>
13
+ </head>
14
+ <body>
15
+
16
+ <div class="container">
17
+ <nav class="navbar navbar-expand-lg navbar-light bg-light">
18
+ <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNavAltMarkup" aria-controls="navbarNavAltMarkup" aria-expanded="false" aria-label="Toggle navigation">
19
+ <span class="navbar-toggler-icon"></span>
20
+ </button>
21
+ <div class="collapse navbar-collapse" id="navbarNavAltMarkup">
22
+ <div class="navbar-nav">
23
+ <a class="nav-item nav-link active" href="{% url 'chatBot' %}">Home</a>
24
+ </div>
25
+ </div>
26
+ </nav>
27
+ </div>
28
+
29
+ <div class="container">
30
+ <h1 align="center">RESUMEN.</h1>
31
+ </div>
32
+ </div>
33
+
34
+ <div class="container">
35
+
36
+ <h3>{{ resumen.titulo_invitacion }}</h3>
37
+
38
+ {% if resumen.objeto_contrato %}
39
+ <h3>Objeto Contrato</h3>
40
+ <p>{{ resumen.objeto_contrato}}</p>
41
+ {% endif %}
42
+
43
+ {% if resumen.objeto_contrato %}
44
+ <h3>Requerimientos Técnicos</h3>
45
+ <ul>
46
+ {% for requerimiento in resumen.requerimientos_tecnicos %}
47
+ <li>{{ requerimiento }}</li>
48
+ {% endfor %}
49
+ </ul>
50
+ {% endif %}
51
+
52
+ {% if resumen.objeto_contrato %}
53
+ <h3>Plazo de ejecución</h3>
54
+ <p>{{ resumen.plazo}}</p>
55
+ {% endif %}
56
+
57
+ {% if resumen.objeto_contrato %}
58
+ <h3>Presupuesto</h3>
59
+ <p>{{ resumen.presupuesto}}</p>
60
+ {% endif %}
61
+
62
+ {% if resumen.objeto_contrato %}
63
+ <h3>Causales de Rechazo</h3>
64
+ <ul>
65
+ {% for causal in resumen.causales_rechazo %}
66
+ <li>{{ causal }}</li>
67
+ {% endfor %}
68
+ </ul>
69
+ {% endif %}
70
+
71
+ {% if resumen.objeto_contrato %}
72
+ <h3>Capacidad Juridica</h3>
73
+ <ul>
74
+ {% for capacidad in resumen.capacidad_juridica %}
75
+ <li>{{ capacidad }}</li>
76
+ {% endfor %}
77
+ </ul>
78
+ {% endif %}
79
+
80
+ {% if resumen.objeto_contrato %}
81
+ <h3>Garantias</h3>
82
+ <ul>
83
+ {% for garantia in resumen.garantias %}
84
+ <li>{{ garantia }}</li>
85
+ {% endfor %}
86
+ </ul>
87
+ {% endif %}
88
+
89
+ {% if resumen.objeto_contrato %}
90
+ <h3>Anexos</h3>
91
+ <ul>
92
+ {% for anexo in resumen.anexos %}
93
+ <li>{{ anexo }}</li>
94
+ {% endfor %}
95
+ </ul>
96
+ {% endif %}
97
+ <a href="{% url 'generar_pdf' %}" target="_blank">Generar PDF</a>
98
+ </div>
99
+
100
+ </body>
101
+ </html>
chatbot/tests.py ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ from django.test import TestCase
2
+
3
+ # Create your tests here.
chatbot/views.py ADDED
@@ -0,0 +1,183 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import requests
2
+ from PyPDF2 import PdfReader
3
+ from django.shortcuts import render
4
+ from django.conf import settings
5
+ import os
6
+ import io
7
+ import re
8
+
9
+ from langchain.document_loaders import PyPDFLoader
10
+ import openai
11
+ from langchain.output_parsers import ResponseSchema
12
+ from langchain.chat_models import ChatOpenAI
13
+ from langchain.output_parsers import StructuredOutputParser
14
+ from langchain.prompts import ChatPromptTemplate
15
+ from langchain.chains import TransformChain
16
+
17
+ from django.template.loader import render_to_string
18
+ from django.http import HttpResponse
19
+ from io import BytesIO
20
+ from xhtml2pdf import pisa
21
+
22
+ # Create your views here.
23
+
24
+ '''
25
+ #if request.method == 'POST':
26
+ # pdf_file = request.FILES['pdf_file']
27
+ # # Lógica para procesar el archivo PDF
28
+ #resultados = {}
29
+ '''
30
+ from dotenv import load_dotenv, find_dotenv
31
+ _ = load_dotenv(find_dotenv()) # read local .env file
32
+ openai.api_key = os.environ['OPENAI_API_KEY']
33
+
34
+ llm = ChatOpenAI(temperature=0.0, model="gpt-3.5-turbo-16k")
35
+
36
+ titulo_invitacion_schema = ResponseSchema(name="titulo_invitacion", description="Extraer el título con el No. Usar mayusculas.")
37
+ objeto_contrato_schema = ResponseSchema(name="objeto_contrato", description="Extraer el objeto del contrato de manera literal. Usar mayusculas.")
38
+ requerimientos_tecnicos_schema = ResponseSchema(name="requerimientos_tecnicos", description="Realizar una lista con la información de los requerimientos tecnicos minimos. Si no lo encuentra, responder No Aplica")
39
+ plazo_schema = ResponseSchema(name="plazo", description="Extraer el plazo de ejecución. Si no lo escuentra, responder No Aplica")
40
+ presupuesto_schema = ResponseSchema(name="presupuesto", description="Extraer el presupuesto oficial. también mostrar el presuopuesto en formato pesos ($xxxx). Si no lo encuentra, responder No Aplica")
41
+ causales_rechazo_schema = ResponseSchema(name="causales_rechazo", description="Realizar una lista con la información de las causales que generan rechazo. Si no lo escuentra, responder No Aplica")
42
+ capacidad_juridica_schema = ResponseSchema(name="capacidad_juridica", description="Realizar una lista con la información de la capacidad juridica. Si no lo encuentra, responder No Aplica")
43
+ garantias_schema = ResponseSchema(name="garantias", description="Realizar una lista con las garantías. Si no lo encuentra, responder No Aplica")
44
+ anexos_schema = ResponseSchema(name="anexos", description="Realizar una lista con los anexos. Se reconocen porque el título empieza con la palabra anexo. Algunos ejemplos pueden ser: ANEXO 1 CARTA DE PRESENTACIÓN DE LA OFERTA, ANEXO No 2, ANEXO PROPUESTA ECONOMICA. Si no lo encuentra, responder No Aplica")
45
+
46
+ response_schemas = [titulo_invitacion_schema,
47
+ objeto_contrato_schema,
48
+ requerimientos_tecnicos_schema,
49
+ plazo_schema,
50
+ presupuesto_schema,
51
+ causales_rechazo_schema,
52
+ capacidad_juridica_schema,
53
+ garantias_schema,
54
+ anexos_schema,
55
+ ]
56
+
57
+ template_string = '''The input is the text delimited by triple backticks. \
58
+ text: ```{text}```\
59
+ Use the text to perform the consecutive taks:\
60
+ Follow the format_instructions:\
61
+ 1) Escribe el título con el No \
62
+ 2) Escribe el el objeto del contrato \
63
+ 3) Realizá una lista con los requerimientos técnicos mínimos. \
64
+ 4) Escribe el plazo de ejecución.\
65
+ 5) Escribe el presupuesto.\
66
+ 6) Realizá una lista con las causales que generan rechazo. \
67
+ 7) Realizá una lista con la información de la capacidad juridica. \
68
+ 8) Realizá una lista con la información de las garantias. \
69
+ 9) Realizá una lista con los anexos. Solo texto o números. Se reconocen porque el título empieza con la palabra anexo. Algunos ejemplos pueden ser: ANEXO 1 CARTA DE PRESENTACIÓN DE LA OFERTA, ANEXO No 2, ANEXO PROPUESTA ECONOMICA. Si no lo encuentra, responder No Aplica\
70
+ {format_instructions}
71
+ '''
72
+
73
+ def chatbot(request):
74
+ global texto, llm
75
+ if request.method == 'POST' and request.FILES.get('pdf_file'):
76
+ pdf_file = request.FILES['pdf_file']
77
+
78
+ # Convertir el archivo InMemoryUploadedFile a un objeto BytesIO
79
+ pdf_bytes = io.BytesIO(pdf_file.read())
80
+
81
+ # Guardar el archivo temporalmente en la carpeta designada
82
+ temp_file_path = os.path.join(settings.TEMP_UPLOAD_DIR, pdf_file.name)
83
+ with open(temp_file_path, 'wb') as temp_file:
84
+ temp_file.write(pdf_bytes.read())
85
+
86
+ texto = obtenerTexto(temp_file_path)
87
+
88
+ #print(texto)
89
+
90
+ print(llm.get_num_tokens(texto))
91
+
92
+ #print(type(texto))
93
+
94
+ #resume = resumenSmallDocs(response_schemas,template_string,texto)
95
+
96
+ os.remove(temp_file_path)
97
+
98
+ # Pasar el resumen a la plantilla
99
+ context = {
100
+ # 'resumen': resume,
101
+ 'archivo_cargado': True
102
+ }
103
+ return render(request, 'chatbot.html', context)
104
+
105
+ return render(request, 'chatbot.html')
106
+
107
+
108
+ def resumen(request):
109
+ global resumen
110
+ try:
111
+ if llm.get_num_tokens(texto)>12000:
112
+ mensaje = 'El documento que esta tratando de resumir es demasiado grande'
113
+ else:
114
+ mensaje = 'Ha ocurrido un error, intenta de nuevo'
115
+ except:
116
+ mensaje = 'Ha ocurrido un error, intenta de nuevo'
117
+ try:
118
+ resumen = resumenSmallDocs(response_schemas,template_string,texto)
119
+ resumen['requerimientos_tecnicos'] = resumen['requerimientos_tecnicos'].split('\n')
120
+ resumen['causales_rechazo'] = resumen['causales_rechazo'].split('\n')
121
+ resumen['capacidad_juridica'] = resumen['capacidad_juridica'].split('\n')
122
+ resumen['garantias'] = resumen['garantias'].split('\n')
123
+ resumen['anexos'] = resumen['anexos'].split('\n')
124
+ context = {'resumen':resumen}
125
+ except:
126
+ resumen = {}
127
+ resumen['titulo_invitacion'] = mensaje
128
+ context = {'resumen':resumen}
129
+ return render(request,'resumen.html',context)
130
+
131
+ def generar_pdf_view(request):
132
+ # Obtener la lista de recomendaciones (suponiendo que ya la tienes)
133
+
134
+ # Renderizar el archivo HTML como una cadena de texto utilizando el resumem
135
+ html = render_to_string('pdf_template.html', {'resumen': resumen})
136
+
137
+ # Crear el objeto HttpResponse con el tipo de contenido adecuado
138
+ response = HttpResponse(content_type='application/pdf')
139
+ # Establecer el encabezado de respuesta para la descarga del archivo
140
+ response['Content-Disposition'] = 'attachment; filename="resumen.pdf"'
141
+
142
+ # Crear el archivo PDF usando la librería xhtml2pdf
143
+ pisa.CreatePDF(html, dest=response, encoding='utf-8')
144
+
145
+ return response
146
+
147
+ def obtenerTexto(file_path):
148
+ loader = PyPDFLoader(file_path)
149
+ pages = loader.load()
150
+ text = ""
151
+ for page in pages:
152
+ text += page.page_content
153
+ text = text.replace('\t', ' ')
154
+
155
+ # Aplicar limpiadores
156
+ text = limpiar_espacios(text)
157
+
158
+ return text
159
+
160
+ def eliminarPiePagina(text):
161
+ footpage_regex = r'\[START FOOTPAGE\](.|\n)*\[END FOOTPAGE\]'
162
+ footpages = re.findall(footpage_regex, text)
163
+ for footpage in footpages:
164
+ text = text.replace(footpage, '')
165
+ return text
166
+
167
+ def limpiar_espacios(texto):
168
+ # Reemplazar múltiples espacios por uno solo
169
+ texto = re.sub(r'\s+', ' ', texto)
170
+ # Eliminar espacios al principio y al final de cada línea
171
+ lineas = texto.split('\n')
172
+ lineas_limpio = [linea.strip() for linea in lineas]
173
+ texto_limpio = '\n'.join(lineas_limpio)
174
+ return texto_limpio
175
+
176
+ def resumenSmallDocs(response_schemas,template_string,text):
177
+ output_parser = StructuredOutputParser.from_response_schemas(response_schemas)
178
+ format_instructions = output_parser.get_format_instructions()
179
+ prompt_3 = ChatPromptTemplate.from_template(template=template_string)
180
+ summary_prompt_3 = prompt_3.format_messages(text=text,format_instructions=format_instructions)
181
+ summary_formatted = llm(summary_prompt_3)
182
+ python_dict_parser = output_parser.parse(summary_formatted.content)
183
+ return python_dict_parser
db.sqlite3 ADDED
Binary file (131 kB). View file
 
manage.py ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python
2
+ """Django's command-line utility for administrative tasks."""
3
+ import os
4
+ import sys
5
+
6
+
7
+ def main():
8
+ """Run administrative tasks."""
9
+ os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'botpdfs.settings')
10
+ try:
11
+ from django.core.management import execute_from_command_line
12
+ except ImportError as exc:
13
+ raise ImportError(
14
+ "Couldn't import Django. Are you sure it's installed and "
15
+ "available on your PYTHONPATH environment variable? Did you "
16
+ "forget to activate a virtual environment?"
17
+ ) from exc
18
+ execute_from_command_line(sys.argv)
19
+
20
+
21
+ if __name__ == '__main__':
22
+ main()
requirements.txt ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ Django==4.1.7
2
+ langchain==0.0.194
3
+ langsmith==0.0.20
4
+ langchainplus-sdk==0.0.7
5
+ numpy==1.24.2
6
+ openai==0.27.6
7
+ openapi-schema-pydantic==1.2.4
8
+ pandas==1.5.3
9
+ Pillow==9.5.0
10
+ plotly==5.13.1
11
+ pypdf==3.9.1
12
+ python-dotenv==1.0.0
13
+ xhtml2pdf==0.2.11
14
+ PyPDF2==3.0.1
15
+ regex==2023.8.8
16
+ tiktoken==0.4.0