Spaces:
Sleeping
Sleeping
Commit
·
3126a86
1
Parent(s):
945c1d0
Updated app.py
Browse files
app.py
CHANGED
|
@@ -15,6 +15,10 @@ from langchain_chroma import Chroma
|
|
| 15 |
from langchain.memory import ConversationBufferMemory
|
| 16 |
from langchain.chains import ConversationalRetrievalChain
|
| 17 |
from langchain_ollama import ChatOllama
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
import numpy as np
|
| 19 |
from sklearn.manifold import TSNE
|
| 20 |
import plotly.graph_objects as go
|
|
@@ -25,7 +29,10 @@ import shutil
|
|
| 25 |
|
| 26 |
db_name = "vector_db"
|
| 27 |
folder = "my-knowledge-base/"
|
| 28 |
-
|
|
|
|
|
|
|
|
|
|
| 29 |
|
| 30 |
def process_files(files):
|
| 31 |
os.makedirs(folder, exist_ok=True)
|
|
@@ -67,7 +74,17 @@ def process_files(files):
|
|
| 67 |
collection = vectorstore._collection
|
| 68 |
result = collection.get(include=['embeddings', 'documents', 'metadatas'])
|
| 69 |
|
| 70 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 71 |
memory = ConversationBufferMemory(memory_key='chat_history', return_messages=True)
|
| 72 |
retriever = vectorstore.as_retriever(search_kwargs={"k": 10})
|
| 73 |
global conversation_chain
|
|
|
|
| 15 |
from langchain.memory import ConversationBufferMemory
|
| 16 |
from langchain.chains import ConversationalRetrievalChain
|
| 17 |
from langchain_ollama import ChatOllama
|
| 18 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer, pipeline
|
| 19 |
+
from langchain.llms import HuggingFacePipeline
|
| 20 |
+
from langchain.memory import ConversationBufferMemory
|
| 21 |
+
from langchain.chains import ConversationalRetrievalChain
|
| 22 |
import numpy as np
|
| 23 |
from sklearn.manifold import TSNE
|
| 24 |
import plotly.graph_objects as go
|
|
|
|
| 29 |
|
| 30 |
db_name = "vector_db"
|
| 31 |
folder = "my-knowledge-base/"
|
| 32 |
+
|
| 33 |
+
MODEL_NAME = "mistralai/Mistral-7B-Instruct" # Example: Mistral-7B
|
| 34 |
+
tokenizer = AutoTokenizer.from_pretrained(MODEL_NAME)
|
| 35 |
+
model = AutoModelForCausalLM.from_pretrained(MODEL_NAME, device_map="auto")
|
| 36 |
|
| 37 |
def process_files(files):
|
| 38 |
os.makedirs(folder, exist_ok=True)
|
|
|
|
| 74 |
collection = vectorstore._collection
|
| 75 |
result = collection.get(include=['embeddings', 'documents', 'metadatas'])
|
| 76 |
|
| 77 |
+
# HF Pipeline
|
| 78 |
+
hf_pipeline = pipeline(
|
| 79 |
+
"text-generation",
|
| 80 |
+
model=model,
|
| 81 |
+
tokenizer=tokenizer,
|
| 82 |
+
max_new_tokens=512, # Limit output length
|
| 83 |
+
temperature=0.7, # Control creativity
|
| 84 |
+
repetition_penalty=1.2
|
| 85 |
+
)
|
| 86 |
+
|
| 87 |
+
llm = HuggingFacePipeline(pipeline=hf_pipeline)
|
| 88 |
memory = ConversationBufferMemory(memory_key='chat_history', return_messages=True)
|
| 89 |
retriever = vectorstore.as_retriever(search_kwargs={"k": 10})
|
| 90 |
global conversation_chain
|