ruilongli commited on
Commit
51a527c
·
verified ·
1 Parent(s): f29b7af

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -1
app.py CHANGED
@@ -7,9 +7,13 @@ os.makedirs(UPLOAD_DIR, exist_ok=True)
7
  def save_file(file):
8
  if file is None:
9
  return "Please upload a file."
 
 
 
10
  file_path = os.path.join(UPLOAD_DIR, file.name)
11
  with open(file_path, "wb") as f:
12
- f.write(file.read())
 
13
  return f"✅ File `{file.name}` uploaded successfully!"
14
 
15
  with gr.Blocks() as demo:
 
7
  def save_file(file):
8
  if file is None:
9
  return "Please upload a file."
10
+
11
+ # file.name is the uploaded filename
12
+ # file is a NamedString -> use file to read content directly
13
  file_path = os.path.join(UPLOAD_DIR, file.name)
14
  with open(file_path, "wb") as f:
15
+ f.write(file) # just write the bytes
16
+
17
  return f"✅ File `{file.name}` uploaded successfully!"
18
 
19
  with gr.Blocks() as demo: