File size: 919 Bytes
b2adcbf
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import openai

# Use Together AI endpoint and your API key
client = openai.OpenAI(
    api_key="52aa1e19fe8427296ae1347416cb22784a0cfe5c9d4324b779f638031a567a30",
    base_url="https://api.together.xyz/v1"
)

def generate_explanation(label, confidence):
    prompt = f"""

    The X-ray result indicates: {label} with {confidence}% confidence.



    Please explain:

    - What is {label}?

    - What are its common symptoms?

    - 2-3 useful precautions

    - Whether the patient should consult a doctor

    """

    try:
        response = client.chat.completions.create(
            model="mistralai/Mistral-7B-Instruct-v0.1",
            messages=[{"role": "user", "content": prompt}],
            max_tokens=500,
            temperature=0.7,
        )
        return response.choices[0].message.content
    except Exception as e:
        return f"❌ Failed to generate explanation: {e}"