Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -12,9 +12,9 @@ genai.configure(api_key=GOOGLE_API_KEY)
|
|
| 12 |
# Use Gemini 1.5 Flash model
|
| 13 |
model = genai.GenerativeModel('gemini-1.5-flash-latest')
|
| 14 |
|
| 15 |
-
def predict_tumor(headaches, neurological_symptoms, family_history, weight_loss, fatigue):
|
| 16 |
# Validate inputs
|
| 17 |
-
inputs = [headaches, neurological_symptoms, family_history, weight_loss, fatigue]
|
| 18 |
if not all(inputs):
|
| 19 |
return "Error: Please provide answers to all questions."
|
| 20 |
|
|
@@ -25,10 +25,15 @@ def predict_tumor(headaches, neurological_symptoms, family_history, weight_loss,
|
|
| 25 |
Family History of Cancer/Tumors: {family_history}
|
| 26 |
Unexplained Weight Loss: {weight_loss}
|
| 27 |
Persistent Fatigue: {fatigue}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
"""
|
| 29 |
|
| 30 |
prompt = f"""
|
| 31 |
-
You are a health assistant predicting the likelihood of a tumor (e.g., brain tumor) based on user responses to
|
| 32 |
Classify the risk as "Tumor Detected" or "No Tumor" and provide a brief reason for your classification.
|
| 33 |
Return the response in this format:
|
| 34 |
|
|
@@ -42,8 +47,13 @@ def predict_tumor(headaches, neurological_symptoms, family_history, weight_loss,
|
|
| 42 |
Family History of Cancer/Tumors: Yes
|
| 43 |
Unexplained Weight Loss: Yes
|
| 44 |
Persistent Fatigue: Yes
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 45 |
Prediction: Tumor Detected
|
| 46 |
-
Reason:
|
| 47 |
|
| 48 |
User Data:
|
| 49 |
Persistent Headaches: None
|
|
@@ -51,8 +61,13 @@ def predict_tumor(headaches, neurological_symptoms, family_history, weight_loss,
|
|
| 51 |
Family History of Cancer/Tumors: No
|
| 52 |
Unexplained Weight Loss: No
|
| 53 |
Persistent Fatigue: No
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 54 |
Prediction: No Tumor
|
| 55 |
-
Reason: The absence of headaches, neurological
|
| 56 |
|
| 57 |
User Data:
|
| 58 |
Persistent Headaches: Occasional and mild
|
|
@@ -60,8 +75,13 @@ def predict_tumor(headaches, neurological_symptoms, family_history, weight_loss,
|
|
| 60 |
Family History of Cancer/Tumors: Yes
|
| 61 |
Unexplained Weight Loss: No
|
| 62 |
Persistent Fatigue: Yes
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 63 |
Prediction: No Tumor
|
| 64 |
-
Reason: Mild headaches,
|
| 65 |
|
| 66 |
User Data:
|
| 67 |
{user_data}
|
|
@@ -83,11 +103,16 @@ iface = gr.Interface(
|
|
| 83 |
gr.Dropdown(choices=["Yes", "No"], label="2. Do you have neurological symptoms (e.g., seizures, vision/hearing changes, cognitive issues)?"),
|
| 84 |
gr.Dropdown(choices=["Yes", "No"], label="3. Do you have a family history of cancer or tumors?"),
|
| 85 |
gr.Dropdown(choices=["Yes", "No"], label="4. Have you experienced unexplained weight loss?"),
|
| 86 |
-
gr.Dropdown(choices=["Yes", "No"], label="5. Do you experience persistent fatigue or weakness?")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 87 |
],
|
| 88 |
outputs=gr.Textbox(label="Tumor Detection Prediction"),
|
| 89 |
title="Tumor Risk Predictor",
|
| 90 |
-
description="Answer
|
| 91 |
)
|
| 92 |
|
| 93 |
# Launch the interface
|
|
|
|
| 12 |
# Use Gemini 1.5 Flash model
|
| 13 |
model = genai.GenerativeModel('gemini-1.5-flash-latest')
|
| 14 |
|
| 15 |
+
def predict_tumor(headaches, neurological_symptoms, family_history, weight_loss, fatigue, nausea, balance_issues, speech_difficulties, mood_changes, radiation_exposure):
|
| 16 |
# Validate inputs
|
| 17 |
+
inputs = [headaches, neurological_symptoms, family_history, weight_loss, fatigue, nausea, balance_issues, speech_difficulties, mood_changes, radiation_exposure]
|
| 18 |
if not all(inputs):
|
| 19 |
return "Error: Please provide answers to all questions."
|
| 20 |
|
|
|
|
| 25 |
Family History of Cancer/Tumors: {family_history}
|
| 26 |
Unexplained Weight Loss: {weight_loss}
|
| 27 |
Persistent Fatigue: {fatigue}
|
| 28 |
+
Unexplained Nausea or Vomiting: {nausea}
|
| 29 |
+
Balance or Coordination Issues: {balance_issues}
|
| 30 |
+
Speech Difficulties: {speech_difficulties}
|
| 31 |
+
Personality or Mood Changes: {mood_changes}
|
| 32 |
+
History of Radiation Exposure: {radiation_exposure}
|
| 33 |
"""
|
| 34 |
|
| 35 |
prompt = f"""
|
| 36 |
+
You are a health assistant predicting the likelihood of a tumor (e.g., brain tumor) based on user responses to 10 health questions.
|
| 37 |
Classify the risk as "Tumor Detected" or "No Tumor" and provide a brief reason for your classification.
|
| 38 |
Return the response in this format:
|
| 39 |
|
|
|
|
| 47 |
Family History of Cancer/Tumors: Yes
|
| 48 |
Unexplained Weight Loss: Yes
|
| 49 |
Persistent Fatigue: Yes
|
| 50 |
+
Unexplained Nausea or Vomiting: Yes
|
| 51 |
+
Balance or Coordination Issues: Yes
|
| 52 |
+
Speech Difficulties: Yes
|
| 53 |
+
Personality or Mood Changes: Yes
|
| 54 |
+
History of Radiation Exposure: Yes
|
| 55 |
Prediction: Tumor Detected
|
| 56 |
+
Reason: Multiple symptoms including frequent severe headaches, neurological symptoms, nausea, balance issues, speech difficulties, mood changes, along with family history, weight loss, fatigue, and radiation exposure, strongly suggest a potential tumor.
|
| 57 |
|
| 58 |
User Data:
|
| 59 |
Persistent Headaches: None
|
|
|
|
| 61 |
Family History of Cancer/Tumors: No
|
| 62 |
Unexplained Weight Loss: No
|
| 63 |
Persistent Fatigue: No
|
| 64 |
+
Unexplained Nausea or Vomiting: No
|
| 65 |
+
Balance or Coordination Issues: No
|
| 66 |
+
Speech Difficulties: No
|
| 67 |
+
Personality or Mood Changes: No
|
| 68 |
+
History of Radiation Exposure: No
|
| 69 |
Prediction: No Tumor
|
| 70 |
+
Reason: The absence of symptoms such as headaches, neurological issues, nausea, balance problems, speech difficulties, mood changes, and risk factors like family history or radiation exposure suggests a low likelihood of a tumor.
|
| 71 |
|
| 72 |
User Data:
|
| 73 |
Persistent Headaches: Occasional and mild
|
|
|
|
| 75 |
Family History of Cancer/Tumors: Yes
|
| 76 |
Unexplained Weight Loss: No
|
| 77 |
Persistent Fatigue: Yes
|
| 78 |
+
Unexplained Nausea or Vomiting: No
|
| 79 |
+
Balance or Coordination Issues: No
|
| 80 |
+
Speech Difficulties: No
|
| 81 |
+
Personality or Mood Changes: No
|
| 82 |
+
History of Radiation Exposure: No
|
| 83 |
Prediction: No Tumor
|
| 84 |
+
Reason: Mild headaches, fatigue, and family history alone, without other significant symptoms like neurological issues or nausea, suggest a low likelihood of a tumor.
|
| 85 |
|
| 86 |
User Data:
|
| 87 |
{user_data}
|
|
|
|
| 103 |
gr.Dropdown(choices=["Yes", "No"], label="2. Do you have neurological symptoms (e.g., seizures, vision/hearing changes, cognitive issues)?"),
|
| 104 |
gr.Dropdown(choices=["Yes", "No"], label="3. Do you have a family history of cancer or tumors?"),
|
| 105 |
gr.Dropdown(choices=["Yes", "No"], label="4. Have you experienced unexplained weight loss?"),
|
| 106 |
+
gr.Dropdown(choices=["Yes", "No"], label="5. Do you experience persistent fatigue or weakness?"),
|
| 107 |
+
gr.Dropdown(choices=["Yes", "No"], label="6. Do you experience unexplained nausea or vomiting?"),
|
| 108 |
+
gr.Dropdown(choices=["Yes", "No"], label="7. Do you have balance or coordination issues (e.g., difficulty walking)?"),
|
| 109 |
+
gr.Dropdown(choices=["Yes", "No"], label="8. Do you have speech difficulties (e.g., slurred speech)?"),
|
| 110 |
+
gr.Dropdown(choices=["Yes", "No"], label="9. Have you noticed personality or mood changes?"),
|
| 111 |
+
gr.Dropdown(choices=["Yes", "No"], label="10. Have you been exposed to significant radiation (e.g., medical treatments, environmental)?")
|
| 112 |
],
|
| 113 |
outputs=gr.Textbox(label="Tumor Detection Prediction"),
|
| 114 |
title="Tumor Risk Predictor",
|
| 115 |
+
description="Answer 10 health questions to predict the likelihood of a tumor using the Gemini API. Set your GOOGLE_API_KEY in the Hugging Face Space settings. Note: This is for demonstration purposes only and not a clinical tool."
|
| 116 |
)
|
| 117 |
|
| 118 |
# Launch the interface
|