rbgo commited on
Commit
7f7b60a
·
verified ·
1 Parent(s): f9e9910

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -4
app.py CHANGED
@@ -54,8 +54,13 @@ def add_new_entry(file, password):
54
  return df, "Incorrect password. Upload failed."
55
 
56
  try:
57
- # Read the uploaded file
58
- new_df = pd.read_csv(file.name)
 
 
 
 
 
59
 
60
  columns_order = [
61
  "Model_Name", "Library", "TTFT", "Tokens-per-Second", "Token_Count",
@@ -69,14 +74,18 @@ def add_new_entry(file, password):
69
  # Append the new data to the existing DataFrame
70
  df = pd.concat([df, new_df], ignore_index=True)
71
 
72
- # Save the uploaded file to the CSV folder
73
  filename = os.path.basename(file.name)
74
  destination = os.path.join(csv_folder_path, filename)
75
- file.save(destination)
76
 
77
  return df, f"File '{filename}' uploaded and data added successfully!"
78
  except Exception as e:
79
  return df, f"An error occurred: {str(e)}"
 
 
 
 
80
 
81
  def read_and_process_csv_files(folder_path):
82
  all_data = []
 
54
  return df, "Incorrect password. Upload failed."
55
 
56
  try:
57
+ # Create a temporary file
58
+ with tempfile.NamedTemporaryFile(delete=False, suffix='.csv') as temp_file:
59
+ temp_file.write(file.read())
60
+ temp_file_path = temp_file.name
61
+
62
+ # Read the CSV file
63
+ new_df = pd.read_csv(temp_file_path)
64
 
65
  columns_order = [
66
  "Model_Name", "Library", "TTFT", "Tokens-per-Second", "Token_Count",
 
74
  # Append the new data to the existing DataFrame
75
  df = pd.concat([df, new_df], ignore_index=True)
76
 
77
+ # Move the temporary file to the CSV folder
78
  filename = os.path.basename(file.name)
79
  destination = os.path.join(csv_folder_path, filename)
80
+ shutil.move(temp_file_path, destination)
81
 
82
  return df, f"File '{filename}' uploaded and data added successfully!"
83
  except Exception as e:
84
  return df, f"An error occurred: {str(e)}"
85
+ finally:
86
+ # Ensure the temporary file is removed if it still exists
87
+ if 'temp_file_path' in locals() and os.path.exists(temp_file_path):
88
+ os.unlink(temp_file_path)
89
 
90
  def read_and_process_csv_files(folder_path):
91
  all_data = []