Spaces:
Sleeping
Sleeping
Upload app.py
Browse files
app.py
CHANGED
@@ -70,18 +70,18 @@ net.eval()
|
|
70 |
path = "uploads" # Define path for uploads
|
71 |
os.makedirs(path, exist_ok=True) # Ensure directory exists
|
72 |
|
73 |
-
def predict_image(
|
74 |
-
img_path = os.path.join(path, img.name)
|
75 |
-
img.save(img_path)
|
76 |
|
77 |
-
image_tensor = preprocess_image(
|
78 |
pred = net(image_tensor)
|
79 |
y_pred = 1 - nn.functional.softmax(pred, dim=1).data.cpu().numpy()[:, 0]
|
80 |
return float(y_pred.item())
|
81 |
|
82 |
iface = gr.Interface(
|
83 |
fn=predict_image,
|
84 |
-
inputs=gr.Image(type="
|
85 |
outputs="number",
|
86 |
title="Image Prediction App",
|
87 |
description="Upload an image and get a model prediction."
|
|
|
70 |
path = "uploads" # Define path for uploads
|
71 |
os.makedirs(path, exist_ok=True) # Ensure directory exists
|
72 |
|
73 |
+
def predict_image(path):
|
74 |
+
# img_path = os.path.join(path, img.name)
|
75 |
+
# img.save(img_path)
|
76 |
|
77 |
+
image_tensor = preprocess_image(path, get_test_transforms(224))
|
78 |
pred = net(image_tensor)
|
79 |
y_pred = 1 - nn.functional.softmax(pred, dim=1).data.cpu().numpy()[:, 0]
|
80 |
return float(y_pred.item())
|
81 |
|
82 |
iface = gr.Interface(
|
83 |
fn=predict_image,
|
84 |
+
inputs=gr.Image(type="filepath"),
|
85 |
outputs="number",
|
86 |
title="Image Prediction App",
|
87 |
description="Upload an image and get a model prediction."
|