Spaces:
Sleeping
Sleeping
Commit
·
720da31
1
Parent(s):
a59eaef
Updated app.py
Browse files
app.py
CHANGED
|
@@ -32,7 +32,6 @@ import torch
|
|
| 32 |
|
| 33 |
db_name = "vector_db"
|
| 34 |
folder = "my-knowledge-base/"
|
| 35 |
-
MODEL_NAME = "mistralai/Mistral-7B-Instruct-v0.3"
|
| 36 |
|
| 37 |
load_dotenv()
|
| 38 |
HF_TOKEN = os.getenv("HF_TOKEN")
|
|
@@ -40,13 +39,6 @@ if HF_TOKEN is None:
|
|
| 40 |
raise ValueError("HF_TOKEN is not set. Check your .env file.")
|
| 41 |
login(HF_TOKEN, add_to_git_credential=True)
|
| 42 |
|
| 43 |
-
tokenizer = AutoTokenizer.from_pretrained(MODEL_NAME, token=HF_TOKEN)
|
| 44 |
-
model = AutoModelForCausalLM.from_pretrained(
|
| 45 |
-
MODEL_NAME,
|
| 46 |
-
device_map="cpu",
|
| 47 |
-
token=HF_TOKEN
|
| 48 |
-
)
|
| 49 |
-
|
| 50 |
def process_files(files):
|
| 51 |
os.makedirs(folder, exist_ok=True)
|
| 52 |
|
|
@@ -88,14 +80,7 @@ def process_files(files):
|
|
| 88 |
result = collection.get(include=['embeddings', 'documents', 'metadatas'])
|
| 89 |
|
| 90 |
# HF Pipeline
|
| 91 |
-
hf_pipeline = pipeline(
|
| 92 |
-
"text-generation",
|
| 93 |
-
model=model,
|
| 94 |
-
tokenizer=tokenizer,
|
| 95 |
-
max_new_tokens=512, # Limit output length
|
| 96 |
-
temperature=0.7, # Control creativity
|
| 97 |
-
repetition_penalty=1.2
|
| 98 |
-
)
|
| 99 |
|
| 100 |
llm = HuggingFacePipeline(pipeline=hf_pipeline)
|
| 101 |
memory = ConversationBufferMemory(memory_key='chat_history', return_messages=True)
|
|
|
|
| 32 |
|
| 33 |
db_name = "vector_db"
|
| 34 |
folder = "my-knowledge-base/"
|
|
|
|
| 35 |
|
| 36 |
load_dotenv()
|
| 37 |
HF_TOKEN = os.getenv("HF_TOKEN")
|
|
|
|
| 39 |
raise ValueError("HF_TOKEN is not set. Check your .env file.")
|
| 40 |
login(HF_TOKEN, add_to_git_credential=True)
|
| 41 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 42 |
def process_files(files):
|
| 43 |
os.makedirs(folder, exist_ok=True)
|
| 44 |
|
|
|
|
| 80 |
result = collection.get(include=['embeddings', 'documents', 'metadatas'])
|
| 81 |
|
| 82 |
# HF Pipeline
|
| 83 |
+
hf_pipeline = pipeline("document-question-answering", model="impira/layoutlm-document-qa")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 84 |
|
| 85 |
llm = HuggingFacePipeline(pipeline=hf_pipeline)
|
| 86 |
memory = ConversationBufferMemory(memory_key='chat_history', return_messages=True)
|