Spaces:
Sleeping
Sleeping
| 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}" | |