MarcosRodrigo commited on
Commit
c852af8
·
verified ·
1 Parent(s): 89afe94

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -6
app.py CHANGED
@@ -5,11 +5,11 @@ import os
5
  from huggingface_hub import HfApi, upload_file, list_repo_files, hf_hub_download
6
 
7
  # Configuration for Hugging Face Repository
8
- REPO_ID = "MarcosRodrigo/Breakfast-Poll" # Replace with your repository ID
9
  HISTORY_DIR = "history" # Directory within the repository to store history
10
 
11
  # Hugging Face API (requires a token with write access)
12
- hf_token = st.secrets["HF_TOKEN"] # Store your token in Streamlit secrets
13
  api = HfApi()
14
 
15
  # Initialize session state for temporary and historical storage
@@ -21,11 +21,13 @@ if "current_selections" not in st.session_state:
21
  # Load history from the repository
22
  def load_history():
23
  history = []
24
- files_in_repo = list_repo_files(REPO_ID, token=hf_token)
 
25
  history_files = [f for f in files_in_repo if f.startswith(f"{HISTORY_DIR}/") and f.endswith(".txt")]
26
 
27
  for file in history_files:
28
- local_filepath = hf_hub_download(repo_id=REPO_ID, filename=file, token=hf_token)
 
29
  summary_df = pd.read_csv(local_filepath)
30
  date = file.split("/")[-1].split(".txt")[0]
31
  history.append({"Date": date, "Summary": summary_df})
@@ -40,8 +42,8 @@ def save_summary_to_file(summary_df):
40
  local_filepath = f"{timestamp}.txt"
41
  summary_df.to_csv(local_filepath, index=False)
42
 
43
- # Upload the file to the repository
44
- upload_file(path_or_fileobj=local_filepath, path_in_repo=filename, repo_id=REPO_ID, token=hf_token)
45
 
46
  # Load history into session state
47
  if "history" not in st.session_state:
 
5
  from huggingface_hub import HfApi, upload_file, list_repo_files, hf_hub_download
6
 
7
  # Configuration for Hugging Face Repository
8
+ REPO_ID = "MarcosRodrigo/Breakfast-Poll" # Use the correct format: namespace/repo_name
9
  HISTORY_DIR = "history" # Directory within the repository to store history
10
 
11
  # Hugging Face API (requires a token with write access)
12
+ hf_token = st.secrets["HF_TOKEN"] # Use the token stored in the secrets manager
13
  api = HfApi()
14
 
15
  # Initialize session state for temporary and historical storage
 
21
  # Load history from the repository
22
  def load_history():
23
  history = []
24
+ # Specify `repo_type="space"` to indicate this is a Space repository
25
+ files_in_repo = list_repo_files(REPO_ID, token=hf_token, repo_type="space")
26
  history_files = [f for f in files_in_repo if f.startswith(f"{HISTORY_DIR}/") and f.endswith(".txt")]
27
 
28
  for file in history_files:
29
+ # Download the file from the Space repository with `repo_type="space"`
30
+ local_filepath = hf_hub_download(repo_id=REPO_ID, filename=file, token=hf_token, repo_type="space")
31
  summary_df = pd.read_csv(local_filepath)
32
  date = file.split("/")[-1].split(".txt")[0]
33
  history.append({"Date": date, "Summary": summary_df})
 
42
  local_filepath = f"{timestamp}.txt"
43
  summary_df.to_csv(local_filepath, index=False)
44
 
45
+ # Upload the file to the Space repository with `repo_type="space"`
46
+ upload_file(path_or_fileobj=local_filepath, path_in_repo=filename, repo_id=REPO_ID, token=hf_token, repo_type="space")
47
 
48
  # Load history into session state
49
  if "history" not in st.session_state: