Update app.py
Browse files
app.py
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
import tempfile
|
| 3 |
from langchain.text_splitter import RecursiveCharacterTextSplitter
|
|
@@ -11,7 +12,6 @@ from langchain.llms import LlamaCpp
|
|
| 11 |
from langchain.prompts import PromptTemplate
|
| 12 |
import os
|
| 13 |
import pandas as pd
|
| 14 |
-
from transformers import AutoModel
|
| 15 |
|
| 16 |
|
| 17 |
prompt_template_questions = """
|
|
@@ -96,21 +96,20 @@ if file_path:
|
|
| 96 |
verbose=True,
|
| 97 |
n_ctx=4096
|
| 98 |
)
|
| 99 |
-
model = AutoModel.from_pretrained("TheBloke/zephyr-7B-beta-GGUF")
|
| 100 |
# Initialize question generation chain
|
| 101 |
question_gen_chain = load_summarize_chain(llm=llm_question_gen, chain_type="refine", verbose=True,
|
| 102 |
question_prompt=PROMPT_QUESTIONS, refine_prompt=REFINE_PROMPT_QUESTIONS)
|
| 103 |
# Run question generation chain
|
| 104 |
questions = question_gen_chain.run(docs_question_gen)
|
| 105 |
|
| 106 |
-
|
| 107 |
-
llm_answer_gen = LlamaCpp(
|
| 108 |
streaming = True,
|
| 109 |
model_path = AutoModel.from_pretrained("TheBloke/zephyr-7B-beta-GGUF"),
|
| 110 |
temperature=0.75,
|
| 111 |
top_p=1,
|
| 112 |
verbose=True,
|
| 113 |
-
n_ctx=4096
|
|
|
|
| 114 |
|
| 115 |
# Create vector database for answer generation
|
| 116 |
embeddings = HuggingFaceEmbeddings(model_name="sentence-transformers/all-MiniLM-L6-v2", model_kwargs={"device": "cpu"})
|
|
@@ -154,3 +153,25 @@ if file_path:
|
|
| 154 |
if file_path:
|
| 155 |
os.remove(file_path)
|
| 156 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from transformers import AutoModel
|
| 2 |
import streamlit as st
|
| 3 |
import tempfile
|
| 4 |
from langchain.text_splitter import RecursiveCharacterTextSplitter
|
|
|
|
| 12 |
from langchain.prompts import PromptTemplate
|
| 13 |
import os
|
| 14 |
import pandas as pd
|
|
|
|
| 15 |
|
| 16 |
|
| 17 |
prompt_template_questions = """
|
|
|
|
| 96 |
verbose=True,
|
| 97 |
n_ctx=4096
|
| 98 |
)
|
|
|
|
| 99 |
# Initialize question generation chain
|
| 100 |
question_gen_chain = load_summarize_chain(llm=llm_question_gen, chain_type="refine", verbose=True,
|
| 101 |
question_prompt=PROMPT_QUESTIONS, refine_prompt=REFINE_PROMPT_QUESTIONS)
|
| 102 |
# Run question generation chain
|
| 103 |
questions = question_gen_chain.run(docs_question_gen)
|
| 104 |
|
| 105 |
+
llm_question_gen = LlamaCpp(
|
|
|
|
| 106 |
streaming = True,
|
| 107 |
model_path = AutoModel.from_pretrained("TheBloke/zephyr-7B-beta-GGUF"),
|
| 108 |
temperature=0.75,
|
| 109 |
top_p=1,
|
| 110 |
verbose=True,
|
| 111 |
+
n_ctx=4096
|
| 112 |
+
)
|
| 113 |
|
| 114 |
# Create vector database for answer generation
|
| 115 |
embeddings = HuggingFaceEmbeddings(model_name="sentence-transformers/all-MiniLM-L6-v2", model_kwargs={"device": "cpu"})
|
|
|
|
| 153 |
if file_path:
|
| 154 |
os.remove(file_path)
|
| 155 |
|
| 156 |
+
|
| 157 |
+
|
| 158 |
+
|
| 159 |
+
# Initialize Large Language Model for question generation
|
| 160 |
+
llm_question_gen = LlamaCpp(
|
| 161 |
+
streaming = True,
|
| 162 |
+
model_path = AutoModel.from_pretrained("TheBloke/zephyr-7B-beta-GGUF"),
|
| 163 |
+
temperature=0.75,
|
| 164 |
+
top_p=1,
|
| 165 |
+
verbose=True,
|
| 166 |
+
n_ctx=4096
|
| 167 |
+
)
|
| 168 |
+
|
| 169 |
+
# Initialize Large Language Model for answer generation
|
| 170 |
+
llm_answer_gen = LlamaCpp(
|
| 171 |
+
streaming = True,
|
| 172 |
+
model_path = AutoModel.from_pretrained("TheBloke/zephyr-7B-beta-GGUF"),
|
| 173 |
+
temperature=0.75,
|
| 174 |
+
top_p=1,
|
| 175 |
+
verbose=True,
|
| 176 |
+
n_ctx=4096)
|
| 177 |
+
|