kanika1912 commited on
Commit
0716e6c
1 Parent(s): 1971588

Upload 41 files

Browse files
.gitignore ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ *.pyc
2
+ __pycache__/
3
+ db.sqlite3
4
+ media/
Dockerfile ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Use the official slim Python image from the Docker library
2
+ FROM python:3.9-slim
3
+
4
+ # Set the working directory
5
+ WORKDIR /app
6
+
7
+ # Install MySQL development libraries
8
+ RUN apt-get update && apt-get install -y \
9
+ default-libmysqlclient-dev \
10
+ build-essential \
11
+ && apt-get clean \
12
+ && rm -rf /var/lib/apt/lists/*
13
+
14
+ # Add the application code to the Docker image
15
+ ADD . /app
16
+
17
+ # Install Python dependencies
18
+ RUN pip install --no-cache-dir -r requirements.txt
19
+
20
+ # Expose the port the app runs on
21
+ EXPOSE 8000
22
+
23
+ # Define the command to run the application
24
+ CMD ["gunicorn", "--bind", "0.0.0.0:8000", "hello.wsgi:application"]
Procfile ADDED
@@ -0,0 +1 @@
 
 
1
+ web: gunicorn app:application
app.py ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ import os
2
+ import sys
3
+
4
+ from django.core.wsgi import get_wsgi_application
5
+
6
+ os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'hello.settings')
7
+ application = get_wsgi_application()
build.sh ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ #!/bin/bash
2
+
3
+ python -m pip install --upgrade pip
4
+ pip install -r requirements.txt
5
+
6
+ python manage.py migrate
7
+ python manage.py collectstatic --noinput
db.sqlite3 ADDED
File without changes
hello/__init__.py ADDED
File without changes
hello/__pycache__/__init__.cpython-311.pyc ADDED
Binary file (180 Bytes). View file
 
hello/__pycache__/settings.cpython-311.pyc ADDED
Binary file (2.89 kB). View file
 
hello/__pycache__/urls.cpython-311.pyc ADDED
Binary file (1.16 kB). View file
 
hello/__pycache__/wsgi.cpython-311.pyc ADDED
Binary file (698 Bytes). View file
 
hello/asgi.py ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ ASGI config for hello 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/4.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', 'hello.settings')
15
+
16
+ application = get_asgi_application()
hello/settings.py ADDED
@@ -0,0 +1,129 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ Django settings for hello project.
3
+
4
+ Generated by 'django-admin startproject' using Django 4.2.4.
5
+
6
+ For more information on this file, see
7
+ https://docs.djangoproject.com/en/4.2/topics/settings/
8
+
9
+ For the full list of settings and their values, see
10
+ https://docs.djangoproject.com/en/4.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/4.2/howto/deployment/checklist/
22
+
23
+ # SECURITY WARNING: keep the secret key used in production secret!
24
+ SECRET_KEY = 'django-insecure-#(!(y_+=qeie9d=n6q%(e50y_p6fh_48@t#@@w@d)_^9rez!9f'
25
+
26
+ # SECURITY WARNING: don't run with debug turned on in production!
27
+ DEBUG = True
28
+
29
+ ALLOWED_HOSTS = ['.hf.space']
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
+ 'home',
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 = 'hello.urls'
55
+
56
+ TEMPLATES = [
57
+ {
58
+ 'BACKEND': 'django.template.backends.django.DjangoTemplates',
59
+ 'DIRS': [os.path.join(BASE_DIR ,"templates")],
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 = 'hello.wsgi.application'
73
+
74
+
75
+ # Database
76
+ # https://docs.djangoproject.com/en/4.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/4.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
+
105
+ # Internationalization
106
+ # https://docs.djangoproject.com/en/4.2/topics/i18n/
107
+
108
+ LANGUAGE_CODE = 'en-us'
109
+
110
+ TIME_ZONE = 'UTC'
111
+
112
+ USE_I18N = True
113
+
114
+ USE_TZ = True
115
+
116
+
117
+ # Static files (CSS, JavaScript, Images)
118
+ # https://docs.djangoproject.com/en/4.2/howto/static-files/
119
+
120
+ STATIC_URL = '/static/'
121
+
122
+ # Default primary key field type
123
+ # https://docs.djangoproject.com/en/4.2/ref/settings/#default-auto-field
124
+
125
+ DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
126
+
127
+
128
+ #added manualy
129
+ STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
hello/urls.py ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ URL configuration for hello project.
3
+
4
+ The `urlpatterns` list routes URLs to views. For more information please see:
5
+ https://docs.djangoproject.com/en/4.2/topics/http/urls/
6
+ Examples:
7
+ Function views
8
+ 1. Add an import: from my_app import views
9
+ 2. Add a URL to urlpatterns: path('', views.home, name='home')
10
+ Class-based views
11
+ 1. Add an import: from other_app.views import Home
12
+ 2. Add a URL to urlpatterns: path('', Home.as_view(), name='home')
13
+ Including another URLconf
14
+ 1. Import the include() function: from django.urls import include, path
15
+ 2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
16
+ """
17
+ from django.contrib import admin
18
+ from django.urls import path, include
19
+
20
+ urlpatterns = [
21
+ path('admin/', admin.site.urls),
22
+ path('', include('home.urls'))
23
+ ]
hello/wsgi.py ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ WSGI config for hello 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/4.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', 'hello.settings')
15
+
16
+ application = get_wsgi_application()
17
+
home/__init__.py ADDED
File without changes
home/__pycache__/__init__.cpython-311.pyc ADDED
Binary file (179 Bytes). View file
 
home/__pycache__/admin.cpython-311.pyc ADDED
Binary file (234 Bytes). View file
 
home/__pycache__/apps.cpython-311.pyc ADDED
Binary file (175 Bytes). View file
 
home/__pycache__/forms.cpython-311.pyc ADDED
Binary file (845 Bytes). View file
 
home/__pycache__/models.cpython-311.pyc ADDED
Binary file (177 Bytes). View file
 
home/__pycache__/urls.cpython-311.pyc ADDED
Binary file (840 Bytes). View file
 
home/__pycache__/views.cpython-311.pyc ADDED
Binary file (6.23 kB). View file
 
home/admin.py ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ from django.contrib import admin
2
+
3
+ # Register your models here.
home/apps.py ADDED
File without changes
home/forms.py ADDED
File without changes
home/migrations/0001_initial.py ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Generated by Django 4.2.4 on 2024-05-28 07:52
2
+
3
+ from django.db import migrations, models
4
+
5
+
6
+ class Migration(migrations.Migration):
7
+
8
+ initial = True
9
+
10
+ dependencies = [
11
+ ]
12
+
13
+ operations = [
14
+ migrations.CreateModel(
15
+ name='Registration',
16
+ fields=[
17
+ ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
18
+ ('first_name', models.CharField(max_length=100)),
19
+ ('last_name', models.CharField(max_length=100)),
20
+ ('email', models.EmailField(max_length=254)),
21
+ ('phone', models.CharField(max_length=15)),
22
+ ('address', models.TextField()),
23
+ ],
24
+ ),
25
+ ]
home/migrations/__init__.py ADDED
File without changes
home/migrations/__pycache__/0001_initial.cpython-311.pyc ADDED
Binary file (1.26 kB). View file
 
home/migrations/__pycache__/__init__.cpython-311.pyc ADDED
Binary file (190 Bytes). View file
 
home/models.py ADDED
@@ -0,0 +1 @@
 
 
1
+
home/templates/registration.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ Name: kannu, Email: kannu@gmail.com, Password: khujjmm5mm6
2
+ Name: kannu, Email: kannu@gmail.com, Password: khhgauhnnnkm
3
+
home/tests.py ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ from django.test import TestCase
2
+
3
+ # Create your tests here.
home/urls.py ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from django.contrib import admin
2
+ from django.urls import path, include
3
+ from home import views
4
+ from . import views
5
+ urlpatterns = [
6
+ path('', views.index, name="home"),
7
+ path('service', views.service, name='service'),
8
+ path('about', views.about, name='about'),
9
+ path('submit_message/', views.submit_message, name='submit_message'),
10
+ path('register/', views.registration, name='register'),
11
+
12
+ ]
home/views.py ADDED
@@ -0,0 +1,103 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from django.shortcuts import render, HttpResponse, redirect
2
+ from transformers import pipeline, AutoModelForSeq2SeqLM, AutoTokenizer
3
+ import PyPDF2
4
+ from django.views.decorators.csrf import csrf_exempt
5
+ import json
6
+ from django.http import JsonResponse
7
+
8
+ import os
9
+ from django.conf import settings
10
+
11
+ # Load model and tokenizer
12
+ model_name = "MBZUAI/LaMini-Flan-T5-248M"
13
+ tokenizer = AutoTokenizer.from_pretrained(model_name)
14
+ model = AutoModelForSeq2SeqLM.from_pretrained(model_name)
15
+ text2text = pipeline("text2text-generation", model=model, tokenizer=tokenizer, max_length=80)
16
+
17
+ # Extract text from PDF for context
18
+ def extract_text_from_pdf(pdf_file_path):
19
+ text = ""
20
+ with open(pdf_file_path, 'rb') as file:
21
+ pdf_reader = PyPDF2.PdfReader(file)
22
+ num_pages = len(pdf_reader.pages)
23
+ for page_num in range(num_pages):
24
+ page = pdf_reader.pages[page_num]
25
+ text += page.extract_text()
26
+ return text
27
+
28
+ pdf_file_path = r'C:\Users\Kanika\OneDrive\Desktop\llm - Copy\hello\static\Sure trust (1).pdf'
29
+ context = extract_text_from_pdf(pdf_file_path)
30
+
31
+ def split_text_into_chunks(text, chunk_size):
32
+ words = text.split()
33
+ return [' '.join(words[i:i + chunk_size]) for i in range(0, len(words), chunk_size)]
34
+
35
+ def get_bot_response(message):
36
+ question = message
37
+ chunk_size = 450 # Adjust the chunk size based on your needs
38
+ input_texts = split_text_into_chunks(context, chunk_size)
39
+
40
+ # Collect responses from each chunk
41
+ responses = []
42
+ for input_text in input_texts:
43
+ input_with_question = f"question: {question} context: {input_text}"
44
+ outputs = text2text(input_with_question)
45
+ if outputs:
46
+ responses.append(outputs[0]['generated_text'])
47
+
48
+ # Combine responses if necessary
49
+ combined_response = " ".join(responses)
50
+ return combined_response if combined_response else "Sorry, I couldn't understand your question."
51
+
52
+ def registration(request):
53
+ if request.method == "POST":
54
+ name = request.POST["name"]
55
+ email = request.POST["email"]
56
+ mobile = request.POST["mobile"]
57
+ Course = request.POST["Course"]
58
+
59
+ # Define the path to the text file in the templates folder
60
+ directory = os.path.join(settings.BASE_DIR, 'home', 'templates')
61
+ file_path = os.path.join(directory, 'registration.txt')
62
+
63
+ # Ensure the directory exists
64
+ if not os.path.exists(directory):
65
+ os.makedirs(directory)
66
+
67
+ try:
68
+ # Write the registration data to the text file
69
+ with open(file_path, 'a') as file:
70
+ file.write(f"Name: {name}, Email: {email}, Mobile Number: {mobile}, Course: {Course}\n")
71
+ print(f"Successfully wrote to {file_path}")
72
+ except Exception as e:
73
+ print(f"Error writing to file: {e}")
74
+ return HttpResponse(f"Error: {e}")
75
+
76
+ return redirect('home') # Redirect to the same page or another page after registration
77
+
78
+ return render(request, 'registration.html')
79
+
80
+ @csrf_exempt
81
+ def submit_message(request):
82
+ if request.method == 'POST':
83
+ data = json.loads(request.body)
84
+ user_message = data.get('input')
85
+ bot_response = get_bot_response(user_message)
86
+ return JsonResponse({'response': bot_response})
87
+ return JsonResponse({'error': 'Invalid request'}, status=400)
88
+
89
+ def index(request):
90
+ context = {"variable1": "kanika is great"}
91
+ return render(request, "index4.html", context)
92
+
93
+ def service(request):
94
+ return HttpResponse("this is service page")
95
+
96
+ def about(request):
97
+ return HttpResponse("this is about page")
98
+
99
+
100
+
101
+
102
+
103
+
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', 'hello.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
Binary file (302 Bytes). View file
 
static/Sure trust (1).pdf ADDED
Binary file (532 kB). View file
 
static/suretrust.png ADDED
templates/index4.html ADDED
@@ -0,0 +1,252 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!DOCTYPE html>
2
+ <html lang="en" dir="ltr">
3
+ <head>
4
+ <meta charset="utf-8">
5
+ <title>Chatbot</title>
6
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
7
+ <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.2/css/all.min.css">
8
+ <style>
9
+ @import url('https://fonts.googleapis.com/css2?family=Roboto:wght@300;400;500;700&display=swap');
10
+ * {
11
+ margin: 0;
12
+ padding: 0;
13
+ box-sizing: border-box;
14
+ font-family: 'Roboto', sans-serif;
15
+ }
16
+ body {
17
+ background-color: #1a1a2e;
18
+ display: flex;
19
+ justify-content: center;
20
+ align-items: center;
21
+ height: 100vh;
22
+ color: #fff;
23
+ position: relative;
24
+ }
25
+ .chatbot {
26
+ background-color: #0f0f20;
27
+ border-radius: 5px;
28
+ border: 1px solid #fff;
29
+ width: 450px;
30
+ height: 500px;
31
+ display: none; /* Initially hidden */
32
+ flex-direction: column;
33
+ overflow: hidden;
34
+ box-shadow: 0 0 20px rgba(0, 0, 0, 0.2);
35
+ position: fixed;
36
+ bottom: 20px;
37
+ right: 20px;
38
+ z-index: 1000;
39
+ }
40
+ .chatbot header {
41
+ background-color: #0f0f20;
42
+ padding: 15px;
43
+ display: flex;
44
+ align-items: center;
45
+ justify-content: center;
46
+ border-bottom: 1px solid #fff;
47
+ }
48
+ .chatbot header img {
49
+ height: 40px;
50
+ border-radius: 50%;
51
+ margin-right: 10px;
52
+ }
53
+ .chatbot header h2 {
54
+ font-size: 1.2rem;
55
+ text-align: center;
56
+ }
57
+ .chatbox {
58
+ background-color: #fff;
59
+ flex: 1;
60
+ padding: 15px;
61
+ overflow-y: auto;
62
+ }
63
+ .chat {
64
+ display: flex;
65
+ align-items: flex-start;
66
+ margin-bottom: 15px;
67
+ }
68
+ .chat img {
69
+ height: 35px;
70
+ border-radius: 50%;
71
+ margin-right: 10px;
72
+ }
73
+ .chat p {
74
+ background-color: #e4e6eb;
75
+ color: #000;
76
+ padding: 10px 15px;
77
+ border-radius: 10px;
78
+ max-width: 70%;
79
+ word-wrap: break-word;
80
+ }
81
+ .chat.outgoing p {
82
+ background-color: #4b7bec;
83
+ color: #fff;
84
+ margin-left: auto;
85
+ border-radius: 10px 10px 0 10px;
86
+ }
87
+ .chat-input {
88
+ display: flex;
89
+ align-items: center;
90
+ padding: 10px;
91
+ border-top: 1px solid #ccc;
92
+ }
93
+ .chat-input textarea {
94
+ flex: 1;
95
+ height: 40px;
96
+ border: none;
97
+ border-radius: 20px;
98
+ padding: 10px;
99
+ font-size: 1rem;
100
+ resize: none;
101
+ margin-right: 10px;
102
+ }
103
+ .chat-input button {
104
+ background-color: #4b7bec;
105
+ border: none;
106
+ border-radius: 50%;
107
+ width: 40px;
108
+ height: 40px;
109
+ display: flex;
110
+ align-items: center;
111
+ justify-content: center;
112
+ cursor: pointer;
113
+ }
114
+ .chat-input button span {
115
+ color: #fff;
116
+ font-size: 1.2rem;
117
+ }
118
+ .thinking {
119
+ font-style: italic;
120
+ color: #888;
121
+ }
122
+ .chatbot-toggle {
123
+ position: fixed;
124
+ bottom: 20px;
125
+ right: 20px;
126
+ background-color: #4b7bec;
127
+ color: #fff;
128
+ border: none;
129
+ border-radius: 50%;
130
+ width: 50px;
131
+ height: 50px;
132
+ display: flex;
133
+ align-items: center;
134
+ justify-content: center;
135
+ cursor: pointer;
136
+ z-index: 1001;
137
+ }
138
+ </style>
139
+ </head>
140
+ <body>
141
+ <div class="chatbot" id="chatbot">
142
+ <header>
143
+ <img src="/static/suretrust.png" alt="Sure Trust">
144
+ <h2>Sure Trust</h2>
145
+ </header>
146
+ <div class="chatbox" id="chatbox">
147
+ <div class="chat incoming">
148
+ <img src="/static/suretrust.png" alt="">
149
+ <p>Welcome! Do you want to make an inquiry or register?</p>
150
+ </div>
151
+ </div>
152
+ <div class="chat-input">
153
+ <textarea id="input" placeholder="Enter a message..." required></textarea>
154
+ <button onclick="sendMessage()">
155
+ <span class="fa-regular fa-paper-plane"></span>
156
+ </button>
157
+ </div>
158
+ </div>
159
+
160
+ <button class="chatbot-toggle" id="chatbot-toggle">
161
+ <span class="fa-regular fa-comment-dots"></span>
162
+ </button>
163
+
164
+ <script>
165
+ let initialMessage = true;
166
+ const chatbot = document.getElementById('chatbot');
167
+ const chatbotToggle = document.getElementById('chatbot-toggle');
168
+
169
+ chatbotToggle.addEventListener('click', () => {
170
+ chatbot.style.display = chatbot.style.display === 'none' ? 'flex' : 'none';
171
+ chatbotToggle.style.bottom = chatbot.style.display === 'none' ? '20px' : '370px'; // Adjust position
172
+ });
173
+
174
+ function getCookie(name) {
175
+ let cookieValue = null;
176
+ if (document.cookie && document.cookie !== '') {
177
+ const cookies = document.cookie.split(';');
178
+ for (let i = 0; i < cookies.length; i++) {
179
+ const cookie = cookies[i].trim();
180
+ if (cookie.substring(0, name.length + 1) === (name + '=')) {
181
+ cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
182
+ break;
183
+ }
184
+ }
185
+ }
186
+ return cookieValue;
187
+ }
188
+
189
+ function sendMessage() {
190
+ const input = document.getElementById('input');
191
+ const message = input.value.trim();
192
+ if (!message) return;
193
+
194
+ const chatbox = document.getElementById('chatbox');
195
+
196
+ // Append user message to chatbox
197
+ const userMessage = document.createElement('div');
198
+ userMessage.className = 'chat outgoing';
199
+ userMessage.innerHTML = `<p>${message}</p>`;
200
+ chatbox.appendChild(userMessage);
201
+ input.value = '';
202
+
203
+ // Check for initial message response
204
+ if (initialMessage) {
205
+ initialMessage = false;
206
+ if (message.toLowerCase().includes('register')) {
207
+ window.location.href = '{% url 'register' %}'; // Correct URL for Django view
208
+ return;
209
+ }
210
+ }
211
+
212
+ // Append "thinking..." message to chatbox
213
+ const thinkingMessage = document.createElement('div');
214
+ thinkingMessage.className = 'chat incoming thinking';
215
+ thinkingMessage.innerHTML = `<img src="/static/suretrust.png" alt=""><p>Processing your request, please wait a moment.</p>`;
216
+ chatbox.appendChild(thinkingMessage);
217
+ chatbox.scrollTop = chatbox.scrollHeight;
218
+
219
+ const csrftoken = getCookie('csrftoken');
220
+
221
+ // Send message to backend
222
+ fetch('/submit_message/', {
223
+ method: 'POST',
224
+ headers: {
225
+ 'Content-Type': 'application/json',
226
+ 'X-CSRFToken': csrftoken
227
+ },
228
+ body: JSON.stringify({ input: message })
229
+ })
230
+ .then(response => response.json())
231
+ .then(data => {
232
+ // Replace "thinking..." message with bot response
233
+ chatbox.removeChild(thinkingMessage);
234
+
235
+ const botMessage = document.createElement('div');
236
+ botMessage.className = 'chat incoming';
237
+ botMessage.innerHTML = `<img src="/static/suretrust.png" alt=""><p>${data.response}</p>`;
238
+ chatbox.appendChild(botMessage);
239
+ chatbox.scrollTop = chatbox.scrollHeight;
240
+ })
241
+ .catch(error => {
242
+ console.error('Error:', error);
243
+ alert('An error occurred. Please try again.');
244
+ });
245
+ }
246
+ </script>
247
+ </body>
248
+ </html>
249
+
250
+
251
+
252
+
templates/registration.html ADDED
@@ -0,0 +1,100 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <title>Registration Form</title>
6
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
7
+ <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.2/css/all.min.css">
8
+ <style>
9
+ @import url('https://fonts.googleapis.com/css2?family=Roboto:wght@300;400;500;700&display=swap');
10
+ * {
11
+ margin: 0;
12
+ padding: 0;
13
+ box-sizing: border-box;
14
+ font-family: 'Roboto', sans-serif;
15
+ }
16
+ body {
17
+ background-color: #1a1a2e;
18
+ display: flex;
19
+ justify-content: center;
20
+ align-items: center;
21
+ height: 100vh;
22
+ color: #fff;
23
+ }
24
+ .registration-form {
25
+ background-color: #fff;
26
+ color: #000;
27
+ padding: 20px;
28
+ border-radius: 10px;
29
+ box-shadow: 0 0 20px rgba(0, 0, 0, 0.2);
30
+ width: 300px;
31
+ }
32
+ .registration-form h2 {
33
+ text-align: center;
34
+ margin-bottom: 20px;
35
+ }
36
+ .registration-form .form-group {
37
+ margin-bottom: 15px;
38
+ }
39
+ .registration-form .form-group label {
40
+ display: block;
41
+ margin-bottom: 5px;
42
+ }
43
+ .registration-form .form-group input,
44
+ .registration-form .form-group select {
45
+ width: 100%;
46
+ padding: 10px;
47
+ border-radius: 5px;
48
+ border: 1px solid #ccc;
49
+ }
50
+ .registration-form button {
51
+ width: 100%;
52
+ padding: 10px;
53
+ border-radius: 5px;
54
+ border: none;
55
+ background-color: #4b7bec;
56
+ color: #fff;
57
+ font-size: 1rem;
58
+ cursor: pointer;
59
+ }
60
+ </style>
61
+ </head>
62
+ <body>
63
+ <div class="registration-form">
64
+ <h2>Registration</h2>
65
+ <form action="{% url 'register' %}" method="post"> <!-- Correct URL for Django view -->
66
+ {% csrf_token %}
67
+ <div class="form-group">
68
+ <label for="name">Name</label>
69
+ <input type="text" id="name" name="name" required>
70
+ </div>
71
+ <div class="form-group">
72
+ <label for="email">Email</label>
73
+ <input type="email" id="email" name="email" required>
74
+ </div>
75
+ <div class="form-group">
76
+ <label for="mobile">Mobile Number</label>
77
+ <input type="tel" id="mobile" name="mobile" pattern="[0-9]{10}" required>
78
+ </div>
79
+ <div class="form-group">
80
+ <label for="Course">Course</label>
81
+ <select class="form-control" id="Course" name="Course">
82
+ <option value="Robotics Foundation Courses">Robotics Foundation Courses</option>
83
+ <option value="CyberSecurity and Ethical Hacking">CyberSecurity and Ethical Hacking</option>
84
+ <option value="Android App Devepopment">Android App Devepopment</option>
85
+ <option value="Full Stack Development">Full Stack Development</option>
86
+ <option value="Core Java Programming">Core Java Programming</option>
87
+ <option value="Python and machine learning Basic Application">Python and machine learning Basic Application</option>
88
+ <option value="Digital Marketing">Digital Marketing</option>
89
+ <option value="Embedded Systems and Internet of Things">Embedded Systems and Internet of Things</option>
90
+ <option value="Financial Modeling and Valuation">Financial Modeling and Valuation</option>
91
+ <option value="SQL and Microsoft BI Tools including PowerBI">SQL and Microsoft BI Tools including PowerBI</option>
92
+ <option value="Data Science and Data Analytics- Basic Applications">Data Science and Data Analytics- Basic Applications</option>
93
+ <option value="PCB Designing">12. PCB Designing</option>
94
+ </select>
95
+ </div>
96
+ <button type="submit">Register</button>
97
+ </form>
98
+ </div>
99
+ </body>
100
+ </html>