JEPHONETORRE commited on
Commit
b33d076
·
1 Parent(s): 195fe71
app.py CHANGED
@@ -4,6 +4,8 @@ import os
4
  import json
5
  import numpy as np
6
  import pickle
 
 
7
  from sklearn.ensemble import RandomForestClassifier
8
  from sklearn.model_selection import train_test_split
9
  from sklearn.metrics import accuracy_score
@@ -78,6 +80,35 @@ def classify_image(file_path):
78
  else:
79
  return "Invalid Image"
80
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
81
  # Streamlit app
82
  def main():
83
  st.title("Human or Alien Identification")
@@ -88,10 +119,11 @@ def main():
88
 
89
  - **Identify Image:** Upload an image and classify it as "Human" or "Alien." The classifications you save will be added to the training data.
90
  - **Train Model:** Review and manage the images already classified as "Human" or "Alien." Upload additional images to improve the training dataset.
 
91
  """
92
  )
93
 
94
- tab1, tab2 = st.tabs(["Identify Image", "Train Model"])
95
 
96
  with tab1:
97
  st.header("Identify Image")
@@ -194,5 +226,17 @@ def main():
194
  else:
195
  st.warning("No alien images found for training.")
196
 
 
 
 
 
 
 
 
 
 
 
 
 
197
  if __name__ == "__main__":
198
  main()
 
4
  import json
5
  import numpy as np
6
  import pickle
7
+ import zipfile
8
+ from io import BytesIO
9
  from sklearn.ensemble import RandomForestClassifier
10
  from sklearn.model_selection import train_test_split
11
  from sklearn.metrics import accuracy_score
 
80
  else:
81
  return "Invalid Image"
82
 
83
+ # Create a sample dataset for download
84
+ def create_sample_dataset():
85
+ sample_dir = "sample_dataset"
86
+ os.makedirs(sample_dir, exist_ok=True)
87
+
88
+ # Create Human and Alien directories
89
+ human_dir = os.path.join(sample_dir, "Human")
90
+ alien_dir = os.path.join(sample_dir, "Alien")
91
+ os.makedirs(human_dir, exist_ok=True)
92
+ os.makedirs(alien_dir, exist_ok=True)
93
+
94
+ # Add placeholder images (replace with real images in a practical application)
95
+ for i in range(1, 4):
96
+ human_image_path = os.path.join(human_dir, f"human_{i}.jpg")
97
+ alien_image_path = os.path.join(alien_dir, f"alien_{i}.jpg")
98
+ Image.new('RGB', (64, 64), color=(255, 0, 0)).save(human_image_path)
99
+ Image.new('RGB', (64, 64), color=(0, 255, 0)).save(alien_image_path)
100
+
101
+ # Create a ZIP file for download
102
+ zip_buffer = BytesIO()
103
+ with zipfile.ZipFile(zip_buffer, "w") as zip_file:
104
+ for folder_name, subfolders, filenames in os.walk(sample_dir):
105
+ for filename in filenames:
106
+ file_path = os.path.join(folder_name, filename)
107
+ arcname = os.path.relpath(file_path, sample_dir)
108
+ zip_file.write(file_path, arcname)
109
+
110
+ return zip_buffer.getvalue()
111
+
112
  # Streamlit app
113
  def main():
114
  st.title("Human or Alien Identification")
 
119
 
120
  - **Identify Image:** Upload an image and classify it as "Human" or "Alien." The classifications you save will be added to the training data.
121
  - **Train Model:** Review and manage the images already classified as "Human" or "Alien." Upload additional images to improve the training dataset.
122
+ - **Download Sample Dataset:** Download a pre-structured dataset to use for training and classification.
123
  """
124
  )
125
 
126
+ tab1, tab2, tab3 = st.tabs(["Identify Image", "Train Model", "Download Sample Dataset"])
127
 
128
  with tab1:
129
  st.header("Identify Image")
 
226
  else:
227
  st.warning("No alien images found for training.")
228
 
229
+ with tab3:
230
+ st.header("Download Sample Dataset")
231
+
232
+ if st.button("Download Sample Dataset"):
233
+ sample_dataset = create_sample_dataset()
234
+ st.download_button(
235
+ label="Click to Download",
236
+ data=sample_dataset,
237
+ file_name="sample_dataset.zip",
238
+ mime="application/zip"
239
+ )
240
+
241
  if __name__ == "__main__":
242
  main()
sample_dataset/Alien/94.jpg ADDED
sample_dataset/Alien/95.jpg ADDED
sample_dataset/Alien/96.jpg ADDED
sample_dataset/Alien/alien_1.jpg ADDED
sample_dataset/Alien/alien_2.jpg ADDED
sample_dataset/Alien/alien_3.jpg ADDED
sample_dataset/HUMAN/human_1.jpg ADDED
sample_dataset/HUMAN/human_2.jpg ADDED
sample_dataset/HUMAN/human_3.jpg ADDED
sample_dataset/HUMAN/tamil-woman-close-up-of-happy-face-ECNPHF.jpg ADDED
sample_dataset/HUMAN/ung-cheerful-beautiful-girl-long-hair-casual-shirt-smiling-looking-172927805.jpg ADDED
sample_dataset/HUMAN/vladimir-putin-smiling-face-png-11646750895sk2xyu6id1.png ADDED
sample_dataset/HUMAN/web3-happy-people-outside-smile-sun-nature-eduardo-dutra-620857-unsplash.jpg ADDED