HuberDa commited on
Commit
18810d9
·
1 Parent(s): 16e74e6
Files changed (1) hide show
  1. app.py +21 -9
app.py CHANGED
@@ -6,17 +6,29 @@ import os
6
  import tkinter as tk
7
  from PIL import Image
8
  import json
 
9
 
 
 
 
 
10
 
11
- def image_generator(directory_path):
12
- for filename in os.listdir(directory_path):
13
- if filename.endswith(".jpg") or filename.endswith(".png"):
14
- image_path = os.path.join(directory_path, filename)
15
- image = Image.open(image_path)
16
- image_array = np.array(image)
17
- yield filename,image_array
 
 
18
 
19
- directory_path = "C:\Users\danie\Downloads"
 
 
 
 
 
20
 
21
  # Create the generator
22
  image_gen = image_generator(directory_path)
@@ -24,7 +36,7 @@ image_gen = image_generator(directory_path)
24
  def record_input(fname:str, label:str):
25
  if label != "Pass":
26
  output = {"fname": fname, "label": label}
27
- with open("/content/output.txt", 'a') as f:
28
  json.dump(output, f)
29
  f.write("\n")
30
  fname, image = next(image_gen)
 
6
  import tkinter as tk
7
  from PIL import Image
8
  import json
9
+ from datasets import load_dataset
10
 
11
+ directory_path = load_dataset("HuberDa/Labeltest")
12
+ print("Spaltennamen:", directory_path['train'].column_names)
13
+ print("Erstes Beispiel im Train-Split:", directory_path['train'][0])
14
+ count = 0
15
 
16
+ def image_generator(hf_dataset, split="train"):
17
+ image_column = None
18
+ for col in hf_dataset[split].column_names:
19
+ if isinstance(hf_dataset[split][0][col], np.ndarray) or isinstance(hf_dataset[split][0][col], Image.Image):
20
+ image_column = col
21
+ break
22
+
23
+ if image_column is None:
24
+ raise ValueError("Keine Bildspalte gefunden!")
25
 
26
+ # Schleife durch das Dataset und generiere Bild-Arrays
27
+ for example in hf_dataset[split]:
28
+ image = example[image_column] # Greife auf das Bild zu
29
+ image_array = np.array(image) # Konvertiere es in ein NumPy-Array
30
+ filename = example['id'] if 'id' in example else "unknown"
31
+ yield filename, image_array
32
 
33
  # Create the generator
34
  image_gen = image_generator(directory_path)
 
36
  def record_input(fname:str, label:str):
37
  if label != "Pass":
38
  output = {"fname": fname, "label": label}
39
+ with open("output.txt", 'a') as f:
40
  json.dump(output, f)
41
  f.write("\n")
42
  fname, image = next(image_gen)