Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -73,7 +73,7 @@ def genus_classify_images(files):
|
|
| 73 |
results = ""
|
| 74 |
predict = []
|
| 75 |
for i, file_path in enumerate(files):
|
| 76 |
-
print(f'\ngenus_classify_image {i}: {file_path.name} \n')
|
| 77 |
try:
|
| 78 |
inp = tf.keras.preprocessing.image.load_img(file_path.name, target_size=(224, 224))
|
| 79 |
inp = tf.keras.preprocessing.image.img_to_array(inp)
|
|
@@ -120,7 +120,7 @@ def Aspergillus_Detect():
|
|
| 120 |
# Construct the command to run the detect.py script
|
| 121 |
command = [
|
| 122 |
"python",
|
| 123 |
-
"yolov7_environment_data/yolov7/detect.py",
|
| 124 |
"--source",
|
| 125 |
test_path,
|
| 126 |
"--weights",
|
|
@@ -203,9 +203,9 @@ def Aspergillus_Detect():
|
|
| 203 |
|
| 204 |
def classify_images(files):
|
| 205 |
predict, result1 = genus_classify_images(files)
|
| 206 |
-
|
| 207 |
-
|
| 208 |
-
|
| 209 |
return result1
|
| 210 |
|
| 211 |
import shutil
|
|
@@ -253,8 +253,8 @@ def upload_file(files):
|
|
| 253 |
file_path = Path(test_path, file.name.split('/')[-1])
|
| 254 |
print(f'\nupload_file:{file}, {file.name}, {os.path.abspath(file_path)}\n')
|
| 255 |
try:
|
| 256 |
-
|
| 257 |
-
|
| 258 |
|
| 259 |
# # Upload the image to the 'Test' directory
|
| 260 |
# upload_image_path = file.name # Replace with the path of the uploaded image
|
|
@@ -265,20 +265,20 @@ def upload_file(files):
|
|
| 265 |
# else:
|
| 266 |
# print("Could not find the 'Test' directory in the project.")
|
| 267 |
|
| 268 |
-
# Open and read the image file
|
| 269 |
-
upload_image_path = file.name
|
| 270 |
-
with open(upload_image_path, 'rb') as file:
|
| 271 |
-
|
| 272 |
|
| 273 |
-
# Upload the image to the 'Test' subdirectory
|
| 274 |
-
upload_url = f"{api_url}/{upload_image_path.split('/')[-1]}"
|
| 275 |
-
response = requests.put(upload_url, data=image_data)
|
| 276 |
|
| 277 |
-
# Check the response status
|
| 278 |
-
if response.status_code == 200:
|
| 279 |
-
|
| 280 |
-
else:
|
| 281 |
-
|
| 282 |
|
| 283 |
except:
|
| 284 |
print("\nError occurred while copying file.\n")
|
|
|
|
| 73 |
results = ""
|
| 74 |
predict = []
|
| 75 |
for i, file_path in enumerate(files):
|
| 76 |
+
print(f'\ngenus_classify_image {i+1}: {file_path.name} \n')
|
| 77 |
try:
|
| 78 |
inp = tf.keras.preprocessing.image.load_img(file_path.name, target_size=(224, 224))
|
| 79 |
inp = tf.keras.preprocessing.image.img_to_array(inp)
|
|
|
|
| 120 |
# Construct the command to run the detect.py script
|
| 121 |
command = [
|
| 122 |
"python",
|
| 123 |
+
"./yolov7_environment_data/yolov7/detect.py",
|
| 124 |
"--source",
|
| 125 |
test_path,
|
| 126 |
"--weights",
|
|
|
|
| 203 |
|
| 204 |
def classify_images(files):
|
| 205 |
predict, result1 = genus_classify_images(files)
|
| 206 |
+
if predict == 'Aspergillus':
|
| 207 |
+
result2 = Aspergillus_Detect()
|
| 208 |
+
return f'{result1}\n\n{result2}'
|
| 209 |
return result1
|
| 210 |
|
| 211 |
import shutil
|
|
|
|
| 253 |
file_path = Path(test_path, file.name.split('/')[-1])
|
| 254 |
print(f'\nupload_file:{file}, {file.name}, {os.path.abspath(file_path)}\n')
|
| 255 |
try:
|
| 256 |
+
shutil.copy(file.name, file_path)
|
| 257 |
+
print(f"File copied successfully.")
|
| 258 |
|
| 259 |
# # Upload the image to the 'Test' directory
|
| 260 |
# upload_image_path = file.name # Replace with the path of the uploaded image
|
|
|
|
| 265 |
# else:
|
| 266 |
# print("Could not find the 'Test' directory in the project.")
|
| 267 |
|
| 268 |
+
# # Open and read the image file
|
| 269 |
+
# upload_image_path = file.name
|
| 270 |
+
# with open(upload_image_path, 'rb') as file:
|
| 271 |
+
# image_data = file.read()
|
| 272 |
|
| 273 |
+
# # Upload the image to the 'Test' subdirectory
|
| 274 |
+
# upload_url = f"{api_url}/{upload_image_path.split('/')[-1]}"
|
| 275 |
+
# response = requests.put(upload_url, data=image_data)
|
| 276 |
|
| 277 |
+
# # Check the response status
|
| 278 |
+
# if response.status_code == 200:
|
| 279 |
+
# print("Image successfully uploaded to the 'Test' subdirectory.")
|
| 280 |
+
# else:
|
| 281 |
+
# print("Failed to upload the image.")
|
| 282 |
|
| 283 |
except:
|
| 284 |
print("\nError occurred while copying file.\n")
|