Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -8,6 +8,10 @@ from PIL import Image
|
|
| 8 |
import requests
|
| 9 |
import os
|
| 10 |
from io import BytesIO
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
|
| 12 |
# Define the number of classes
|
| 13 |
num_classes = 2
|
|
@@ -66,17 +70,25 @@ def predict_from_image(image):
|
|
| 66 |
def process_file_path(file_path_input):
|
| 67 |
global file_path
|
| 68 |
file_path = file_path_input # Store the file path
|
|
|
|
|
|
|
|
|
|
| 69 |
if not os.path.exists(file_path):
|
|
|
|
| 70 |
return {"error": f"File not found at {file_path}"}
|
|
|
|
| 71 |
image = Image.open(file_path)
|
|
|
|
| 72 |
return predict_from_image(image)
|
| 73 |
|
| 74 |
# Function to fetch the result (for the GET request)
|
| 75 |
def fetch_result():
|
| 76 |
if file_path:
|
| 77 |
image = Image.open(file_path)
|
|
|
|
| 78 |
return predict_from_image(image)
|
| 79 |
else:
|
|
|
|
| 80 |
return {"error": "No file path available. Please send a POST request with a file path first."}
|
| 81 |
|
| 82 |
# Gradio interface
|
|
|
|
| 8 |
import requests
|
| 9 |
import os
|
| 10 |
from io import BytesIO
|
| 11 |
+
import logging
|
| 12 |
+
|
| 13 |
+
# Set up basic logging
|
| 14 |
+
logging.basicConfig(level=logging.INFO)
|
| 15 |
|
| 16 |
# Define the number of classes
|
| 17 |
num_classes = 2
|
|
|
|
| 70 |
def process_file_path(file_path_input):
|
| 71 |
global file_path
|
| 72 |
file_path = file_path_input # Store the file path
|
| 73 |
+
|
| 74 |
+
logging.info(f"Received file path: {file_path}")
|
| 75 |
+
|
| 76 |
if not os.path.exists(file_path):
|
| 77 |
+
logging.error(f"File not found at {file_path}")
|
| 78 |
return {"error": f"File not found at {file_path}"}
|
| 79 |
+
|
| 80 |
image = Image.open(file_path)
|
| 81 |
+
logging.info(f"Processing image from path: {file_path}")
|
| 82 |
return predict_from_image(image)
|
| 83 |
|
| 84 |
# Function to fetch the result (for the GET request)
|
| 85 |
def fetch_result():
|
| 86 |
if file_path:
|
| 87 |
image = Image.open(file_path)
|
| 88 |
+
logging.info(f"Making prediction for image at path: {file_path}")
|
| 89 |
return predict_from_image(image)
|
| 90 |
else:
|
| 91 |
+
logging.warning("No file path available. Please send a POST request with a file path first.")
|
| 92 |
return {"error": "No file path available. Please send a POST request with a file path first."}
|
| 93 |
|
| 94 |
# Gradio interface
|