Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -3,6 +3,9 @@ from pytorch_tabular.tabular_datamodule import TabularDatamodule
|
|
| 3 |
from streamlit_option_menu import option_menu
|
| 4 |
import google.generativeai as genai
|
| 5 |
import os
|
|
|
|
|
|
|
|
|
|
| 6 |
|
| 7 |
genai.configure(api_key=os.getenv("GEMINI_API_KEY"))
|
| 8 |
|
|
@@ -46,6 +49,26 @@ dm._inferred_config = SimpleNamespace(output_cardinality=[2])
|
|
| 46 |
with open("FTTransformerModel/threshold.json", "r") as f:
|
| 47 |
threshold = json.load(f)["threshold"]
|
| 48 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 49 |
|
| 50 |
# User input
|
| 51 |
with st.sidebar:
|
|
@@ -129,14 +152,22 @@ if selected == "Prediction Tool":
|
|
| 129 |
|
| 130 |
model_gemini = genai.GenerativeModel(
|
| 131 |
model_name="models/gemini-2.0-flash",
|
| 132 |
-
generation_config=genai.types.GenerationConfig(
|
| 133 |
-
temperature=0.2
|
| 134 |
-
)
|
| 135 |
)
|
| 136 |
response = model_gemini.generate_content(prompt)
|
| 137 |
-
|
| 138 |
-
|
| 139 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 140 |
|
| 141 |
|
| 142 |
|
|
|
|
| 3 |
from streamlit_option_menu import option_menu
|
| 4 |
import google.generativeai as genai
|
| 5 |
import os
|
| 6 |
+
from googletrans import Translator
|
| 7 |
+
|
| 8 |
+
translator = Translator()
|
| 9 |
|
| 10 |
genai.configure(api_key=os.getenv("GEMINI_API_KEY"))
|
| 11 |
|
|
|
|
| 49 |
with open("FTTransformerModel/threshold.json", "r") as f:
|
| 50 |
threshold = json.load(f)["threshold"]
|
| 51 |
|
| 52 |
+
# Sidebar: language selection
|
| 53 |
+
with st.sidebar:
|
| 54 |
+
lang = st.selectbox("🌐 Language / 語言 / Bahasa", ["English", "中文", "Malay"])
|
| 55 |
+
|
| 56 |
+
# Label dictionary for multilingual UI
|
| 57 |
+
LABELS = {
|
| 58 |
+
"age": {"English": "Patient's Age", "中文": "年齡", "Malay": "Umur"},
|
| 59 |
+
"height": {"English": "Patient's Height (cm)", "中文": "身高 (cm)", "Malay": "Tinggi (cm)"},
|
| 60 |
+
"weight": {"English": "Patient's Weight (kg)", "中文": "體重 (kg)", "Malay": "Berat (kg)"},
|
| 61 |
+
"systolic": {"English": "Patient's Systolic BP", "中文": "收縮壓", "Malay": "Tekanan Sistolik"},
|
| 62 |
+
"diastolic": {"English": "Patient's Diastolic BP", "中文": "舒张壓", "Malay": "Tekanan Diastolik"},
|
| 63 |
+
"cholesterol": {"English": "Patient's Cholesterol", "中文": "膽固醇", "Malay": "Kolesterol"},
|
| 64 |
+
"gluc": {"English": "Patient's Glucose", "中文": "血糖", "Malay": "Glukosa"},
|
| 65 |
+
"gender": {"English": "Patient's Gender", "中文": "性別", "Malay": "Jantina"},
|
| 66 |
+
"smoke": {"English": "Do patient smoke?", "中文": "是否吸煙?", "Malay": "Adakah merokok?"},
|
| 67 |
+
"alco": {"English": "Do patient drink alcohol?", "中文": "是否喝酒?", "Malay": "Adakah minum alkohol?"},
|
| 68 |
+
"active": {"English": "Are patient physically active?", "中文": "是否練習運動?", "Malay": "Adakah aktif secara fizikal?"},
|
| 69 |
+
"predict": {"English": "Predict CVD Risk", "中文": "預測心血管風險", "Malay": "Ramalkan Risiko CVD"}
|
| 70 |
+
}
|
| 71 |
+
|
| 72 |
|
| 73 |
# User input
|
| 74 |
with st.sidebar:
|
|
|
|
| 152 |
|
| 153 |
model_gemini = genai.GenerativeModel(
|
| 154 |
model_name="models/gemini-2.0-flash",
|
| 155 |
+
generation_config=genai.types.GenerationConfig(temperature=0.2)
|
|
|
|
|
|
|
| 156 |
)
|
| 157 |
response = model_gemini.generate_content(prompt)
|
| 158 |
+
original_text = response.text
|
| 159 |
+
|
| 160 |
+
if lang == "中文":
|
| 161 |
+
translated = translator.translate(original_text, dest="zh-tw").text
|
| 162 |
+
st.markdown("### 🔹 AI 健康建議(繁體中文)")
|
| 163 |
+
st.write(translated)
|
| 164 |
+
elif lang == "Malay":
|
| 165 |
+
translated = translator.translate(original_text, dest="ms").text
|
| 166 |
+
st.markdown("### 🔹 Nasihat Kesihatan AI (Bahasa Melayu)")
|
| 167 |
+
st.write(translated)
|
| 168 |
+
else:
|
| 169 |
+
st.markdown("### 🔹 AI Health Advice")
|
| 170 |
+
st.write(original_text)
|
| 171 |
|
| 172 |
|
| 173 |
|