CelagenexResearch commited on
Commit
1ea1daf
Β·
verified Β·
1 Parent(s): 6ffd8d5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +73 -62
app.py CHANGED
@@ -1077,7 +1077,7 @@ def update_media_input(input_type):
1077
  else: # Video Analysis
1078
  return gr.update(visible=False), gr.update(visible=True)
1079
 
1080
- # Custom CSS for enhanced styling
1081
  custom_css = """
1082
  /* Enhanced gradient background */
1083
  .gradio-container {
@@ -1085,13 +1085,13 @@ custom_css = """
1085
  min-height: 100vh;
1086
  }
1087
 
1088
- /* Card styling */
1089
  .input-card, .questionnaire-card {
1090
  background: white;
1091
  border-radius: 15px;
1092
- padding: 25px;
1093
  box-shadow: 0 8px 25px rgba(0,0,0,0.1);
1094
- margin: 10px;
1095
  border: 1px solid #e0e6ed;
1096
  }
1097
 
@@ -1102,7 +1102,7 @@ custom_css = """
1102
  text-align: center;
1103
  padding: 30px;
1104
  border-radius: 15px;
1105
- margin-bottom: 30px;
1106
  box-shadow: 0 8px 25px rgba(102, 126, 234, 0.3);
1107
  }
1108
 
@@ -1125,27 +1125,12 @@ custom_css = """
1125
  box-shadow: 0 8px 25px rgba(102, 126, 234, 0.4);
1126
  }
1127
 
