Sabatino81 commited on
Commit
b2c144e
·
verified ·
1 Parent(s): 42f73ba

Upload app.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. app.py +181 -31
app.py CHANGED
@@ -1021,10 +1021,176 @@ def generate_flutter_screens(
1021
  )
1022
 
1023
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1024
  def generate_background_gallery(theme_json: str = ""):
1025
  """
1026
  Generate HTML gallery of all 30 backgrounds organized by category
1027
- Backgrounds are styled with theme colors if provided
1028
  """
1029
  from agents.flutter_screen_generator import FlutterScreenGenerator
1030
 
@@ -1118,24 +1284,21 @@ def generate_background_gallery(theme_json: str = ""):
1118
  }
1119
  complexity_color = complexity_colors.get(info['complexity'], "#6c757d")
1120
 
1121
- # Generate DartPad link (we'll use a simple approach with URL encoding)
1122
- dartpad_url = f"https://dartpad.dev"
1123
 
1124
  html_parts.append(f"""
1125
- <div style="background: #f8f9fa; padding: 12px; border-radius: 6px; border: 1px solid #dee2e6;">
1126
- <div style="font-weight: 600; font-size: 13px; margin-bottom: 4px;">{info['name']}</div>
1127
- <div style="font-size: 11px; color: #6c757d; margin-bottom: 8px;">
1128
- <code style="background: #e9ecef; padding: 2px 6px; border-radius: 3px; font-size: 10px;">{bg_id}</code>
1129
- </div>
1130
- <div style="display: flex; gap: 6px; align-items: center; margin-bottom: 8px;">
 
1131
  <span style="background: {complexity_color}; color: white; padding: 2px 8px; border-radius: 10px; font-size: 10px; font-weight: 600;">
1132
  {info['complexity'].upper()}
1133
  </span>
1134
  </div>
1135
- <button onclick="generateBackgroundPreview('{bg_id}')"
1136
- style="width: 100%; background: #007AFF; color: white; border: none; padding: 8px; border-radius: 4px; font-size: 12px; cursor: pointer; font-weight: 500;">
1137
- 🔗 Genera Preview
1138
- </button>
1139
  </div>
1140
  """)
1141
 
@@ -1144,27 +1307,14 @@ def generate_background_gallery(theme_json: str = ""):
1144
  html_parts.append("""
1145
  <div style="margin-top: 20px; padding: 12px; background: #e7f3ff; border-radius: 6px; border-left: 3px solid #007AFF;">
1146
  <p style="margin: 0; font-size: 13px; color: #004085;">
1147
- <strong>💡 Come usare:</strong> Clicca su "Genera Preview" per creare il codice Flutter del background.
1148
- Il codice apparirà sotto e potrai copiarlo su <a href="https://dartpad.dev" target="_blank" style="color: #007AFF;">DartPad</a> per vederlo in azione!
 
 
 
1149
  </p>
1150
  </div>
1151
  </div>
1152
-
1153
- <script>
1154
- function generateBackgroundPreview(bgId) {
1155
- // Trigger the Gradio function to generate preview
1156
- const event = new CustomEvent('generateBgPreview', { detail: bgId });
1157
- document.dispatchEvent(event);
1158
-
1159
- // Scroll to preview area
1160
- setTimeout(() => {
1161
- const previewArea = document.getElementById('bg-preview-area');
1162
- if (previewArea) {
1163
- previewArea.scrollIntoView({ behavior: 'smooth', block: 'nearest' });
1164
- }
1165
- }, 100);
1166
- }
1167
- </script>
1168
  """)
1169
 
1170
  return "".join(html_parts)
 
1021
  )
1022
 
1023
 
