Muhammad Abdiel Al Hafiz
commited on
Commit
·
41fecdd
1
Parent(s):
7dc8bac
adjust output for disease explanation
Browse files
app.py
CHANGED
@@ -14,9 +14,15 @@ genai.configure(api_key=api_key)
|
|
14 |
labels = ['cataract', 'diabetic_retinopathy', 'glaucoma', 'normal']
|
15 |
|
16 |
def get_disease_detail(disease_name):
|
17 |
-
prompt =
|
|
|
|
|
|
|
|
|
|
|
|
|
18 |
response = genai.GenerativeModel("gemini-1.5-flash").generate_content(prompt)
|
19 |
-
return response.text
|
20 |
|
21 |
def predict_image(image):
|
22 |
image_resized = image.resize((224, 224))
|
@@ -32,7 +38,15 @@ def predict_image(image):
|
|
32 |
|
33 |
explanation = get_disease_detail(top_label)
|
34 |
|
35 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
36 |
|
37 |
# Example images
|
38 |
example_images = [
|
|
|
14 |
labels = ['cataract', 'diabetic_retinopathy', 'glaucoma', 'normal']
|
15 |
|
16 |
def get_disease_detail(disease_name):
|
17 |
+
prompt = (
|
18 |
+
f"Diagnosis: {disease_name}\n\n"
|
19 |
+
"What is it?\n(Description about {disease_name})\n\n"
|
20 |
+
"What cause it?\n(Explain what causes {disease_name})\n\n"
|
21 |
+
"Suggestion\n(Suggestion to user)\n\n"
|
22 |
+
"Reminder: Always seek professional help, such as a doctor."
|
23 |
+
)
|
24 |
response = genai.GenerativeModel("gemini-1.5-flash").generate_content(prompt)
|
25 |
+
return response.text.strip()
|
26 |
|
27 |
def predict_image(image):
|
28 |
image_resized = image.resize((224, 224))
|
|
|
38 |
|
39 |
explanation = get_disease_detail(top_label)
|
40 |
|
41 |
+
formatted_explanation = (
|
42 |
+
f"**Diagnosis:** {top_label}\n\n"
|
43 |
+
f"**What is it?**\n{explanation.split('What causes it?')[0].strip()}\n\n"
|
44 |
+
f"**What causes it?**\n{explanation.split('What causes it?')[1].split('Suggestion')[0].strip()}\n\n"
|
45 |
+
f"**Suggestion**\n{explanation.split('Suggestion')[1].split('Reminder')[0].strip()}\n\n"
|
46 |
+
f"**Reminder:** Always seek professional help, such as a doctor."
|
47 |
+
)
|
48 |
+
|
49 |
+
return {top_label: top_probability}, formatted_explanation
|
50 |
|
51 |
# Example images
|
52 |
example_images = [
|