Spaces:
Paused
Paused
Updated app.py
Browse files
app.py
CHANGED
|
@@ -1,8 +1,3 @@
|
|
| 1 |
-
import os
|
| 2 |
-
os.system("langchain upgrade-imports")
|
| 3 |
-
os.system("pip install accelerate")
|
| 4 |
-
os.system("pip install -i https://pypi.org/simple/ bitsandbytes")
|
| 5 |
-
|
| 6 |
import gradio as gr
|
| 7 |
# import fitz # PyMuPDF for extracting text from PDFs
|
| 8 |
from langchain.embeddings import HuggingFaceEmbeddings
|
|
@@ -61,12 +56,14 @@ query_pipeline = transformers.pipeline(
|
|
| 61 |
return_full_text=True,
|
| 62 |
torch_dtype=torch.float16,
|
| 63 |
device_map=device,
|
| 64 |
-
|
|
|
|
| 65 |
top_p=0.9,
|
| 66 |
top_k=50,
|
| 67 |
max_new_tokens=256
|
| 68 |
)
|
| 69 |
|
|
|
|
| 70 |
llm = HuggingFacePipeline(pipeline=query_pipeline)
|
| 71 |
|
| 72 |
books_db_client_retriever = RetrievalQA.from_chain_type(
|
|
@@ -91,7 +88,9 @@ def test_rag(query):
|
|
| 91 |
return corrected_text_books
|
| 92 |
|
| 93 |
# Define the Gradio interface
|
| 94 |
-
def chat(query, history=
|
|
|
|
|
|
|
| 95 |
answer = test_rag(query)
|
| 96 |
history.append((query, answer))
|
| 97 |
return history, history
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
# import fitz # PyMuPDF for extracting text from PDFs
|
| 3 |
from langchain.embeddings import HuggingFaceEmbeddings
|
|
|
|
| 56 |
return_full_text=True,
|
| 57 |
torch_dtype=torch.float16,
|
| 58 |
device_map=device,
|
| 59 |
+
do_sample=True, # Enable sampling
|
| 60 |
+
temperature=0.7, # Keep if sampling is used
|
| 61 |
top_p=0.9,
|
| 62 |
top_k=50,
|
| 63 |
max_new_tokens=256
|
| 64 |
)
|
| 65 |
|
| 66 |
+
|
| 67 |
llm = HuggingFacePipeline(pipeline=query_pipeline)
|
| 68 |
|
| 69 |
books_db_client_retriever = RetrievalQA.from_chain_type(
|
|
|
|
| 88 |
return corrected_text_books
|
| 89 |
|
| 90 |
# Define the Gradio interface
|
| 91 |
+
def chat(query, history=None):
|
| 92 |
+
if history is None:
|
| 93 |
+
history = []
|
| 94 |
answer = test_rag(query)
|
| 95 |
history.append((query, answer))
|
| 96 |
return history, history
|