1024
+ def render_background_html(bg_id: str, bg_info: dict, primary: str, secondary: str, accent: str) -> str:
1025
+ """
1026
+ Generate HTML/CSS for a single background preview
1027
+ Returns HTML div with the background rendered
1028
+ """
1029
+ bg_name = bg_info['name']
1030
+ bg_category = bg_info['category']
1031
+
1032
+ # Common container style
1033
+ base_style = "width: 150px; height: 250px; border-radius: 12px; position: relative; overflow: hidden; box-shadow: 0 4px 12px rgba(0,0,0,0.15);"
1034
+
1035
+ # Generate background based on type
1036
+ if "gradient_linear" in bg_id:
1037
+ bg_style = f"{base_style} background: linear-gradient(135deg, {primary}, {secondary}, {accent});"
1038
+ bg_layer = ""
1039
+ elif "gradient_radial" in bg_id:
1040
+ bg_style = f"{base_style} background: radial-gradient(circle at 30% 40%, {primary}, {secondary} 50%, {accent});"
1041
+ bg_layer = ""
1042
+ elif "gradient_angular" in bg_id:
1043
+ bg_style = f"{base_style} background: conic-gradient(from 45deg, {primary}, {secondary}, {accent}, {primary});"
1044
+ bg_layer = ""
1045
+ elif "gradient_sweep" in bg_id:
1046
+ bg_style = f"{base_style} background: conic-gradient(from 0deg at 50% 50%, {primary}, {secondary}, {accent}, {primary});"
1047
+ bg_layer = ""
1048
+ elif "gradient_diagonal" in bg_id:
1049
+ bg_style = f"{base_style} background: linear-gradient(45deg, {primary} 0%, {secondary} 50%, {accent} 100%);"
1050
+ bg_layer = ""
1051
+ elif "gradient_mesh" in bg_id:
1052
+ bg_style = f"{base_style} background: radial-gradient(at 20% 30%, {primary} 0%, transparent 50%), radial-gradient(at 80% 70%, {secondary} 0%, transparent 50%), radial-gradient(at 50% 50%, {accent} 0%, transparent 50%), linear-gradient(135deg, {primary}20, {secondary}30);"
1053
+ bg_layer = ""
1054
+ elif "waves_smooth" in bg_id or "waves_sharp" in bg_id or "waves_layered" in bg_id or "waves_curved" in bg_id or "waves_minimal" in bg_id:
1055
+ bg_style = f"{base_style} background: linear-gradient(to bottom, {primary}20, {secondary}33, {accent}20);"
1056
+ bg_layer = f"""
1057
+ <svg style="position: absolute; width: 100%; height: 100%; top: 0; left: 0;" viewBox="0 0 150 250" preserveAspectRatio="none">
1058
+ <path d="M 0,60 Q 37.5,30 75,60 T 150,55 L 150,0 L 0,0 Z" fill="{primary}" opacity="0.4"/>
1059
+ <path d="M 0,150 Q 45,130 75,155 T 150,150 L 150,90 L 0,90 Z" fill="{secondary}" opacity="0.35"/>
1060
+ <path d="M 0,210 Q 37.5,190 75,205 T 150,202 L 150,250 L 0,250 Z" fill="{accent}" opacity="0.3"/>
1061
+ </svg>
1062
+ """
1063
+ elif "geometric_circles" in bg_id:
1064
+ bg_style = f"{base_style} background: linear-gradient(135deg, {primary}33, {secondary}4D);"
1065
+ bg_layer = f"""
1066
+ <div style="position: absolute; width: 100%; height: 100%; top: 0; left: 0;">
1067
+ <div style="position: absolute; left: 15%; top: 12%; width: 35%; padding-top: 35%; background: {primary}; opacity: 0.3; border-radius: 50%;"></div>
1068
+ <div style="position: absolute; right: 8%; bottom: 25%; width: 30%; padding-top: 30%; background: {accent}; opacity: 0.25; border-radius: 50%;"></div>
1069
+ <div style="position: absolute; left: 45%; top: 40%; width: 22%; padding-top: 22%; background: {secondary}; opacity: 0.2; border-radius: 50%;"></div>
1070
+ </div>
1071
+ """
1072
+ elif "geometric_triangles" in bg_id:
1073
+ bg_style = f"{base_style} background: linear-gradient(135deg, {primary}1A, {secondary}26);"
1074
+ bg_layer = f"""
1075
+ <svg style="position: absolute; width: 100%; height: 100%; top: 0; left: 0;" viewBox="0 0 150 250">
1076
+ <polygon points="30,50 60,10 90,50" fill="{primary}" opacity="0.3"/>
1077
+ <polygon points="80,120 110,80 140,120" fill="{secondary}" opacity="0.3"/>
1078
+ <polygon points="20,180 50,140 80,180" fill="{accent}" opacity="0.25"/>
1079
+ </svg>
1080
+ """
1081
+ elif "geometric_hexagons" in bg_id:
1082
+ bg_style = f"{base_style} background: linear-gradient(to bottom, {primary}1A, {secondary}26);"
1083
+ bg_layer = f"""
1084
+ <svg style="position: absolute; width: 100%; height: 100%; top: 0; left: 0;" viewBox="0 0 150 250">
1085
+ <polygon points="75,30 95,40 95,60 75,70 55,60 55,40" fill="{primary}" opacity="0.3" stroke="{primary}" stroke-width="1"/>
1086
+ <polygon points="45,100 65,110 65,130 45,140 25,130 25,110" fill="{secondary}" opacity="0.3" stroke="{secondary}" stroke-width="1"/>
1087
+ <polygon points="105,160 125,170 125,190 105,200 85,190 85,170" fill="{accent}" opacity="0.25" stroke="{accent}" stroke-width="1"/>
1088
+ </svg>
1089
+ """
1090
+ elif "geometric_grid" in bg_id:
1091
+ bg_style = f"{base_style} background: repeating-linear-gradient(0deg, transparent, transparent 19px, {primary}40 19px, {primary}40 20px), repeating-linear-gradient(90deg, transparent, transparent 19px, {secondary}40 19px, {secondary}40 20px), {accent}0D;"
1092
+ bg_layer = ""
1093
+ elif "geometric_stripes" in bg_id:
1094
+ bg_style = f"{base_style} background: repeating-linear-gradient(45deg, {primary}40, {primary}40 10px, {secondary}40 10px, {secondary}40 20px, {accent}30 20px, {accent}30 30px);"
1095
+ bg_layer = ""
1096
+ elif "geometric_diamonds" in bg_id:
1097
+ bg_style = f"{base_style} background: linear-gradient(135deg, {primary}1A 25%, transparent 25%), linear-gradient(225deg, {secondary}1A 25%, transparent 25%), linear-gradient(45deg, {accent}1A 25%, transparent 25%), linear-gradient(315deg, {primary}26 25%, {secondary}0D 25%);"
1098
+ bg_layer = ""
1099
+ elif "organic_blobs" in bg_id or "organic_fluid" in bg_id:
1100
+ bg_style = f"{base_style} background: {secondary}26;"
1101
+ bg_layer = f"""
1102
+ <svg style="position: absolute; width: 100%; height: 100%; top: 0; left: 0;" viewBox="0 0 150 250">
1103
+ <path d="M 30,40 Q 50,20 70,40 T 110,50 Q 120,70 100,90 T 60,80 Q 40,70 30,40 Z" fill="{primary}" opacity="0.4"/>
1104
+ <path d="M 80,140 Q 100,120 120,140 T 140,180 Q 130,200 110,190 T 80,170 Q 70,150 80,140 Z" fill="{accent}" opacity="0.3"/>
1105
+ </svg>
1106
+ """
1107
+ elif "organic_noise" in bg_id:
1108
+ bg_style = f"{base_style} background: linear-gradient(135deg, {primary}33, {secondary}4D); filter: contrast(170%) brightness(1000%);"
1109
+ bg_layer = f'<div style="position: absolute; width: 100%; height: 100%; background: url(\'data:image/svg+xml,%3Csvg viewBox="0 0 200 200" xmlns="http://www.w3.org/2000/svg"%3E%3Cfilter id="noise"%3E%3CfeTurbulence baseFrequency="0.9" /%3E%3C/filter%3E%3Crect width="100%25" height="100%25" filter="url(%23noise)" opacity="0.15"/%3E%3C/svg%3E\'); background-size: 100px 100px;"></div>'
1110
+ elif "organic_clouds" in bg_id:
1111
+ bg_style = f"{base_style} background: linear-gradient(to bottom, {primary}40, {secondary}60, {accent}40);"
1112
+ bg_layer = f"""
1113
+ <div style="position: absolute; width: 100%; height: 100%;">
1114
+ <div style="position: absolute; left: 10%; top: 15%; width: 50px; height: 25px; background: white; opacity: 0.3; border-radius: 50%;"></div>
1115
+ <div style="position: absolute; left: 25%; top: 10%; width: 40px; height: 30px; background: white; opacity: 0.25; border-radius: 50%;"></div>
1116
+ <div style="position: absolute; right: 15%; top: 40%; width: 45px; height: 28px; background: white; opacity: 0.3; border-radius: 50%;"></div>
1117
+ </div>
1118
+ """
1119
+ elif "pattern_dots" in bg_id:
1120
+ bg_style = f"{base_style} background: radial-gradient(circle, {primary} 2px, transparent 2px); background-size: 20px 20px; background-color: {secondary}1A;"
1121
+ bg_layer = ""
1122
+ elif "pattern_lines" in bg_id:
1123
+ bg_style = f"{base_style} background: repeating-linear-gradient(0deg, {primary}60, {primary}60 2px, transparent 2px, transparent 10px), {secondary}1A;"
1124
+ bg_layer = ""
1125
+ elif "pattern_chevron" in bg_id:
1126
+ bg_style = f"{base_style} background: repeating-linear-gradient(45deg, {primary}40, {primary}40 10px, {secondary}40 10px, {secondary}40 20px);"
1127
+ bg_layer = ""
1128
+ elif "pattern_zigzag" in bg_id:
1129
+ bg_style = f"{base_style} background: linear-gradient(135deg, {primary}40 25%, transparent 25%), linear-gradient(225deg, {secondary}40 25%, transparent 25%), linear-gradient(315deg, {accent}30 25%, transparent 25%); background-size: 20px 20px;"
1130
+ bg_layer = ""
1131
+ elif "abstract_crystalline" in bg_id or "abstract_voronoi" in bg_id:
1132
+ bg_style = f"{base_style} background: linear-gradient(135deg, {primary}26, {secondary}33, {accent}26);"
1133
+ bg_layer = f"""
1134
+ <svg style="position: absolute; width: 100%; height: 100%;" viewBox="0 0 150 250">
1135
+ <polygon points="30,20 60,50 40,80 10,70" fill="{primary}" opacity="0.3"/>
1136
+ <polygon points="70,30 110,40 100,80 80,90" fill="{secondary}" opacity="0.3"/>
1137
+ <polygon points="20,120 50,140 30,180 0,160" fill="{accent}" opacity="0.25"/>
1138
+ <polygon points="90,120 130,130 120,180 85,170" fill="{primary}" opacity="0.3"/>
1139
+ </svg>
1140
+ """
1141
+ elif "abstract_particles" in bg_id:
1142
+ bg_style = f"{base_style} background: {secondary}1A;"
1143
+ bg_layer = f"""
1144
+ <svg style="position: absolute; width: 100%; height: 100%;" viewBox="0 0 150 250">
1145
+ <circle cx="30" cy="40" r="3" fill="{primary}" opacity="0.6"/>
1146
+ <circle cx="70" cy="25" r="2" fill="{secondary}" opacity="0.5"/>
1147
+ <circle cx="110" cy="50" r="2.5" fill="{accent}" opacity="0.5"/>
1148
+ <circle cx="40" cy="90" r="2" fill="{primary}" opacity="0.4"/>
1149
+ <circle cx="90" cy="110" r="3" fill="{secondary}" opacity="0.6"/>
1150
+ <circle cx="120" cy="140" r="2" fill="{accent}" opacity="0.5"/>
1151
+ <circle cx="50" cy="170" r="2.5" fill="{primary}" opacity="0.5"/>
1152
+ <circle cx="100" cy="200" r="2" fill="{secondary}" opacity="0.4"/>
1153
+ <line x1="30" y1="40" x2="70" y2="25" stroke="{primary}" opacity="0.2" stroke-width="1"/>
1154
+ <line x1="70" y1="25" x2="110" y2="50" stroke="{secondary}" opacity="0.2" stroke-width="1"/>
1155
+ <line x1="40" y1="90" x2="90" y2="110" stroke="{accent}" opacity="0.2" stroke-width="1"/>
1156
+ </svg>
1157
+ """
1158
+ elif "abstract_rays" in bg_id:
1159
+ bg_style = f"{base_style} background: radial-gradient(circle at 50% 120%, {primary}, {secondary} 40%, {accent} 80%);"
1160
+ bg_layer = ""
1161
+ elif "abstract_constellation" in bg_id:
1162
+ bg_style = f"{base_style} background: linear-gradient(to bottom, {primary}1A, {secondary}26, {accent}1A);"
1163
+ bg_layer = f"""
1164
+ <svg style="position: absolute; width: 100%; height: 100%;" viewBox="0 0 150 250">
1165
+ <circle cx="40" cy="30" r="2" fill="white" opacity="0.8"/>
1166
+ <circle cx="80" cy="50" r="2.5" fill="white" opacity="0.9"/>
1167
+ <circle cx="110" cy="40" r="2" fill="white" opacity="0.7"/>
1168
+ <circle cx="30" cy="100" r="2" fill="white" opacity="0.8"/>
1169
+ <circle cx="100" cy="120" r="2.5" fill="white" opacity="0.9"/>
1170
+ <circle cx="60" cy="180" r="2" fill="white" opacity="0.7"/>
1171
+ <circle cx="120" cy="200" r="2" fill="white" opacity="0.8"/>
1172
+ <line x1="40" y1="30" x2="80" y2="50" stroke="white" opacity="0.3" stroke-width="0.5"/>
1173
+ <line x1="80" y1="50" x2="110" y2="40" stroke="white" opacity="0.3" stroke-width="0.5"/>
1174
+ <line x1="30" y1="100" x2="100" y2="120" stroke="white" opacity="0.3" stroke-width="0.5"/>
1175
+ <line x1="60" y1="180" x2="120" y2="200" stroke="white" opacity="0.3" stroke-width="0.5"/>
1176
+ </svg>
1177
+ """
1178
+ else:
1179
+ # Fallback: simple gradient
1180
+ bg_style = f"{base_style} background: linear-gradient(135deg, {primary}, {secondary});"
1181
+ bg_layer = ""
1182
+
1183
+ return f"""
1184
+ <div style="{bg_style}">
1185
+ {bg_layer}
1186
+ </div>
1187
+ """
1188
+
1189
+
1190
  def generate_background_gallery(theme_json: str = ""):
