Spaces:
Sleeping
Sleeping
Peter
commited on
Commit
·
f8734a4
1
Parent(s):
11da24b
attempt file upload fix #1
Browse files
app.py
CHANGED
@@ -122,7 +122,7 @@ def load_uploaded_file(file_obj):
|
|
122 |
load_uploaded_file - process an uploaded file
|
123 |
|
124 |
Args:
|
125 |
-
file_obj (list): Gradio file object inside a list
|
126 |
|
127 |
Returns:
|
128 |
str, the uploaded file contents
|
@@ -130,13 +130,17 @@ def load_uploaded_file(file_obj):
|
|
130 |
|
131 |
# file_path = Path(file_obj[0].name)
|
132 |
|
|
|
|
|
|
|
|
|
133 |
try:
|
134 |
-
with open(
|
135 |
raw_text = f.read()
|
136 |
text = clean(raw_text, lower=False)
|
137 |
return text
|
138 |
except Exception as e:
|
139 |
-
logging.info(f"Trying to load file with path {
|
140 |
return "Error: Could not read file. Ensure that it is a valid text file with encoding UTF-8."
|
141 |
|
142 |
|
|
|
122 |
load_uploaded_file - process an uploaded file
|
123 |
|
124 |
Args:
|
125 |
+
file_obj (POTENTIALLY list): Gradio file object inside a list
|
126 |
|
127 |
Returns:
|
128 |
str, the uploaded file contents
|
|
|
130 |
|
131 |
# file_path = Path(file_obj[0].name)
|
132 |
|
133 |
+
# check if mysterious file object is a list
|
134 |
+
if isinstance(file_obj, list):
|
135 |
+
file_obj = file_obj[0]
|
136 |
+
file_path = Path(file_obj.name)
|
137 |
try:
|
138 |
+
with open(file_path, "r", encoding="utf-8", errors="ignore") as f:
|
139 |
raw_text = f.read()
|
140 |
text = clean(raw_text, lower=False)
|
141 |
return text
|
142 |
except Exception as e:
|
143 |
+
logging.info(f"Trying to load file with path {file_path}, error: {e}")
|
144 |
return "Error: Could not read file. Ensure that it is a valid text file with encoding UTF-8."
|
145 |
|
146 |
|