Spaces:
Build error
Build error
Initial Draft
Browse files
app.py
CHANGED
@@ -3,7 +3,6 @@ import tempfile
|
|
3 |
import os
|
4 |
import re
|
5 |
import torch
|
6 |
-
from threading import Thread
|
7 |
|
8 |
from transformers import AutoTokenizer, AutoModelForCausalLM, pipeline, TextIteratorStreamer
|
9 |
from langchain_community.document_loaders import PyPDFLoader
|
@@ -52,23 +51,22 @@ def fn_generate_QnA_response(mv_selected_model, mv_user_question, lv_vector_stor
|
|
52 |
print("Step4: Generating LLM response")
|
53 |
mv_processing_message.text("Step4: Generating LLM response")
|
54 |
|
55 |
-
lv_tokenizer = AutoTokenizer.from_pretrained(
|
56 |
-
lv_model = AutoModelForCausalLM.from_pretrained(
|
57 |
mv_selected_model,
|
58 |
-
|
|
|
|
|
|
|
|
|
59 |
device_map="cpu",
|
60 |
trust_remote_code=True
|
61 |
)
|
62 |
-
# lv_streamer = TextIteratorStreamer(
|
63 |
-
# tokenizer=lv_tokenizer,
|
64 |
-
# skip_prompt=True,
|
65 |
-
# skip_special_tokens=True,
|
66 |
-
# timeout=300.0
|
67 |
-
# )
|
68 |
lv_ms_phi2_pipeline = pipeline(
|
69 |
"text-generation", tokenizer=lv_tokenizer, model=lv_model,
|
70 |
-
|
|
|
71 |
)
|
|
|
72 |
lv_hf_phi2_pipeline = HuggingFacePipeline(pipeline=lv_ms_phi2_pipeline)
|
73 |
lv_chain = ConversationalRetrievalChain.from_llm(lv_hf_phi2_pipeline, lv_vector_store.as_retriever(), return_source_documents=True)
|
74 |
lv_response = lv_chain({"question": mv_user_question, 'chat_history': lv_chat_history})
|
@@ -116,9 +114,6 @@ def main():
|
|
116 |
st.text("")
|
117 |
st.text("")
|
118 |
st.text("")
|
119 |
-
st.text("")
|
120 |
-
st.text("")
|
121 |
-
st.text("")
|
122 |
|
123 |
mv_vector_storage_dir = "/workspace/knowledge-base/01-ML/01-dev/adhoc/Talk2PDF/vector_store"
|
124 |
|
@@ -164,7 +159,6 @@ def main():
|
|
164 |
st.markdown(message["content"])
|
165 |
|
166 |
|
167 |
-
|
168 |
# Calling Main Function
|
169 |
if __name__ == '__main__':
|
170 |
main()
|
|
|
3 |
import os
|
4 |
import re
|
5 |
import torch
|
|
|
6 |
|
7 |
from transformers import AutoTokenizer, AutoModelForCausalLM, pipeline, TextIteratorStreamer
|
8 |
from langchain_community.document_loaders import PyPDFLoader
|
|
|
51 |
print("Step4: Generating LLM response")
|
52 |
mv_processing_message.text("Step4: Generating LLM response")
|
53 |
|
54 |
+
lv_tokenizer = AutoTokenizer.from_pretrained(
|
|
|
55 |
mv_selected_model,
|
56 |
+
model_max_length=2048,
|
57 |
+
trust_remote_code=True
|
58 |
+
)
|
59 |
+
lv_model = AutoModelForCausalLM.from_pretrained(
|
60 |
+
mv_selected_model,
|
61 |
device_map="cpu",
|
62 |
trust_remote_code=True
|
63 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
64 |
lv_ms_phi2_pipeline = pipeline(
|
65 |
"text-generation", tokenizer=lv_tokenizer, model=lv_model,
|
66 |
+
pad_token_id=lv_tokenizer.eos_token_id, eos_token_id=lv_tokenizer.eos_token_id,
|
67 |
+
device_map="cpu", max_new_tokens=2048, return_full_text=True
|
68 |
)
|
69 |
+
|
70 |
lv_hf_phi2_pipeline = HuggingFacePipeline(pipeline=lv_ms_phi2_pipeline)
|
71 |
lv_chain = ConversationalRetrievalChain.from_llm(lv_hf_phi2_pipeline, lv_vector_store.as_retriever(), return_source_documents=True)
|
72 |
lv_response = lv_chain({"question": mv_user_question, 'chat_history': lv_chat_history})
|
|
|
114 |
st.text("")
|
115 |
st.text("")
|
116 |
st.text("")
|
|
|
|
|
|
|
117 |
|
118 |
mv_vector_storage_dir = "/workspace/knowledge-base/01-ML/01-dev/adhoc/Talk2PDF/vector_store"
|
119 |
|
|
|
159 |
st.markdown(message["content"])
|
160 |
|
161 |
|
|
|
162 |
# Calling Main Function
|
163 |
if __name__ == '__main__':
|
164 |
main()
|