1191
  """
1192
  Generate HTML gallery of all 30 backgrounds organized by category
1193
+ Backgrounds are rendered directly with HTML/CSS using theme colors
1194
  """
1195
  from agents.flutter_screen_generator import FlutterScreenGenerator
1196
 
 
1284
  }
1285
  complexity_color = complexity_colors.get(info['complexity'], "#6c757d")
1286
 
1287
+ # Render background preview
1288
+ bg_preview = render_background_html(bg_id, info, primary, secondary, accent)
1289
 
1290
  html_parts.append(f"""
1291
+ <div style="background: white; padding: 12px; border-radius: 8px; border: 1px solid #dee2e6; display: flex; flex-direction: column; align-items: center; gap: 10px;">
1292
+ {bg_preview}
1293
+ <div style="width: 100%; text-align: center;">
1294
+ <div style="font-weight: 600; font-size: 13px; margin-bottom: 4px;">{info['name']}</div>
1295
+ <div style="font-size: 11px; color: #6c757d; margin-bottom: 6px;">
1296
+ <code style="background: #e9ecef; padding: 2px 6px; border-radius: 3px; font-size: 10px;">{bg_id}</code>
1297
+ </div>
1298
  <span style="background: {complexity_color}; color: white; padding: 2px 8px; border-radius: 10px; font-size: 10px; font-weight: 600;">
1299
  {info['complexity'].upper()}
1300
  </span>
1301
  </div>
 
 
 
 
1302
  </div>
1303
  """)
1304
 
 
1307
  html_parts.append("""
1308
  <div style="margin-top: 20px; padding: 12px; background: #e7f3ff; border-radius: 6px; border-left: 3px solid #007AFF;">
1309
  <p style="margin: 0; font-size: 13px; color: #004085;">
1310
+ <strong>💡 Anteprima Live:</strong> Tutti i 30 background sono renderizzati direttamente con i colori del tuo tema!
1311
+ Ogni preview mostra esattamente come apparirà il background nell'app con il tema selezionato.
1312
+ <br/><br/>
1313
+ <strong>📋 Per testare:</strong> Usa il selettore sotto per generare il codice Flutter/Dart completo di un background specifico
1314
+ e copiarlo su <a href="https://dartpad.dev" target="_blank" style="color: #007AFF; font-weight: 600;">DartPad</a> per vederlo in azione!
1315
  </p>
1316
  </div>
1317
  </div>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1318
  """)
1319
 
1320
  return "".join(html_parts)