HotshotGoku commited on
Commit
5d30462
·
1 Parent(s): e7e0ab0

Image files shifted to HF dataset

Browse files
Files changed (2) hide show
  1. .gitignore +3 -1
  2. app.py +18 -7
.gitignore CHANGED
@@ -1,3 +1,5 @@
1
  # secret keys
2
  service_account.json
3
- app.ipynb
 
 
 
1
  # secret keys
2
  service_account.json
3
+ app.ipynb
4
+ # Hugging Face token
5
+ hf_token.txt
app.py CHANGED
@@ -4,10 +4,26 @@ from PIL import Image, ImageOps
4
  import numpy as np
5
  import gradio as gr
6
  from gspread import service_account_from_dict
 
7
 
8
  # -------- Configuration --------
9
- folder_ai = "images/AI"
10
- folder_real = "images/Real"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
11
  history_file = "history_state.json"
12
  # --------------------------------
13
 
@@ -45,11 +61,6 @@ def get_new_grid(state=None):
45
  """
46
 
47
  attempt_count = (state or {}).get("attempt_count", 0)
48
-
49
-
50
- # 2) Sample & shuffle images as before
51
- ai_files = [os.path.join(folder_ai, f) for f in os.listdir(folder_ai) if f.endswith(".png")]
52
- real_files = [os.path.join(folder_real, f) for f in os.listdir(folder_real) if f.endswith(".png")]
53
  t = random.randint(4, 12)
54
  sel_ai = random.sample(ai_files, t)
55
  sel_real = random.sample(real_files, 16 - t)
 
4
  import numpy as np
5
  import gradio as gr
6
  from gspread import service_account_from_dict
7
+ from huggingface_hub import HfApi, hf_hub_download
8
 
9
  # -------- Configuration --------
10
+ HF_TOKEN = os.environ["HF_TOKEN"]
11
+ api = HfApi(token=HF_TOKEN)
12
+ REPO_ID = "HotshotGoku/Images_Test_AI_or_Real"
13
+
14
+ # List files in the dataset
15
+ all_files = api.list_repo_files(
16
+ repo_id=REPO_ID,
17
+ repo_type="dataset"
18
+ )
19
+
20
+ # Get the AI vs Real folders
21
+ ai_remote = [f for f in all_files if f.startswith("AI/")]
22
+ real_remote = [f for f in all_files if f.startswith("Real/")]
23
+
24
+ ai_files = [hf_hub_download(repo_id=REPO_ID, repo_type="dataset",filename=path, token=HF_TOKEN) for path in ai_remote]
25
+ real_files = [hf_hub_download(repo_id=REPO_ID, repo_type="dataset",filename=path, token=HF_TOKEN) for path in real_remote]
26
+
27
  history_file = "history_state.json"
28
  # --------------------------------
29
 
 
61
  """
62
 
63
  attempt_count = (state or {}).get("attempt_count", 0)
 
 
 
 
 
64
  t = random.randint(4, 12)
65
  sel_ai = random.sample(ai_files, t)
66
  sel_real = random.sample(real_files, 16 - t)