File size: 950 Bytes
f771f4e
d8bcc32
c0c9e80
f771f4e
7e5e561
 
 
 
 
f771f4e
842c982
f771f4e
d8bcc32
7e5e561
f771f4e
a28c608
7e5e561
 
842c982
c0c9e80
 
d8bcc32
7e5e561
 
c0c9e80
7e5e561
 
 
 
 
 
ea44779
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
from langchain_core.tools import tool
from gradio_client import Client
import json

# Instantiate client once (efficient & stable)
VISION_SPACE_URL = "https://datdevsteve-nivra-vision-diagnosis-v2.hf.space/"
vision_client = Client(VISION_SPACE_URL)


@tool
def analyze_symptom_image(img_url: str) -> str:
    """
    Calls Nivra Vision Diagnosis Gradio Space using image URL
    Returns structured JSON string.
    """
    try:
        result = vision_client.predict(
            image_upload=None,
            image_url=img_url,
            top_k=2,
            api_name="/predict"
        )

        # result is a tuple: (markdown_output, json_string)
        result_json = json.loads(result[1])

        return (
            "[SYMPTOM IMAGE ANALYSIS - SUCCESS]\n"
            + json.dumps(result_json, indent=2)
        )

    except Exception as e:
        return (
            "[SYMPTOM IMAGE ANALYSIS - ERROR]\n"
            + str(e)
        )