Awashati commited on
Commit
4101a8a
·
verified ·
1 Parent(s): 6fdad4a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -2
app.py CHANGED
@@ -1,4 +1,3 @@
1
-
2
  import gradio as gr
3
  import requests
4
  import base64
@@ -7,7 +6,12 @@ import json
7
  API_KEY = "GCT8F6KhPYNUvBvh7X617OzRF9zXUNhwvWu4NyWxhklqU75S8d"
8
  API_URL = "https://plant.id/api/v3/identification"
9
 
 
 
 
10
  def identify_plant(image):
 
 
11
  try:
12
  with open(image, "rb") as img_file:
13
  img_data = base64.b64encode(img_file.read()).decode("utf-8")
@@ -38,7 +42,17 @@ def identify_plant(image):
38
  prob = top.get("probability", 0.0)
39
  desc = top.get("details", {}).get("description", {}).get("value", "No description available.")
40
 
41
- return f"""\n🌿 **Plant:** {name}\n📊 **Confidence:** {prob * 100:.2f}%\n📖 {desc}"""
 
 
 
 
 
 
 
 
 
 
42
  except Exception as e:
43
  return f"💥 Error: {str(e)}"
44
 
 
 
1
  import gradio as gr
2
  import requests
3
  import base64
 
6
  API_KEY = "GCT8F6KhPYNUvBvh7X617OzRF9zXUNhwvWu4NyWxhklqU75S8d"
7
  API_URL = "https://plant.id/api/v3/identification"
8
 
9
+ # Tracks the last prediction to detect repetition
10
+ last_prediction = {"name": None}
11
+
12
  def identify_plant(image):
13
+ global last_prediction
14
+
15
  try:
16
  with open(image, "rb") as img_file:
17
  img_data = base64.b64encode(img_file.read()).decode("utf-8")
 
42
  prob = top.get("probability", 0.0)
43
  desc = top.get("details", {}).get("description", {}).get("value", "No description available.")
44
 
45
+ warning = ""
46
+ if last_prediction["name"] == name:
47
+ warning = "\n⚠️ Same result as last time. This may indicate repetition. Try a different photo or angle."
48
+
49
+ last_prediction["name"] = name
50
+
51
+ return f"""
52
+ 🌿 **Plant:** {name}
53
+ 📊 **Confidence:** {prob * 100:.2f}%
54
+ 📖 {desc}{warning}
55
+ """
56
  except Exception as e:
57
  return f"💥 Error: {str(e)}"
58