kushagrasharma-13 commited on
Commit
8338481
·
1 Parent(s): 0d4441c

Add application file

Browse files
Files changed (3) hide show
  1. __pycache__/app.cpython-311.pyc +0 -0
  2. app.py +2 -10
  3. templates/index.html +120 -0
__pycache__/app.cpython-311.pyc ADDED
Binary file (4.36 kB). View file
 
app.py CHANGED
@@ -11,15 +11,12 @@ from qdrant_client import QdrantClient
11
  from langchain.vectorstores import Qdrant
12
  import os
13
  import json
 
14
 
15
  app = FastAPI()
16
  templates = Jinja2Templates(directory="templates")
17
  app.mount("/static", StaticFiles(directory="static"), name="static")
18
 
19
- # local_llm = r"meditron-7b.Q2_K.gguf"
20
- # local_llm = 'neural-chat-7b-v3-1.Q2_K.gguf'
21
- local_llm = 'Models/zephyr-7b-beta.Q2_K.gguf'
22
-
23
  config = {
24
  'max_new_tokens': 1024,
25
  'context_length': 2048,
@@ -31,12 +28,7 @@ config = {
31
  'threads': int(os.cpu_count() / 2)
32
  }
33
 
34
- llm = CTransformers(
35
- model=local_llm,
36
- model_type="mistral",
37
- lib="avx2",
38
- **config
39
- )
40
 
41
  print("LLM Initialized....")
42
 
 
11
  from langchain.vectorstores import Qdrant
12
  import os
13
  import json
14
+ from ctransformers import AutoModelForCausalLM
15
 
16
  app = FastAPI()
17
  templates = Jinja2Templates(directory="templates")
18
  app.mount("/static", StaticFiles(directory="static"), name="static")
19
 
 
 
 
 
20
  config = {
21
  'max_new_tokens': 1024,
22
  'context_length': 2048,
 
28
  'threads': int(os.cpu_count() / 2)
29
  }
30
 
31
+ llm = AutoModelForCausalLM.from_pretrained("TheBloke/zephyr-7B-beta-GGUF", model_file="zephyr-7b-beta.Q8_0.gguf", model_type="mistral", gpu_layers=50, **config)
 
 
 
 
 
32
 
33
  print("LLM Initialized....")
34
 
templates/index.html ADDED
@@ -0,0 +1,120 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <title>Patent RAG QA App</title>
7
+ <link href="https://fonts.googleapis.com/css2?family=Poppins:wght@400;600&display=swap" rel="stylesheet">
8
+ <link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet">
9
+ <style>
10
+ body {
11
+ background-color: black;
12
+ font-family: 'Poppins', sans-serif;
13
+ color: white;
14
+ }
15
+ .chat-container {
16
+ max-width: 800px;
17
+ margin: 50px auto;
18
+ margin-top: 10%;
19
+ padding: 20px;
20
+ background-color: #333;
21
+ border-radius: 10px;
22
+ }
23
+ .chat-heading {
24
+ text-align: center;
25
+ font-size: 2.5em;
26
+ font-weight: 600;
27
+ margin-bottom: 30px;
28
+ color: #ffd700; /* Golden color for the heading */
29
+ }
30
+ .chat-input {
31
+ margin-top: 20px; /* Added margin */
32
+ margin-bottom: 20px;
33
+ height: 100px; /* Increased height */
34
+ }
35
+ .chat-button {
36
+ background-color: green;
37
+ color: white;
38
+ padding: 10px 20px;
39
+ font-size: 1.2em;
40
+ }
41
+ .chat-response {
42
+ background-color: #444;
43
+ padding: 15px;
44
+ border-radius: 5px;
45
+ min-height: 100px; /* Minimum height for the response box */
46
+ margin-top: 20px;
47
+ }
48
+ .accordion {
49
+ margin-top: 20px;
50
+ background-color: #444;
51
+ border-radius: 5px;
52
+ }
53
+ .accordion-button {
54
+ color: white;
55
+ background-color: #555;
56
+ }
57
+ .accordion-body {
58
+ color: white; /* Improved visibility of text */
59
+ }
60
+ pre {
61
+ white-space:pre-wrap;
62
+ }
63
+ </style>
64
+ </head>
65
+ <body>
66
+ <div class="container chat-container">
67
+ <h1 class="chat-heading">Patent RAG QA App</h1>
68
+
69
+ <div class="accordion" id="appDescriptionAccordion">
70
+ <div class="accordion-item">
71
+ <h2 class="accordion-header" id="descriptionHeading">
72
+ <button class="accordion-button collapsed" type="button" data-bs-toggle="collapse" data-bs-target="#collapseDescription" aria-expanded="true" aria-controls="collapseDescription">
73
+ About This App
74
+ </button>
75
+ </h2>
76
+ <div id="collapseDescription" class="accordion-collapse collapse" aria-labelledby="descriptionHeading" data-bs-parent="#appDescriptionAccordion">
77
+ <div class="accordion-body text-dark">
78
+ This is a RAG implementation using Open Source stack.
79
+ </div>
80
+ </div>
81
+ </div>
82
+ </div>
83
+
84
+ <div class="row">
85
+ <div class="col">
86
+ <textarea id="userInput" class="form-control chat-input" placeholder="Type your query here..."></textarea>
87
+ <button id="submitBtn" class="btn chat-button">Submit</button>
88
+ <div id="response" class="chat-response"></div>
89
+ </div>
90
+ </div>
91
+ </div>
92
+
93
+ <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script>
94
+ <script>
95
+ document.getElementById('submitBtn').addEventListener('click', async function() {
96
+ var userInput = document.getElementById('userInput').value;
97
+ document.getElementById('response').innerHTML = '<p>Processing...</p>';
98
+ const formData = new FormData();
99
+ formData.append('query', userInput);
100
+ try {
101
+ const response = await fetch('/get_response', {
102
+ method: 'POST',
103
+ body: formData
104
+ });
105
+
106
+ if (!response.ok) {
107
+ throw new Error('Network response was not ok');
108
+ }
109
+
110
+ const data = await response.json();
111
+ document.getElementById('response').innerHTML = `<p>${data.answer}</p><br><pre><b>Context: </b> ${data.source_document}</pre><br><pre><b>Source Document: </b> ${data.doc}</pre>`;
112
+ } catch (error) {
113
+ console.error('Error:', error);
114
+ document.getElementById('response').innerHTML = '<p>Error processing your request</p>';
115
+ }
116
+ });
117
+
118
+ </script>
119
+ </body>
120
+ </html>