CelagenexResearch commited on
Commit
cfbf4f1
Β·
verified Β·
1 Parent(s): 2d64122

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +58 -48
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(__name__)
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 "❌ **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,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>⚠️ High Uncertainty:</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("πŸ”‹ **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,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;">⚠️ 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,7 +1185,7 @@ custom_css = """
1185
  }
1186
  """
1187
 
1188
- # FIXED GRADIO INTERFACE WITH CLEAN QUESTIONNAIRE UI (NO ERRORS)
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
- βš™οΈ Optional Information
1250
  </h3>
1251
  </div>
1252
  """)
@@ -1265,11 +1265,11 @@ with gr.Blocks(
1265
  maximum=25
1266
  )
1267
 
1268
- # Right Column - CLEAN HRQOL Questionnaire Form (FIXED - NO ERRORS)
1269
  with gr.Column(scale=1):
1270
  # Clean questionnaire header
1271
  gr.HTML("""
1272
- <div style="background: white; border-radius: 12px; padding: 25px; margin: 10px 0; box-shadow: 0 4px 12px rgba(0,0,0,0.08);">
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 - FIXED VERSION
1287
- for i, (domain_key, domain_data) in enumerate(HRQOL_QUESTIONNAIRE.items()):
1288
- # Clean section header
1289
- gr.HTML(f"""
1290
- <div style="background: #f8fafc; border: 1px solid #e2e8f0; border-radius: 6px; padding: 16px; margin: 16px 0 8px 0; border-left: 4px solid #667eea;">
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
-
1301
- # Clean question form field - FIXED: No placeholder parameter
1302
- for question in domain_data["questions"]:
1303
- dropdown = gr.Dropdown(
1304
- choices=question["options"],
1305
- label=question["text"], # Show full question as label
1306
- value=None,
1307
- interactive=True,
1308
- container=True
1309
- )
1310
- hrqol_inputs.append(dropdown)
1311
-
1312
- # Clean separator between sections (except last)
1313
- if i < len(HRQOL_QUESTIONNAIRE) - 1:
1314
- gr.HTML('<div style="height: 1px; background: #e5e7eb; margin: 20px 0; border: none;"></div>')
 
 
 
 
 
 
 
 
 
 
1315
 
1316
  # Clean Analysis Button
1317
  gr.HTML("""
@@ -1341,5 +1351,5 @@ with gr.Blocks(
1341
  outputs=output_report
1342
  )
1343
 
1344
- if __name__ == "__main__":
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()