ali121300 commited on
Commit
5389c06
1 Parent(s): 3baac02

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -6
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
- import PyPDF2
86
- from deep_translator import GoogleTranslator
87
- with open(pdf_file_path, 'rb') as pdf_file:
 
 
 
88
  pdf_reader = PyPDF2.PdfReader(pdf_file)
89
- full_text = ""
 
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
- return(full_text)
 
 
 
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(