Update app.py
Browse files
app.py
CHANGED
@@ -39,12 +39,12 @@ def predict(image):
|
|
39 |
top_probs = top_probs.detach().numpy()[0].tolist() # Convert to list
|
40 |
top_idxs = top_idxs.detach().numpy()[0].tolist() # Convert to list
|
41 |
top_classes = [model.config.id2label[idx] for idx in top_idxs]
|
42 |
-
result = {top_classes[i]: top_probs[i] for i in range(3)}
|
43 |
logging.info("Prediction successful.")
|
44 |
return result
|
45 |
except Exception as e:
|
46 |
logging.error("Error during prediction: %s", e)
|
47 |
-
return str(e)
|
48 |
|
49 |
# Create the Gradio interface
|
50 |
iface = gr.Interface(
|
|
|
39 |
top_probs = top_probs.detach().numpy()[0].tolist() # Convert to list
|
40 |
top_idxs = top_idxs.detach().numpy()[0].tolist() # Convert to list
|
41 |
top_classes = [model.config.id2label[idx] for idx in top_idxs]
|
42 |
+
result = {top_classes[i]: float(top_probs[i]) for i in range(3)}
|
43 |
logging.info("Prediction successful.")
|
44 |
return result
|
45 |
except Exception as e:
|
46 |
logging.error("Error during prediction: %s", e)
|
47 |
+
return {"error": str(e)}
|
48 |
|
49 |
# Create the Gradio interface
|
50 |
iface = gr.Interface(
|