Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -15,7 +15,7 @@ import logging
|
|
15 |
|
16 |
# Setup logging for continuous feedback
|
17 |
logging.basicConfig(level=logging.INFO)
|
18 |
-
logger = logging.getLogger(
|
19 |
|
20 |
# βββββββββββββββββββββββββββββ
|
21 |
# CONFIG: set your HF token here or via env var HF_TOKEN
|
@@ -789,16 +789,16 @@ def comprehensive_healthspan_analysis(input_type, image_input, video_input, bree
|
|
789 |
media_type = "video"
|
790 |
video_path = video_input
|
791 |
else:
|
792 |
-
yield "β
|
793 |
return
|
794 |
|
795 |
if selected_media is None:
|
796 |
-
yield f"β
|
797 |
return
|
798 |
|
799 |
# Check if questionnaire is completed
|
800 |
if not hrqol_responses or all(not r for r in hrqol_responses):
|
801 |
-
yield "β
|
802 |
return
|
803 |
|
804 |
# Build HRQOL responses dictionary - Updated for shortened questionnaire
|
@@ -931,7 +931,7 @@ def comprehensive_healthspan_analysis(input_type, image_input, video_input, bree
|
|
931 |
uncertainty_info = ""
|
932 |
if breed_info.get('high_uncertainty', False):
|
933 |
uncertainty_info = f"""<div style="background: #fff3cd; border: 1px solid #ffeaa7; padding: 10px; border-radius: 8px; margin: 10px 0;">
|
934 |
-
<p style="margin: 0; color: #856404;"><strong
|
935 |
Age prediction uncertainty is Β±{breed_info.get('uncertainty', 0):.1f} years. Consider veterinary consultation.</p>
|
936 |
</div>"""
|
937 |
|
@@ -998,7 +998,7 @@ def comprehensive_healthspan_analysis(input_type, image_input, video_input, bree
|
|
998 |
"""
|
999 |
for aspect, data in health_aspects.items():
|
1000 |
is_healthy = any(word in data["assessment"].lower() for word in ["healthy", "bright", "clean", "ideal"])
|
1001 |
-
status_icon = "β
" if is_healthy else "
|
1002 |
status_color = "#2E7D32" if is_healthy else "#F57C00"
|
1003 |
bg_color = "#E8F5E8" if is_healthy else "#FFF3E0"
|
1004 |
|
@@ -1018,21 +1018,21 @@ def comprehensive_healthspan_analysis(input_type, image_input, video_input, bree
|
|
1018 |
# Enhanced recommendations based on advanced analysis
|
1019 |
recommendations = []
|
1020 |
if hrqol_scores["vitality"] < 60:
|
1021 |
-
recommendations.append("π
|
1022 |
if hrqol_scores["comfort"] < 70:
|
1023 |
-
recommendations.append("π
|
1024 |
if hrqol_scores["emotional_wellbeing"] < 65:
|
1025 |
-
recommendations.append("π
|
1026 |
if hrqol_scores["alertness"] < 70:
|
1027 |
-
recommendations.append("π§
|
1028 |
|
1029 |
if breed_info and breed_info.get('high_uncertainty', False):
|
1030 |
-
recommendations.append("π₯
|
1031 |
|
1032 |
if breed_info and age:
|
1033 |
pace = breed_info["bio_age"] / age
|
1034 |
if pace > 1.3:
|
1035 |
-
recommendations.append("β‘
|
1036 |
|
1037 |
if recommendations:
|
1038 |
report_html += f"""
|
@@ -1046,7 +1046,7 @@ def comprehensive_healthspan_analysis(input_type, image_input, video_input, bree
|
|
1046 |
report_html += """
|
1047 |
<div style="background: #F5F5F5; border: 1px solid #E0E0E0; padding: 20px; border-radius: 8px; margin: 20px 0;">
|
1048 |
<p style="margin: 0; font-size: 0.9em; color: #424242; line-height: 1.5;">
|
1049 |
-
<strong style="color: #D32F2F;"
|
1050 |
This analysis uses advanced AI models with multi-factor biological age prediction based on visual health indicators,
|
1051 |
HRQOL correlations, and movement analysis. Results are for educational purposes only.
|
1052 |
Always consult with a qualified veterinarian for professional medical advice and diagnosis.
|
@@ -1185,7 +1185,7 @@ custom_css = """
|
|
1185 |
}
|
1186 |
"""
|
1187 |
|
1188 |
-
#
|
1189 |
with gr.Blocks(
|
1190 |
title="πΆ Enhanced AI Dog Health Analyzer",
|
1191 |
theme=gr.themes.Soft(),
|
@@ -1246,7 +1246,7 @@ with gr.Blocks(
|
|
1246 |
gr.HTML("""
|
1247 |
<div style="margin: 20px 0;">
|
1248 |
<h3 style="color: #667eea; text-align: center; margin-bottom: 15px;">
|
1249 |
-
|
1250 |
</h3>
|
1251 |
</div>
|
1252 |
""")
|
@@ -1265,11 +1265,11 @@ with gr.Blocks(
|
|
1265 |
maximum=25
|
1266 |
)
|
1267 |
|
1268 |
-
# Right Column - CLEAN HRQOL Questionnaire Form
|
1269 |
with gr.Column(scale=1):
|
1270 |
# Clean questionnaire header
|
1271 |
gr.HTML("""
|
1272 |
-
<div
|
1273 |
<div style="text-align: center; margin-bottom: 24px;">
|
1274 |
<h2 style="color: #1f2937; margin: 0 0 8px 0; font-size: 1.6em; font-weight: 600;">
|
1275 |
π Health Assessment Form
|
@@ -1283,35 +1283,45 @@ with gr.Blocks(
|
|
1283 |
|
1284 |
hrqol_inputs = []
|
1285 |
|
1286 |
-
# Clean questionnaire form layout
|
1287 |
-
|
1288 |
-
|
1289 |
-
|
1290 |
-
|
1291 |
-
|
1292 |
-
|
1293 |
-
|
1294 |
-
|
1295 |
-
|
1296 |
-
|
1297 |
-
|
1298 |
-
|
1299 |
-
|
1300 |
-
|
1301 |
-
|
1302 |
-
|
1303 |
-
|
1304 |
-
|
1305 |
-
|
1306 |
-
|
1307 |
-
|
1308 |
-
|
1309 |
-
|
1310 |
-
|
1311 |
-
|
1312 |
-
|
1313 |
-
|
1314 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1315 |
|
1316 |
# Clean Analysis Button
|
1317 |
gr.HTML("""
|
@@ -1341,5 +1351,5 @@ with gr.Blocks(
|
|
1341 |
outputs=output_report
|
1342 |
)
|
1343 |
|
1344 |
-
if
|
1345 |
-
demo.launch()
|
|
|
15 |
|
16 |
# Setup logging for continuous feedback
|
17 |
logging.basicConfig(level=logging.INFO)
|
18 |
+
logger = logging.getLogger(_name_)
|
19 |
|
20 |
# βββββββββββββββββββββββββββββ
|
21 |
# CONFIG: set your HF token here or via env var HF_TOKEN
|
|
|
789 |
media_type = "video"
|
790 |
video_path = video_input
|
791 |
else:
|
792 |
+
yield "β *Error*: Please select an input type."
|
793 |
return
|
794 |
|
795 |
if selected_media is None:
|
796 |
+
yield f"β *Error*: Please provide a {media_type} for analysis."
|
797 |
return
|
798 |
|
799 |
# Check if questionnaire is completed
|
800 |
if not hrqol_responses or all(not r for r in hrqol_responses):
|
801 |
+
yield "β *Error*: Please complete the HRQOL questionnaire before analysis."
|
802 |
return
|
803 |
|
804 |
# Build HRQOL responses dictionary - Updated for shortened questionnaire
|
|
|
931 |
uncertainty_info = ""
|
932 |
if breed_info.get('high_uncertainty', False):
|
933 |
uncertainty_info = f"""<div style="background: #fff3cd; border: 1px solid #ffeaa7; padding: 10px; border-radius: 8px; margin: 10px 0;">
|
934 |
+
<p style="margin: 0; color: #856404;"><strong>β High Uncertainty:</strong>
|
935 |
Age prediction uncertainty is Β±{breed_info.get('uncertainty', 0):.1f} years. Consider veterinary consultation.</p>
|
936 |
</div>"""
|
937 |
|
|
|
998 |
"""
|
999 |
for aspect, data in health_aspects.items():
|
1000 |
is_healthy = any(word in data["assessment"].lower() for word in ["healthy", "bright", "clean", "ideal"])
|
1001 |
+
status_icon = "β
" if is_healthy else "β "
|
1002 |
status_color = "#2E7D32" if is_healthy else "#F57C00"
|
1003 |
bg_color = "#E8F5E8" if is_healthy else "#FFF3E0"
|
1004 |
|
|
|
1018 |
# Enhanced recommendations based on advanced analysis
|
1019 |
recommendations = []
|
1020 |
if hrqol_scores["vitality"] < 60:
|
1021 |
+
recommendations.append("π *Vitality Enhancement*: Implement graduated exercise program with monitoring")
|
1022 |
if hrqol_scores["comfort"] < 70:
|
1023 |
+
recommendations.append("π *Comfort Support*: Consider pain management and mobility aids")
|
1024 |
if hrqol_scores["emotional_wellbeing"] < 65:
|
1025 |
+
recommendations.append("π *Emotional Care*: Increase environmental enrichment and social interaction")
|
1026 |
if hrqol_scores["alertness"] < 70:
|
1027 |
+
recommendations.append("π§ *Cognitive Support*: Introduce cognitive enhancement activities")
|
1028 |
|
1029 |
if breed_info and breed_info.get('high_uncertainty', False):
|
1030 |
+
recommendations.append("π₯ *Veterinary Consultation*: High prediction uncertainty suggests professional evaluation needed")
|
1031 |
|
1032 |
if breed_info and age:
|
1033 |
pace = breed_info["bio_age"] / age
|
1034 |
if pace > 1.3:
|
1035 |
+
recommendations.append("β‘ *Accelerated Aging*: Consider comprehensive health screening and lifestyle modifications")
|
1036 |
|
1037 |
if recommendations:
|
1038 |
report_html += f"""
|
|
|
1046 |
report_html += """
|
1047 |
<div style="background: #F5F5F5; border: 1px solid #E0E0E0; padding: 20px; border-radius: 8px; margin: 20px 0;">
|
1048 |
<p style="margin: 0; font-size: 0.9em; color: #424242; line-height: 1.5;">
|
1049 |
+
<strong style="color: #D32F2F;">β Important Disclaimer:</strong>
|
1050 |
This analysis uses advanced AI models with multi-factor biological age prediction based on visual health indicators,
|
1051 |
HRQOL correlations, and movement analysis. Results are for educational purposes only.
|
1052 |
Always consult with a qualified veterinarian for professional medical advice and diagnosis.
|
|
|
1185 |
}
|
1186 |
"""
|
1187 |
|
1188 |
+
# UPDATED GRADIO INTERFACE WITH CLEAN QUESTIONNAIRE UI
|
1189 |
with gr.Blocks(
|
1190 |
title="πΆ Enhanced AI Dog Health Analyzer",
|
1191 |
theme=gr.themes.Soft(),
|
|
|
1246 |
gr.HTML("""
|
1247 |
<div style="margin: 20px 0;">
|
1248 |
<h3 style="color: #667eea; text-align: center; margin-bottom: 15px;">
|
1249 |
+
β Optional Information
|
1250 |
</h3>
|
1251 |
</div>
|
1252 |
""")
|
|
|
1265 |
maximum=25
|
1266 |
)
|
1267 |
|
1268 |
+
# Right Column - CLEAN HRQOL Questionnaire Form
|
1269 |
with gr.Column(scale=1):
|
1270 |
# Clean questionnaire header
|
1271 |
gr.HTML("""
|
1272 |
+
<div class="clean-questionnaire-card">
|
1273 |
<div style="text-align: center; margin-bottom: 24px;">
|
1274 |
<h2 style="color: #1f2937; margin: 0 0 8px 0; font-size: 1.6em; font-weight: 600;">
|
1275 |
π Health Assessment Form
|
|
|
1283 |
|
1284 |
hrqol_inputs = []
|
1285 |
|
1286 |
+
# Clean questionnaire form layout
|
1287 |
+
with gr.Group(elem_classes=["clean-form"]):
|
1288 |
+
for i, (domain_key, domain_data) in enumerate(HRQOL_QUESTIONNAIRE.items()):
|
1289 |
+
# Clean section header
|
1290 |
+
gr.HTML(f"""<div class="clean-section-header">
|
1291 |
+
<h3 style="margin: 0; color: #1f2937; font-size: 1.1em; font-weight: 600; display: flex; align-items: center;">
|
1292 |
+
<span style="margin-right: 8px;">{domain_data['title'].split()[0]}</span>
|
1293 |
+
{domain_data['title'].split()[1:][0] if len(domain_data['title'].split()) > 1 else ''}
|
1294 |
+
</h3>
|
1295 |
+
<p style="margin: 6px 0 0 0; color: #6b7280; font-size: 0.9em; line-height: 1.3;">
|
1296 |
+
{domain_data['description']}
|
1297 |
+
</p>
|
1298 |
+
</div>""")
|
1299 |
+
|
1300 |
+
# Clean question form field
|
1301 |
+
for question in domain_data["questions"]:
|
1302 |
+
# Clean question container
|
1303 |
+
gr.HTML(f"""
|
1304 |
+
<div style="margin: 16px 0;">
|
1305 |
+
<label style="display: block; font-size: 0.95em; font-weight: 500; color: #374151; margin-bottom: 8px; line-height: 1.4;">
|
1306 |
+
{question["text"]}
|
1307 |
+
</label>
|
1308 |
+
</div>
|
1309 |
+
""")
|
1310 |
+
|
1311 |
+
dropdown = gr.Dropdown(
|
1312 |
+
choices=question["options"],
|
1313 |
+
label="", # Remove label since we're showing it above
|
1314 |
+
placeholder="Select your answer...",
|
1315 |
+
value=None,
|
1316 |
+
interactive=True,
|
1317 |
+
container=False,
|
1318 |
+
elem_classes=["clean-dropdown"]
|
1319 |
+
)
|
1320 |
+
hrqol_inputs.append(dropdown)
|
1321 |
+
|
1322 |
+
# Clean separator between sections (except last)
|
1323 |
+
if i < len(HRQOL_QUESTIONNAIRE) - 1:
|
1324 |
+
gr.HTML('<hr class="clean-separator">')
|
1325 |
|
1326 |
# Clean Analysis Button
|
1327 |
gr.HTML("""
|
|
|
1351 |
outputs=output_report
|
1352 |
)
|
1353 |
|
1354 |
+
if _name_ == "_main_":
|
1355 |
+
demo.launch()
|