kendrickfff commited on
Commit
968fed8
·
verified ·
1 Parent(s): 96a4e6c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -9
app.py CHANGED
@@ -13,13 +13,12 @@ import zipfile
13
  from PIL import Image
14
  import gradio as gr
15
 
16
- # Step 1: Setup Kaggle API
17
- # Ensure the .kaggle directory exists
18
  kaggle_dir = os.path.expanduser("~/.kaggle")
19
  if not os.path.exists(kaggle_dir):
20
  os.makedirs(kaggle_dir)
21
 
22
- # Step 2: Copy the kaggle.json file to the ~/.kaggle directory
23
  kaggle_json_path = "kaggle.json"
24
  kaggle_dest_path = os.path.join(kaggle_dir, "kaggle.json")
25
 
@@ -30,15 +29,14 @@ if not os.path.exists(kaggle_dest_path):
30
  else:
31
  print("Kaggle API key already exists.")
32
 
33
- # Step 3: Download the dataset from Kaggle using Kaggle CLI
34
  dataset_name = "mostafaabla/garbage-classification"
35
  print(f"Downloading the dataset: {dataset_name}")
36
  download_command = f"kaggle datasets download -d {dataset_name}"
37
 
38
  # Run the download command
39
  subprocess.run(download_command, shell=True)
40
-
41
- # Step 4: Unzip the downloaded dataset
42
  dataset_zip = "garbage-classification.zip"
43
  extracted_folder = "./garbage-classification"
44
 
@@ -54,12 +52,12 @@ else:
54
  print(f"Dataset zip file '{dataset_zip}' not found.")
55
 
56
 
57
-
58
 
59
  from PIL import Image
60
  import gradio as gr
61
 
62
- # Load your model
63
  def load_model():
64
  model = models.resnet50(weights='DEFAULT') # Using default weights for initialization
65
  num_ftrs = model.fc.in_features
@@ -116,7 +114,7 @@ def predict(image):
116
  bin_color = bin_colors[class_name] # Get the corresponding bin color
117
  return class_name, bin_color # Return both class name and bin color
118
 
119
- # Buat antarmuka Gradio dengan deskripsi
120
  iface = gr.Interface(
121
  fn=predict,
122
  inputs=gr.Image(type="numpy", label="Unggah Gambar"),
 
13
  from PIL import Image
14
  import gradio as gr
15
 
16
+ # Setup Kaggle API
 
17
  kaggle_dir = os.path.expanduser("~/.kaggle")
18
  if not os.path.exists(kaggle_dir):
19
  os.makedirs(kaggle_dir)
20
 
21
+ Copy the kaggle.json file to the ~/.kaggle directory
22
  kaggle_json_path = "kaggle.json"
23
  kaggle_dest_path = os.path.join(kaggle_dir, "kaggle.json")
24
 
 
29
  else:
30
  print("Kaggle API key already exists.")
31
 
32
+ Download the dataset from Kaggle using Kaggle CLI
33
  dataset_name = "mostafaabla/garbage-classification"
34
  print(f"Downloading the dataset: {dataset_name}")
35
  download_command = f"kaggle datasets download -d {dataset_name}"
36
 
37
  # Run the download command
38
  subprocess.run(download_command, shell=True)
39
+ Unzip the downloaded dataset
 
40
  dataset_zip = "garbage-classification.zip"
41
  extracted_folder = "./garbage-classification"
42
 
 
52
  print(f"Dataset zip file '{dataset_zip}' not found.")
53
 
54
 
55
+ # Model training and testing in separate directory at ipynb file (Copy of ai-portfolio Kendrick.ipynb)
56
 
57
  from PIL import Image
58
  import gradio as gr
59
 
60
+ # Load model
61
  def load_model():
62
  model = models.resnet50(weights='DEFAULT') # Using default weights for initialization
63
  num_ftrs = model.fc.in_features
 
114
  bin_color = bin_colors[class_name] # Get the corresponding bin color
115
  return class_name, bin_color # Return both class name and bin color
116
 
117
+ # Make Gradio interface
118
  iface = gr.Interface(
119
  fn=predict,
120
  inputs=gr.Image(type="numpy", label="Unggah Gambar"),