Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -24,7 +24,11 @@ def read_pdf(file_path):
|
|
24 |
for page in range(len(pdf_reader.pages)):
|
25 |
text += pdf_reader.pages[page].extract_text()
|
26 |
return text
|
27 |
-
|
|
|
|
|
|
|
|
|
28 |
def summarize(file, n_words):
|
29 |
global llm
|
30 |
# Read the content of the uploaded file
|
@@ -32,10 +36,9 @@ def summarize(file, n_words):
|
|
32 |
if file_path.endswith('.pdf'):
|
33 |
text = read_pdf(file_path)
|
34 |
else:
|
35 |
-
|
36 |
-
text = f.read()
|
37 |
|
38 |
-
lang = detect(text)
|
39 |
template_translate = '''
|
40 |
Please carefully read the following document:
|
41 |
<document>
|
|
|
24 |
for page in range(len(pdf_reader.pages)):
|
25 |
text += pdf_reader.pages[page].extract_text()
|
26 |
return text
|
27 |
+
def read_txt(file_path):
|
28 |
+
with open(file_path, "r", encoding="utf-8") as f:
|
29 |
+
text = f.read()
|
30 |
+
return text
|
31 |
+
|
32 |
def summarize(file, n_words):
|
33 |
global llm
|
34 |
# Read the content of the uploaded file
|
|
|
36 |
if file_path.endswith('.pdf'):
|
37 |
text = read_pdf(file_path)
|
38 |
else:
|
39 |
+
text = read_txt(file_path)
|
|
|
40 |
|
41 |
+
lang = detect(text[:300])
|
42 |
template_translate = '''
|
43 |
Please carefully read the following document:
|
44 |
<document>
|