Spaces:
Sleeping
Sleeping
fixed missing instantiation code for predict method
Browse files- 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(
|
| 7 |
"""
|
| 8 |
Calls Nivra Vision Diagnosis Gradio Space using image URL
|
|
|
|
| 9 |
"""
|
| 10 |
try:
|
| 11 |
-
result =
|
| 12 |
-
image_upload=None,
|
| 13 |
-
image_url=
|
| 14 |
top_k=2,
|
| 15 |
api_name="/predict"
|
| 16 |
)
|
| 17 |
-
|
|
|
|
| 18 |
result_json = json.loads(result[1])
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 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
|
|
|
|
|
|