Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,90 +1,61 @@
|
|
| 1 |
from flask import Flask, request, jsonify
|
| 2 |
from flask_cors import CORS
|
| 3 |
-
import json
|
| 4 |
from deep_translator import GoogleTranslator
|
|
|
|
| 5 |
|
| 6 |
app = Flask(__name__)
|
| 7 |
CORS(app)
|
| 8 |
|
| 9 |
-
# Load disease data
|
| 10 |
with open("diseases.json", "r", encoding="utf-8") as f:
|
| 11 |
disease_data = json.load(f)
|
| 12 |
|
| 13 |
-
DISEASE_ALIASES = {
|
| 14 |
-
"ringworm": "Tinea Ringworm Candidiasis",
|
| 15 |
-
"fungal infection": "Tinea Ringworm Candidiasis",
|
| 16 |
-
"eczema": "eczema",
|
| 17 |
-
"warts": "Warts Molluscum Viral Infections",
|
| 18 |
-
"melanoma": "melanoma",
|
| 19 |
-
"nevus": "nevus"
|
| 20 |
-
}
|
| 21 |
-
|
| 22 |
-
SUPPORTED_LANGUAGES = {
|
| 23 |
-
"en": "English",
|
| 24 |
-
"ta": "Tamil",
|
| 25 |
-
"hi": "Hindi",
|
| 26 |
-
"te": "Telugu",
|
| 27 |
-
"ml": "Malayalam",
|
| 28 |
-
"kn": "Kannada",
|
| 29 |
-
"bn": "Bengali",
|
| 30 |
-
"mr": "Marathi",
|
| 31 |
-
"ur": "Urdu",
|
| 32 |
-
"es": "Spanish"
|
| 33 |
-
}
|
| 34 |
-
|
| 35 |
-
@app.route("/")
|
| 36 |
-
def home():
|
| 37 |
-
return "Chatbot backend running"
|
| 38 |
-
|
| 39 |
@app.route("/chat", methods=["POST"])
|
| 40 |
def chat():
|
| 41 |
data = request.json
|
| 42 |
|
| 43 |
-
|
| 44 |
-
|
| 45 |
|
| 46 |
-
print("LANG RECEIVED
|
| 47 |
|
| 48 |
-
|
| 49 |
-
|
|
|
|
|
|
|
|
|
|
| 50 |
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
translated_input = GoogleTranslator(
|
| 54 |
-
source=user_lang, target="en"
|
| 55 |
-
).translate(user_input)
|
| 56 |
-
else:
|
| 57 |
-
translated_input = user_input
|
| 58 |
|
| 59 |
-
|
| 60 |
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
|
| 67 |
-
|
| 68 |
-
|
| 69 |
|
| 70 |
-
|
|
|
|
| 71 |
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
f"Description:\n{info['description']}\n\n"
|
| 75 |
-
f"Symptoms:\n➤ " + "\n➤ ".join(info["symptoms"]) + "\n\n"
|
| 76 |
-
f"Precautions:\n➤ " + "\n➤ ".join(info["precautions"]) + "\n\n"
|
| 77 |
-
"⚠ Educational purpose only"
|
| 78 |
-
)
|
| 79 |
|
| 80 |
-
if
|
| 81 |
-
|
| 82 |
-
source="en", target=
|
| 83 |
-
).translate(
|
| 84 |
else:
|
| 85 |
-
|
| 86 |
|
| 87 |
-
return jsonify({"reply":
|
|
|
|
|
|
|
|
|
|
|
|
|
| 88 |
|
| 89 |
if __name__ == "__main__":
|
| 90 |
app.run(host="0.0.0.0", port=7860)
|
|
|
|
| 1 |
from flask import Flask, request, jsonify
|
| 2 |
from flask_cors import CORS
|
|
|
|
| 3 |
from deep_translator import GoogleTranslator
|
| 4 |
+
import json
|
| 5 |
|
| 6 |
app = Flask(__name__)
|
| 7 |
CORS(app)
|
| 8 |
|
|
|
|
| 9 |
with open("diseases.json", "r", encoding="utf-8") as f:
|
| 10 |
disease_data = json.load(f)
|
| 11 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
@app.route("/chat", methods=["POST"])
|
| 13 |
def chat():
|
| 14 |
data = request.json
|
| 15 |
|
| 16 |
+
message = data.get("message", "")
|
| 17 |
+
language = data.get("language", "en")
|
| 18 |
|
| 19 |
+
print("LANG RECEIVED:", language) # 👈 DEBUG
|
| 20 |
|
| 21 |
+
disease = None
|
| 22 |
+
for d in disease_data:
|
| 23 |
+
if d.lower() in message.lower():
|
| 24 |
+
disease = d
|
| 25 |
+
break
|
| 26 |
|
| 27 |
+
if not disease:
|
| 28 |
+
return jsonify({"reply": "Disease not found"})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
|
| 30 |
+
info = disease_data[disease]
|
| 31 |
|
| 32 |
+
english_reply = f"""
|
| 33 |
+
Disease: {disease}
|
| 34 |
+
|
| 35 |
+
Description:
|
| 36 |
+
{info['description']}
|
| 37 |
|
| 38 |
+
Symptoms:
|
| 39 |
+
- """ + "\n- ".join(info["symptoms"]) + """
|
| 40 |
|
| 41 |
+
Precautions:
|
| 42 |
+
- """ + "\n- ".join(info["precautions"]) + """
|
| 43 |
|
| 44 |
+
⚠ Consult dermatologist
|
| 45 |
+
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 46 |
|
| 47 |
+
if language != "en":
|
| 48 |
+
reply = GoogleTranslator(
|
| 49 |
+
source="en", target=language
|
| 50 |
+
).translate(english_reply)
|
| 51 |
else:
|
| 52 |
+
reply = english_reply
|
| 53 |
|
| 54 |
+
return jsonify({"reply": reply})
|
| 55 |
+
|
| 56 |
+
@app.route("/")
|
| 57 |
+
def home():
|
| 58 |
+
return "Chatbot running"
|
| 59 |
|
| 60 |
if __name__ == "__main__":
|
| 61 |
app.run(host="0.0.0.0", port=7860)
|