hideosnes commited on
Commit
6cb6a24
·
verified ·
1 Parent(s): 624df34

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -1
app.py CHANGED
@@ -31,7 +31,14 @@ def summarize(file, text, style, length):
31
  with fitz.open(stream=file.read(), filetype="pdf") as doc:
32
  text_input = " ".join([page.get_text() for page in doc])
33
  elif file.name.endswith(".txt"):
34
- text_input = file.read().decode("utf-8")
 
 
 
 
 
 
 
35
  elif text:
36
  text_input = text
37
  # If the input text is empty or contains only whitespace,
 
31
  with fitz.open(stream=file.read(), filetype="pdf") as doc:
32
  text_input = " ".join([page.get_text() for page in doc])
33
  elif file.name.endswith(".txt"):
34
+ text_input = str(file)
35
+ # text_input = file.read().decode("utf-8") <-- Bug
36
+ # in Hugging Face Spaces, when you use gr.File, text files are passed as
37
+ # a NamedString (which acts like a string with a .name attribute),
38
+ # while binary files (like PDFs) are passed as a NamedBytesIO
39
+ # (which has a .read() method).
40
+ # ### #
41
+
42
  elif text:
43
  text_input = text
44
  # If the input text is empty or contains only whitespace,