Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,7 +1,7 @@
|
|
1 |
import os
|
2 |
import streamlit as st
|
3 |
from dotenv import load_dotenv
|
4 |
-
from PyPDF2 import PdfReader
|
5 |
from langchain.text_splitter import CharacterTextSplitter
|
6 |
from langchain.embeddings import HuggingFaceBgeEmbeddings
|
7 |
from langchain.vectorstores import FAISS
|
@@ -82,17 +82,24 @@ def handle_userinput(user_question:str):
|
|
82 |
|
83 |
#############################################################################################################
|
84 |
def read_pdf_pr_en(pdf_file_path):
|
85 |
-
|
86 |
-
|
87 |
-
|
|
|
|
|
|
|
88 |
pdf_reader = PyPDF2.PdfReader(pdf_file)
|
89 |
-
|
|
|
90 |
for page in pdf_reader.pages:
|
91 |
page_pdf=page.extract_text()
|
92 |
translator = GoogleTranslator(source='persian', target='english')
|
93 |
result = translator.translate(page_pdf)
|
94 |
full_text +=result
|
95 |
-
|
|
|
|
|
|
|
96 |
#################################################################################################################
|
97 |
def main():
|
98 |
st.set_page_config(
|
|
|
1 |
import os
|
2 |
import streamlit as st
|
3 |
from dotenv import load_dotenv
|
4 |
+
#from PyPDF2 import PdfReader
|
5 |
from langchain.text_splitter import CharacterTextSplitter
|
6 |
from langchain.embeddings import HuggingFaceBgeEmbeddings
|
7 |
from langchain.vectorstores import FAISS
|
|
|
82 |
|
83 |
#############################################################################################################
|
84 |
def read_pdf_pr_en(pdf_file_path):
|
85 |
+
from deep_translator import GoogleTranslator
|
86 |
+
import PyPDF2
|
87 |
+
# مسیر فایل PDF را تعیین کنید
|
88 |
+
#pdf_file_path = '/content/d2en.pdf'
|
89 |
+
# باز کردن فایل PDF
|
90 |
+
with open(pdf_file_path, 'rb') as pdf_file:
|
91 |
pdf_reader = PyPDF2.PdfReader(pdf_file)
|
92 |
+
# خواندن محتوای صفحهها
|
93 |
+
full_text = ''
|
94 |
for page in pdf_reader.pages:
|
95 |
page_pdf=page.extract_text()
|
96 |
translator = GoogleTranslator(source='persian', target='english')
|
97 |
result = translator.translate(page_pdf)
|
98 |
full_text +=result
|
99 |
+
|
100 |
+
# نمایش محتوای کل فایل PDF
|
101 |
+
print(full_text)
|
102 |
+
return(full_text)
|
103 |
#################################################################################################################
|
104 |
def main():
|
105 |
st.set_page_config(
|