custom slider added
Browse files- requirements.txt +13 -12
- src/app.py +2 -2
- src/pdfchatbot.py +7 -7
requirements.txt
CHANGED
|
@@ -1,13 +1,14 @@
|
|
| 1 |
-
PyMuPDF
|
| 2 |
-
gradio
|
| 3 |
-
Pillow
|
| 4 |
-
torch
|
| 5 |
-
transformers
|
| 6 |
-
PyYAML
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
sentence-transformers==2.2.2
|
| 12 |
langchain
|
| 13 |
-
langchain-text-splitters
|
|
|
|
|
|
|
|
|
| 1 |
+
PyMuPDF
|
| 2 |
+
gradio
|
| 3 |
+
Pillow
|
| 4 |
+
torch
|
| 5 |
+
transformers
|
| 6 |
+
PyYAML
|
| 7 |
+
pypdf
|
| 8 |
+
Jinja2
|
| 9 |
+
accelerate
|
| 10 |
+
sentence-transformers
|
|
|
|
| 11 |
langchain
|
| 12 |
+
langchain-text-splitters
|
| 13 |
+
langchain_community
|
| 14 |
+
langchain_core
|
src/app.py
CHANGED
|
@@ -2,10 +2,10 @@ from interface import create_demo
|
|
| 2 |
from pdfchatbot import PDFChatBot
|
| 3 |
|
| 4 |
# Create Gradio interface
|
| 5 |
-
demo, chat_history, show_img, txt, submit_button, uploaded_pdf,
|
| 6 |
|
| 7 |
# Create PDFChatBot instance
|
| 8 |
-
pdf_chatbot = PDFChatBot()
|
| 9 |
pdf_chatbot.load_model()
|
| 10 |
pdf_chatbot.load_tokenizer()
|
| 11 |
|
|
|
|
| 2 |
from pdfchatbot import PDFChatBot
|
| 3 |
|
| 4 |
# Create Gradio interface
|
| 5 |
+
demo, chat_history, show_img, txt, submit_button, uploaded_pdf, slider1 = create_demo()
|
| 6 |
|
| 7 |
# Create PDFChatBot instance
|
| 8 |
+
pdf_chatbot = PDFChatBot(chunk_size_slider=slider1)
|
| 9 |
pdf_chatbot.load_model()
|
| 10 |
pdf_chatbot.load_tokenizer()
|
| 11 |
|
src/pdfchatbot.py
CHANGED
|
@@ -16,7 +16,7 @@ from langchain_text_splitters import CharacterTextSplitter
|
|
| 16 |
|
| 17 |
|
| 18 |
class PDFChatBot:
|
| 19 |
-
def __init__(self, config_path="config.yaml"):
|
| 20 |
"""
|
| 21 |
Initialize the PDFChatBot instance.
|
| 22 |
|
|
@@ -37,7 +37,7 @@ class PDFChatBot:
|
|
| 37 |
self.pipeline = None
|
| 38 |
self.chain = None
|
| 39 |
self.chunk_size = None
|
| 40 |
-
|
| 41 |
|
| 42 |
def load_config(self, file_path):
|
| 43 |
"""
|
|
@@ -71,7 +71,7 @@ class PDFChatBot:
|
|
| 71 |
if not text:
|
| 72 |
raise gr.Error('Enter text')
|
| 73 |
history.append((text, ''))
|
| 74 |
-
|
| 75 |
return history
|
| 76 |
|
| 77 |
def create_prompt_template(self):
|
|
@@ -180,9 +180,9 @@ class PDFChatBot:
|
|
| 180 |
self.chat_history.append((query, result["answer"]))
|
| 181 |
for char in result['answer']:
|
| 182 |
history[-1][-1] += char
|
| 183 |
-
return
|
| 184 |
|
| 185 |
-
def render_file(self, file,chunk_size
|
| 186 |
"""
|
| 187 |
Renders a specific page of a PDF file as an image.
|
| 188 |
|
|
@@ -192,8 +192,8 @@ class PDFChatBot:
|
|
| 192 |
Returns:
|
| 193 |
PIL.Image.Image: The rendered page as an image.
|
| 194 |
"""
|
| 195 |
-
|
| 196 |
-
|
| 197 |
print(chunk_size)
|
| 198 |
doc = fitz.open(file.name)
|
| 199 |
page = doc[self.page]
|
|
|
|
| 16 |
|
| 17 |
|
| 18 |
class PDFChatBot:
|
| 19 |
+
def __init__(self, config_path="config.yaml",chunk_size_slider=None):
|
| 20 |
"""
|
| 21 |
Initialize the PDFChatBot instance.
|
| 22 |
|
|
|
|
| 37 |
self.pipeline = None
|
| 38 |
self.chain = None
|
| 39 |
self.chunk_size = None
|
| 40 |
+
self.chunk_size_slider = chunk_size_slider
|
| 41 |
|
| 42 |
def load_config(self, file_path):
|
| 43 |
"""
|
|
|
|
| 71 |
if not text:
|
| 72 |
raise gr.Error('Enter text')
|
| 73 |
history.append((text, ''))
|
| 74 |
+
self.chunk_size_slider.interactive = False
|
| 75 |
return history
|
| 76 |
|
| 77 |
def create_prompt_template(self):
|
|
|
|
| 180 |
self.chat_history.append((query, result["answer"]))
|
| 181 |
for char in result['answer']:
|
| 182 |
history[-1][-1] += char
|
| 183 |
+
return result, " "
|
| 184 |
|
| 185 |
+
def render_file(self, file,chunk_size):
|
| 186 |
"""
|
| 187 |
Renders a specific page of a PDF file as an image.
|
| 188 |
|
|
|
|
| 192 |
Returns:
|
| 193 |
PIL.Image.Image: The rendered page as an image.
|
| 194 |
"""
|
| 195 |
+
if self.chunk_size_slider.interactive == False:
|
| 196 |
+
self.chunk_size_slider.interactive = True
|
| 197 |
print(chunk_size)
|
| 198 |
doc = fitz.open(file.name)
|
| 199 |
page = doc[self.page]
|