1128
- /* Accordion styling */
1129
- .accordion-header {
1130
- background: linear-gradient(135deg, #f8f9fa 0%, #e9ecef 100%);
1131
- border: 1px solid #dee2e6;
1132
- border-radius: 8px;
1133
- padding: 15px;
1134
- margin: 10px 0;
1135
- cursor: pointer;
1136
- transition: all 0.3s ease;
1137
- }
1138
-
1139
- .accordion-header:hover {
1140
- background: linear-gradient(135deg, #e9ecef 0%, #dee2e6 100%);
1141
- transform: translateY(-1px);
1142
- }
1143
-
1144
- /* Dropdown styling */
1145
  .gr-dropdown {
1146
  border-radius: 8px;
1147
  border: 2px solid #e0e6ed;
1148
  transition: border-color 0.3s ease;
 
1149
  }
1150
 
1151
  .gr-dropdown:focus {
@@ -1153,19 +1138,40 @@ custom_css = """
1153
  box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
1154
  }
1155
 
1156
- /* Progress animation */
1157
- @keyframes pulse {
1158
- 0% { opacity: 1; }
1159
- 50% { opacity: 0.5; }
1160
- 100% { opacity: 1; }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1161
  }
1162
 
1163
- .loading-pulse {
1164
- animation: pulse 2s infinite;
 
 
1165
  }
1166
  """
1167
 
1168
- # Gradio Interface with Enhanced UI
1169
  with gr.Blocks(
1170
  title="🐢 Enhanced AI Dog Health Analyzer",
1171
  theme=gr.themes.Soft(),
@@ -1195,16 +1201,13 @@ with gr.Blocks(
1195
  </div>
1196
  """)
1197
 
1198
- # Enhanced dropdown with better styling
1199
  input_type_dropdown = gr.Dropdown(
1200
  choices=["Image Analysis", "Video Analysis"],
1201
  label="πŸ” Select Analysis Type",
1202
  value="Image Analysis",
1203
- interactive=True,
1204
- elem_classes=["gr-dropdown"]
1205
  )
1206
 
1207
- # Media input components with enhanced labels
1208
  image_input = gr.Image(
1209
  type="pil",
1210
  label="πŸ“· Upload Dog Photo or Use Webcam",
@@ -1220,14 +1223,12 @@ with gr.Blocks(
1220
  height=300
1221
  )
1222
 
1223
- # Update visibility based on dropdown selection
1224
  input_type_dropdown.change(
1225
  fn=update_media_input,
1226
  inputs=[input_type_dropdown],
1227
  outputs=[image_input, video_input]
1228
  )
1229
 
1230
- # Enhanced optional information section
1231
  gr.HTML("""
1232
  <div style="margin: 20px 0;">
1233
  <h3 style="color: #667eea; text-align: center; margin-bottom: 15px;">
@@ -1240,8 +1241,7 @@ with gr.Blocks(
1240
  STANFORD_BREEDS,
1241
  label="πŸ• Dog Breed (Auto-detected if not specified)",
1242
  value=None,
1243
- allow_custom_value=True,
1244
- elem_classes=["gr-dropdown"]
1245
  )
1246
  age_input = gr.Number(
1247
  label="πŸ“… Chronological Age (years)",
@@ -1251,49 +1251,60 @@ with gr.Blocks(
1251
  maximum=25
1252
  )
1253
 
1254
- # Right Column - SHORTENED HRQOL Questionnaire
1255
  with gr.Column(scale=1):
 
1256
  gr.HTML("""
1257
- <div class="questionnaire-card">
1258
- <h2 style="color: #667eea; margin: 0 0 10px 0; text-align: center;">
1259
- πŸ“‹ Streamlined HRQOL Assessment
1260
  </h2>
1261
- <p style="text-align: center; color: #666; font-style: italic; margin-bottom: 20px;">
1262
- Complete all 4 comprehensive questions for accurate healthspan analysis
1263
  </p>
1264
  </div>
1265
  """)
1266
 
1267
  hrqol_inputs = []
1268
 
1269
- for domain_key, domain_data in HRQOL_QUESTIONNAIRE.items():
1270
- # Enhanced accordion header
1271
- gr.HTML(f"""
1272
- <div class="accordion-header">
1273
- <h3 style="margin: 0; color: #333;">
1274
- {domain_data['title']}
1275
- </h3>
1276
- <p style="margin: 5px 0 0 0; color: #666; font-size: 0.9em;">
1277
- {domain_data['description']}
1278
- </p>
1279
- </div>
1280
- """)
1281
-
1282
- with gr.Accordion(domain_data["title"], open=True):
 
 
 
 
1283
  for question in domain_data["questions"]:
1284
- # Enhanced dropdown for each question
1285
  dropdown = gr.Dropdown(
1286
  choices=question["options"],
1287
  label=question["text"],
1288
  value=None,
1289
  interactive=True,
1290
- elem_classes=["gr-dropdown"]
 
1291
  )
1292
  hrqol_inputs.append(dropdown)
 
 
 
 
 
 
1293
 
1294
- # Enhanced Analysis Button
1295
  gr.HTML("""
1296
- <div style="text-align: center; margin: 30px 0;">
1297
  """)
1298
 
1299
  analyze_button = gr.Button(
 
1077
  else: # Video Analysis
1078
  return gr.update(visible=False), gr.update(visible=True)
1079
 
1080
+ # Custom CSS for enhanced styling with compact questionnaire
1081
  custom_css = """
1082
  /* Enhanced gradient background */
1083
  .gradio-container {
 
1085
  min-height: 100vh;
1086
  }
1087
 
1088
+ /* Card styling - more compact */
1089
  .input-card, .questionnaire-card {
1090
  background: white;
1091
  border-radius: 15px;
1092
+ padding: 20px;
1093
  box-shadow: 0 8px 25px rgba(0,0,0,0.1);
1094
+ margin: 5px;
1095
  border: 1px solid #e0e6ed;
1096
  }
1097
 
 
1102
  text-align: center;
1103
  padding: 30px;
1104
  border-radius: 15px;
1105
+ margin-bottom: 20px;
1106
  box-shadow: 0 8px 25px rgba(102, 126, 234, 0.3);
1107
  }
1108
 
 
1125
  box-shadow: 0 8px 25px rgba(102, 126, 234, 0.4);
1126
  }
1127
 
1128
+ /* Compact dropdown styling */
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1129
  .gr-dropdown {
1130
  border-radius: 8px;
1131
  border: 2px solid #e0e6ed;
1132
  transition: border-color 0.3s ease;
1133
+ margin: 5px 0 !important;
1134
  }
1135
 
1136
  .gr-dropdown:focus {
 
1138
  box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
1139
  }
1140
 
1141
+ /* Compact form styling */
1142
+ .gr-form {
1143
+ gap: 8px !important;
1144
+ }
1145
+
1146
+ /* Reduce spacing in groups */
1147
+ .gr-group {
1148
+ border: none !important;
1149
+ padding: 0 !important;
1150
+ margin: 0 !important;
1151
+ background: transparent !important;
1152
+ }
1153
+
1154
+ /* Compact label styling */
1155
+ .gr-block label {
1156
+ margin-bottom: 4px !important;
1157
+ font-size: 0.9em !important;
1158
+ font-weight: 500 !important;
1159
+ }
1160
+
1161
+ /* Reduce container padding */
1162
+ .gr-box {
1163
+ border: none !important;
1164
+ padding: 2px !important;
1165
  }
1166
 
1167
+ /* Ensure equal column widths */
1168
+ .gr-row > .gr-column {
1169
+ min-width: 0 !important;
1170
+ flex: 1 !important;
1171
  }
1172
  """
1173
 
1174
+ # UPDATED GRADIO INTERFACE WITH COMPACT UI
1175
  with gr.Blocks(
1176
  title="🐢 Enhanced AI Dog Health Analyzer",
1177
  theme=gr.themes.Soft(),
 
1201
  </div>
1202
  """)
1203
 
 
1204
  input_type_dropdown = gr.Dropdown(
1205
  choices=["Image Analysis", "Video Analysis"],
1206
  label="πŸ” Select Analysis Type",
1207
  value="Image Analysis",
1208
+ interactive=True
 
1209
  )
1210
 
 
1211
  image_input = gr.Image(
1212
  type="pil",
1213
  label="πŸ“· Upload Dog Photo or Use Webcam",
 
1223
  height=300
1224
  )
1225
 
 
1226
  input_type_dropdown.change(
1227
  fn=update_media_input,
1228
  inputs=[input_type_dropdown],
1229
  outputs=[image_input, video_input]
1230
  )
1231
 
 
1232
  gr.HTML("""
1233
  <div style="margin: 20px 0;">
1234
  <h3 style="color: #667eea; text-align: center; margin-bottom: 15px;">
 
1241
  STANFORD_BREEDS,
1242
  label="πŸ• Dog Breed (Auto-detected if not specified)",
1243
  value=None,
1244
+ allow_custom_value=True
 
1245
  )
1246
  age_input = gr.Number(
1247
  label="πŸ“… Chronological Age (years)",
 
1251
  maximum=25
1252
  )
1253
 
1254
+ # Right Column - COMPACT HRQOL Questionnaire
1255
  with gr.Column(scale=1):
1256
+ # Single unified card for all questionnaire sections
1257
  gr.HTML("""
1258
+ <div class="questionnaire-card" style="padding: 20px; margin: 0;">
1259
+ <h2 style="color: #667eea; margin: 0 0 15px 0; text-align: center; font-size: 1.5em;">
1260
+ πŸ“‹ HRQOL Health Assessment
1261
  </h2>
1262
+ <p style="text-align: center; color: #666; font-style: italic; margin-bottom: 20px; font-size: 0.9em;">
1263
+ Complete all 4 sections for accurate analysis
1264
  </p>
1265
  </div>
1266
  """)
1267
 
1268
  hrqol_inputs = []
1269
 
1270
+ # Compact questionnaire layout - all in one card
1271
+ with gr.Group():
1272
+ for i, (domain_key, domain_data) in enumerate(HRQOL_QUESTIONNAIRE.items()):
1273
+ # Compact section header with minimal spacing
1274
+ gr.HTML(f"""
1275
+ <div style="background: linear-gradient(135deg, #f8f9fa 0%, #e9ecef 100%);
1276
+ border: 1px solid #dee2e6; border-radius: 8px;
1277
+ padding: 12px; margin: 8px 0;">
1278
+ <h4 style="margin: 0; color: #333; font-size: 1em; font-weight: 600;">
1279
+ {domain_data['title']}
1280
+ </h4>
1281
+ <p style="margin: 3px 0 0 0; color: #666; font-size: 0.8em;">
1282
+ {domain_data['description']}
1283
+ </p>
1284
+ </div>
1285
+ """)
1286
+
1287
+ # Question dropdown with minimal spacing
1288
  for question in domain_data["questions"]:
 
1289
  dropdown = gr.Dropdown(
1290
  choices=question["options"],
1291
  label=question["text"],
1292
  value=None,
1293
  interactive=True,
1294
+ container=True,
1295
+ scale=1
1296
  )
1297
  hrqol_inputs.append(dropdown)
1298
+
1299
+ # Add small separator except for last item
1300
+ if i < len(HRQOL_QUESTIONNAIRE) - 1:
1301
+ gr.HTML("""
1302
+ <div style="height: 1px; background: #e0e0e0; margin: 10px 0;"></div>
1303
+ """)
1304
 
1305
+ # Enhanced Analysis Button with reduced spacing
1306
  gr.HTML("""
1307
+ <div style="text-align: center; margin: 20px 0;">
1308
  """)
1309
 
1310
  analyze_button = gr.Button(