atiwari751 commited on
Commit
4d89502
·
1 Parent(s): a66ef08

Updated with Hugging Face app

Browse files
Files changed (1) hide show
  1. app.py +6 -4
app.py CHANGED
@@ -36,15 +36,17 @@ def predict(image):
36
  probabilities = torch.nn.functional.softmax(outputs, dim=1)[0]
37
  top5_prob, top5_catid = torch.topk(probabilities, 5)
38
 
39
- results = []
40
  for i in range(top5_prob.size(0)):
41
  class_index = top5_catid[i].item()
42
  class_label = class_labels.get(class_index, "Unknown")
43
  prob = top5_prob[i].item() * 100
44
- results.append(f"{class_label}: {prob:.2f}%")
 
 
45
 
46
- return "\n".join(results)
47
 
48
  # Create the Gradio interface
49
- iface = gr.Interface(fn=predict, inputs=gr.Image(type="pil"), outputs="text", title="ResNet 50 Image Classifier")
50
  iface.launch()
 
36
  probabilities = torch.nn.functional.softmax(outputs, dim=1)[0]
37
  top5_prob, top5_catid = torch.topk(probabilities, 5)
38
 
39
+ results = "<div style='font-family: Arial, sans-serif; font-size: 18px;'>"
40
  for i in range(top5_prob.size(0)):
41
  class_index = top5_catid[i].item()
42
  class_label = class_labels.get(class_index, "Unknown")
43
  prob = top5_prob[i].item() * 100
44
+ results += f"<div style='margin-bottom: 10px;'><strong>{class_label}</strong>: {prob:.2f}%</div>"
45
+ results += f"<div style='background-color: #ddd; width: 100%;'><div style='width: {prob}%; background-color: #4CAF50; height: 20px;'></div></div>"
46
+ results += "</div>"
47
 
48
+ return results
49
 
50
  # Create the Gradio interface
51
+ iface = gr.Interface(fn=predict, inputs=gr.Image(type="pil"), outputs="html", title="ResNet 50 Image Classifier")
52
  iface.launch()