import sys import types if 'audioop' not in sys.modules: sys.modules['audioop'] = types.ModuleType('audioop') from flask import Flask, request, jsonify, render_template_string import anthropic import os app = Flask(__name__) client = anthropic.Anthropic(api_key=os.environ.get("ANTHROPIC_API_KEY")) SYSTEM_PROMPT = """You are a medical AI assistant specializing in disease identification and health analysis. When given symptoms, images, or descriptions, you: 1. Analyze the provided information carefully 2. List the most likely conditions/diseases (ranked by likelihood) 3. Explain key symptoms that match each condition 4. Recommend appropriate next steps (see a doctor, urgency level, etc.) 5. Provide general information about each condition IMPORTANT DISCLAIMERS: - Always remind users this is for educational purposes only - Always recommend consulting a qualified healthcare professional - Never provide definitive diagnoses - Be clear about limitations Format your response clearly with sections: ## Possible Conditions ## Symptom Analysis ## Recommended Actions ## Important Disclaimer """ HTML = """ DxAI — Disease Identification
◈ DxAI Diagnostic System v1.0

Disease IdentificationAI-Powered Symptom Analysis

Describe your symptoms or upload an image for AI-assisted disease identification. Powered by Claude — for educational purposes only.

Medical Disclaimer: This tool is for educational and informational purposes only. It does not constitute medical advice, diagnosis, or treatment. Always consult a qualified healthcare professional.
INPUT
Tips for better results:
• Include duration, severity (1–10), and progression
• Mention age, sex, and relevant medical history
• For images: rashes, skin conditions, wounds work best
• Note any medications currently being taken
ANALYSIS OUTPUT
Analysis results will appear here after you submit your symptoms...
◈ EXAMPLE: RESPIRATORY
Dry cough 10 days, 100°F fever, shortness of breath, no appetite, slight chest pain on deep breathing.
◈ EXAMPLE: GASTROINTESTINAL
Nausea after eating, bloating, sharp abdominal pain (upper right), yellow tinge in eyes, fatigue for 3 days.
◈ EXAMPLE: DERMATOLOGY
Red itchy rash spreading from arms to torso, small blisters, started after using new detergent, 5 days ago.
""" @app.route("/") def index(): return render_template_string(HTML) @app.route("/analyze", methods=["POST"]) def analyze(): data = request.json symptoms = data.get("symptoms", "").strip() image_b64 = data.get("image") if not symptoms and not image_b64: return jsonify({"error": "No input provided."}) content = [] if image_b64: content.append({"type": "image", "source": {"type": "base64", "media_type": "image/jpeg", "data": image_b64}}) prompt = "" if symptoms: prompt += f"**Patient Symptoms:**\n{symptoms}\n\n" if image_b64: prompt += "An image has also been provided for visual analysis.\n\n" prompt += "Please analyze and identify possible diseases or conditions." content.append({"type": "text", "text": prompt}) try: response = client.messages.create( model="claude-opus-4-5", max_tokens=1500, system=SYSTEM_PROMPT, messages=[{"role": "user", "content": content}] ) return jsonify({"result": response.content[0].text}) except Exception as e: return jsonify({"error": str(e)}) if __name__ == "__main__": app.run(host="0.0.0.0", port=7860)