datdevsteve commited on
Commit
7e5e561
·
verified ·
1 Parent(s): df33ce6

fixed missing instantiation code for predict method

Browse files
Files changed (1) hide show
  1. agent/image_symptom_tool.py +19 -14
agent/image_symptom_tool.py CHANGED
@@ -2,26 +2,31 @@ from langchain_core.tools import tool
2
  from gradio_client import Client
3
  import json
4
 
 
 
 
 
 
5
  @tool
6
- def analyze_symptom_image(img_url: str) -> str:
7
  """
8
  Calls Nivra Vision Diagnosis Gradio Space using image URL
 
9
  """
10
  try:
11
- result = Client.predict(
12
- image_upload=None, # Explicitly None
13
- image_url=img_url,
14
  top_k=2,
15
  api_name="/predict"
16
  )
17
- md_output = result[0]
 
18
  result_json = json.loads(result[1])
19
- return f"""
20
- [SYMPTOM IMAGE ANALYSIS - SUCCESS]
21
- {result_json}
22
- """
23
- except Exception as e:
24
- return f"""
25
- [SYMPTOM IMAGE ANALYSIS - ERROR]
26
- {str(e)}
27
- """
 
2
  from gradio_client import Client
3
  import json
4
 
5
+ # Instantiate client once (efficient & stable)
6
+ VISION_SPACE_URL = "https://datdevsteve-nivra-vision-diagnosis-v2.hf.space/"
7
+ vision_client = Client(VISION_SPACE_URL)
8
+
9
+
10
  @tool
11
+ def analyze_symptom_image(image_url: str) -> str:
12
  """
13
  Calls Nivra Vision Diagnosis Gradio Space using image URL
14
+ Returns structured JSON string.
15
  """
16
  try:
17
+ result = vision_client.predict(
18
+ image_upload=None,
19
+ image_url=image_url,
20
  top_k=2,
21
  api_name="/predict"
22
  )
23
+
24
+ # result is a tuple: (markdown_output, json_string)
25
  result_json = json.loads(result[1])
26
+
27
+ return (
28
+ "[SYMPTOM IMAGE ANALYSIS - SUCCESS]\n"
29
+ + json.dumps(result_json, indent=2)
30
+ )
31
+
32
+ e