user-agent commited on
Commit
35b0d39
·
verified ·
1 Parent(s): 9b67e53

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -2
app.py CHANGED
@@ -52,8 +52,12 @@ def predict_tags(image_url, threshold=0.5):
52
  def gradio_predict(url, threshold):
53
  tags, error = predict_tags(url, threshold)
54
  if error:
55
- return error
56
- return "\n".join([f"{tag}: {score:.2f}" for tag, score in tags])
 
 
 
 
57
 
58
  demo = gr.Interface(
59
  fn=gradio_predict,
 
52
  def gradio_predict(url, threshold):
53
  tags, error = predict_tags(url, threshold)
54
  if error:
55
+ return {"error": error}
56
+ if not tags:
57
+ return {"error": "No tags above threshold."}
58
+
59
+ top_tag, top_score = tags[0]
60
+ return {"tag_name": top_tag, "tag_score": round(top_score, 4)}
61
 
62
  demo = gr.Interface(
63
  fn=gradio_predict,