Update app.py
Browse files
app.py
CHANGED
@@ -81,22 +81,25 @@ class TogetherEmbeddings(Embeddings):
|
|
81 |
@st.cache_resource
|
82 |
def get_pdf_index():
|
83 |
with st.spinner('📄 در حال پردازش فایل PDF...'):
|
84 |
-
loader =
|
85 |
-
|
86 |
-
|
87 |
-
|
|
|
|
|
|
|
|
|
88 |
)
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
).from_loaders(loader)
|
93 |
|
94 |
index = get_pdf_index()
|
95 |
|
96 |
-
llm =
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
)
|
101 |
|
102 |
chain = RetrievalQA.from_chain_type(
|
|
|
81 |
@st.cache_resource
|
82 |
def get_pdf_index():
|
83 |
with st.spinner('📄 در حال پردازش فایل PDF...'):
|
84 |
+
loader = PyPDFLoader('test1.pdf')
|
85 |
+
documents = loader.load()
|
86 |
+
|
87 |
+
text_splitter = RecursiveCharacterTextSplitter(chunk_size=300, chunk_overlap=0)
|
88 |
+
texts = text_splitter.split_documents(documents)
|
89 |
+
|
90 |
+
embeddings = HuggingFaceEmbeddings(
|
91 |
+
model_name="sentence-transformers/all-MiniLM-L6-v2"
|
92 |
)
|
93 |
+
|
94 |
+
index = FAISS.from_documents(texts, embeddings)
|
95 |
+
return index
|
|
|
96 |
|
97 |
index = get_pdf_index()
|
98 |
|
99 |
+
llm = HuggingFaceHub(
|
100 |
+
repo_id="HuggingFaceH4/zephyr-7b-alpha", # یا مدل دلخواهت مثل llama یا mistral
|
101 |
+
model_kwargs={"temperature": 0.7, "max_new_tokens": 512},
|
102 |
+
huggingfacehub_api_token="توکن شما"
|
103 |
)
|
104 |
|
105 |
chain = RetrievalQA.from_chain_type(
|