InnerI commited on
Commit
78c8f0e
·
verified ·
1 Parent(s): 7210091

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -3
app.py CHANGED
@@ -175,9 +175,30 @@ with gr.Blocks(title="Vertical AI: Agriculture • Homesteading • Off-Grid •
175
  docs = []
176
  if files:
177
  for f in files:
178
- content = f.read().decode("utf-8", errors="ignore")
179
- docs.append((f.name, content))
180
- return add_docs(namespace, docs)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
181
  add_btn.click(add_action, [ns2, up], [add_out])
182
 
183
  q2 = gr.Textbox(label="Question", lines=3)
 
175
  docs = []
176
  if files:
177
  for f in files:
178
+ try:
179
+ # Try reading as text directly
180
+ if hasattr(f, "name"):
181
+ name = os.path.basename(f.name)
182
+ else:
183
+ name = "uploaded.txt"
184
+
185
+ # Open file path safely
186
+ if hasattr(f, "read"):
187
+ content = f.read()
188
+ if isinstance(content, bytes):
189
+ content = content.decode("utf-8", errors="ignore")
190
+ elif hasattr(f, "decode"):
191
+ content = f.decode("utf-8", errors="ignore")
192
+ else:
193
+ with open(f, "r", encoding="utf-8", errors="ignore") as fh:
194
+ content = fh.read()
195
+
196
+ docs.append((name, content))
197
+ except Exception as e:
198
+ return f"Error reading {f}: {e}"
199
+ if not docs:
200
+ return "No files processed."
201
+ return add_docs(namespace, docs)
202
  add_btn.click(add_action, [ns2, up], [add_out])
203
 
204
  q2 = gr.Textbox(label="Question", lines=3)