Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -65,12 +65,19 @@ def predict(image):
|
|
| 65 |
|
| 66 |
with torch.no_grad(): # Use no_grad context for inference to save memory and computations
|
| 67 |
x = model(x)
|
| 68 |
-
probabilities = torch.nn.functional.softmax(x, dim=1)
|
| 69 |
-
class_id = probabilities.argmax(dim=1).item()
|
|
|
|
|
|
|
| 70 |
|
| 71 |
-
|
| 72 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 73 |
|
| 74 |
# Update Gradio interface
|
| 75 |
-
demo = gr.Interface(fn=predict, inputs="image", outputs="
|
| 76 |
demo.launch()
|
|
|
|
| 65 |
|
| 66 |
with torch.no_grad(): # Use no_grad context for inference to save memory and computations
|
| 67 |
x = model(x)
|
| 68 |
+
probabilities = torch.nn.functional.softmax(x, dim=1)[0]
|
| 69 |
+
#class_id = probabilities.argmax(dim=1).item()
|
| 70 |
+
cat_prob = probabilities[0]
|
| 71 |
+
dog_prob = probabilities[1]
|
| 72 |
|
| 73 |
+
return {
|
| 74 |
+
'cat': cat_prob.item(),
|
| 75 |
+
'dog': dog_prob.item()
|
| 76 |
+
}
|
| 77 |
+
|
| 78 |
+
#classes = ['cat', 'dog']
|
| 79 |
+
#return classes[class_id]
|
| 80 |
|
| 81 |
# Update Gradio interface
|
| 82 |
+
demo = gr.Interface(fn=predict, inputs="image", outputs="label")
|
| 83 |
demo.launch()
|