File size: 17,442 Bytes
9282c17
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
import gradio as gr

from models.data_manager import DataManager
from models.image_processor import image_search_performers

_COUNTRY_FLAGS = {
    'AD': '๐Ÿ‡ฆ๐Ÿ‡ฉ', 'AE': '๐Ÿ‡ฆ๐Ÿ‡ช', 'AF': '๐Ÿ‡ฆ๐Ÿ‡ซ', 'AG': '๐Ÿ‡ฆ๐Ÿ‡ฌ', 'AI': '๐Ÿ‡ฆ๐Ÿ‡ฎ', 'AL': '๐Ÿ‡ฆ๐Ÿ‡ฑ', 'AM': '๐Ÿ‡ฆ๐Ÿ‡ฒ', 'AO': '๐Ÿ‡ฆ๐Ÿ‡ด',
    'AQ': '๐Ÿ‡ฆ๐Ÿ‡ถ', 'AR': '๐Ÿ‡ฆ๐Ÿ‡ท', 'AS': '๐Ÿ‡ฆ๐Ÿ‡ธ', 'AT': '๐Ÿ‡ฆ๐Ÿ‡น', 'AU': '๐Ÿ‡ฆ๐Ÿ‡บ', 'AW': '๐Ÿ‡ฆ๐Ÿ‡ผ', 'AX': '๐Ÿ‡ฆ๐Ÿ‡ฝ', 'AZ': '๐Ÿ‡ฆ๐Ÿ‡ฟ',
    'BA': '๐Ÿ‡ง๐Ÿ‡ฆ', 'BB': '๐Ÿ‡ง๐Ÿ‡ง', 'BD': '๐Ÿ‡ง๐Ÿ‡ฉ', 'BE': '๐Ÿ‡ง๐Ÿ‡ช', 'BF': '๐Ÿ‡ง๐Ÿ‡ซ', 'BG': '๐Ÿ‡ง๐Ÿ‡ฌ', 'BH': '๐Ÿ‡ง๐Ÿ‡ญ', 'BI': '๐Ÿ‡ง๐Ÿ‡ฎ',
    'BJ': '๐Ÿ‡ง๐Ÿ‡ฏ', 'BL': '๐Ÿ‡ง๐Ÿ‡ฑ', 'BM': '๐Ÿ‡ง๐Ÿ‡ฒ', 'BN': '๐Ÿ‡ง๐Ÿ‡ณ', 'BO': '๐Ÿ‡ง๐Ÿ‡ด', 'BQ': '๐Ÿ‡ง๐Ÿ‡ถ', 'BR': '๐Ÿ‡ง๐Ÿ‡ท', 'BS': '๐Ÿ‡ง๐Ÿ‡ธ',
    'BT': '๐Ÿ‡ง๐Ÿ‡น', 'BV': '๐Ÿ‡ง๐Ÿ‡ป', 'BW': '๐Ÿ‡ง๐Ÿ‡ผ', 'BY': '๐Ÿ‡ง๐Ÿ‡พ', 'BZ': '๐Ÿ‡ง๐Ÿ‡ฟ', 'CA': '๐Ÿ‡จ๐Ÿ‡ฆ', 'CC': '๐Ÿ‡จ๐Ÿ‡จ', 'CD': '๐Ÿ‡จ๐Ÿ‡ฉ',
    'CF': '๐Ÿ‡จ๐Ÿ‡ซ', 'CG': '๐Ÿ‡จ๐Ÿ‡ฌ', 'CH': '๐Ÿ‡จ๐Ÿ‡ญ', 'CI': '๐Ÿ‡จ๐Ÿ‡ฎ', 'CK': '๐Ÿ‡จ๐Ÿ‡ฐ', 'CL': '๐Ÿ‡จ๐Ÿ‡ฑ', 'CM': '๐Ÿ‡จ๐Ÿ‡ฒ', 'CN': '๐Ÿ‡จ๐Ÿ‡ณ',
    'CO': '๐Ÿ‡จ๐Ÿ‡ด', 'CR': '๐Ÿ‡จ๐Ÿ‡ท', 'CU': '๐Ÿ‡จ๐Ÿ‡บ', 'CV': '๐Ÿ‡จ๐Ÿ‡ป', 'CW': '๐Ÿ‡จ๐Ÿ‡ผ', 'CX': '๐Ÿ‡จ๐Ÿ‡ฝ', 'CY': '๐Ÿ‡จ๐Ÿ‡พ', 'CZ': '๐Ÿ‡จ๐Ÿ‡ฟ',
    'DE': '๐Ÿ‡ฉ๐Ÿ‡ช', 'DJ': '๐Ÿ‡ฉ๐Ÿ‡ฏ', 'DK': '๐Ÿ‡ฉ๐Ÿ‡ฐ', 'DM': '๐Ÿ‡ฉ๐Ÿ‡ฒ', 'DO': '๐Ÿ‡ฉ๐Ÿ‡ด', 'DZ': '๐Ÿ‡ฉ๐Ÿ‡ฟ', 'EC': '๐Ÿ‡ช๐Ÿ‡จ', 'EE': '๐Ÿ‡ช๐Ÿ‡ช',
    'EG': '๐Ÿ‡ช๐Ÿ‡ฌ', 'EH': '๐Ÿ‡ช๐Ÿ‡ญ', 'ER': '๐Ÿ‡ช๐Ÿ‡ท', 'ES': '๐Ÿ‡ช๐Ÿ‡ธ', 'ET': '๐Ÿ‡ช๐Ÿ‡น', 'FI': '๐Ÿ‡ซ๐Ÿ‡ฎ', 'FJ': '๐Ÿ‡ซ๐Ÿ‡ฏ', 'FK': '๐Ÿ‡ซ๐Ÿ‡ฐ',
    'FM': '๐Ÿ‡ซ๐Ÿ‡ฒ', 'FO': '๐Ÿ‡ซ๐Ÿ‡ด', 'FR': '๐Ÿ‡ซ๐Ÿ‡ท', 'GA': '๐Ÿ‡ฌ๐Ÿ‡ฆ', 'GB': '๐Ÿ‡ฌ๐Ÿ‡ง', 'GD': '๐Ÿ‡ฌ๐Ÿ‡ฉ', 'GE': '๐Ÿ‡ฌ๐Ÿ‡ช', 'GF': '๐Ÿ‡ฌ๐Ÿ‡ซ',
    'GG': '๐Ÿ‡ฌ๐Ÿ‡ฌ', 'GH': '๐Ÿ‡ฌ๐Ÿ‡ญ', 'GI': '๐Ÿ‡ฌ๐Ÿ‡ฎ', 'GL': '๐Ÿ‡ฌ๐Ÿ‡ฑ', 'GM': '๐Ÿ‡ฌ๐Ÿ‡ฒ', 'GN': '๐Ÿ‡ฌ๐Ÿ‡ณ', 'GP': '๐Ÿ‡ฌ๐Ÿ‡ต', 'GQ': '๐Ÿ‡ฌ๐Ÿ‡ถ',
    'GR': '๐Ÿ‡ฌ๐Ÿ‡ท', 'GS': '๐Ÿ‡ฌ๐Ÿ‡ธ', 'GT': '๐Ÿ‡ฌ๐Ÿ‡น', 'GU': '๐Ÿ‡ฌ๐Ÿ‡บ', 'GW': '๐Ÿ‡ฌ๐Ÿ‡ผ', 'GY': '๐Ÿ‡ฌ๐Ÿ‡พ', 'HK': '๐Ÿ‡ญ๐Ÿ‡ฐ', 'HM': '๐Ÿ‡ญ๐Ÿ‡ฒ',
    'HN': '๐Ÿ‡ญ๐Ÿ‡ณ', 'HR': '๐Ÿ‡ญ๐Ÿ‡ท', 'HT': '๐Ÿ‡ญ๐Ÿ‡น', 'HU': '๐Ÿ‡ญ๐Ÿ‡บ', 'ID': '๐Ÿ‡ฎ๐Ÿ‡ฉ', 'IE': '๐Ÿ‡ฎ๐Ÿ‡ช', 'IL': '๐Ÿ‡ฎ๐Ÿ‡ฑ', 'IM': '๐Ÿ‡ฎ๐Ÿ‡ฒ',
    'IN': '๐Ÿ‡ฎ๐Ÿ‡ณ', 'IO': '๐Ÿ‡ฎ๐Ÿ‡ด', 'IQ': '๐Ÿ‡ฎ๐Ÿ‡ถ', 'IR': '๐Ÿ‡ฎ๐Ÿ‡ท', 'IS': '๐Ÿ‡ฎ๐Ÿ‡ธ', 'IT': '๐Ÿ‡ฎ๐Ÿ‡น', 'JE': '๐Ÿ‡ฏ๐Ÿ‡ช', 'JM': '๐Ÿ‡ฏ๐Ÿ‡ฒ',
    'JO': '๐Ÿ‡ฏ๐Ÿ‡ด', 'JP': '๐Ÿ‡ฏ๐Ÿ‡ต', 'KE': '๐Ÿ‡ฐ๐Ÿ‡ช', 'KG': '๐Ÿ‡ฐ๐Ÿ‡ฌ', 'KH': '๐Ÿ‡ฐ๐Ÿ‡ญ', 'KI': '๐Ÿ‡ฐ๐Ÿ‡ฎ', 'KM': '๐Ÿ‡ฐ๐Ÿ‡ฒ', 'KN': '๐Ÿ‡ฐ๐Ÿ‡ณ',
    'KP': '๐Ÿ‡ฐ๐Ÿ‡ต', 'KR': '๐Ÿ‡ฐ๐Ÿ‡ท', 'KW': '๐Ÿ‡ฐ๐Ÿ‡ผ', 'KY': '๐Ÿ‡ฐ๐Ÿ‡พ', 'KZ': '๐Ÿ‡ฐ๐Ÿ‡ฟ', 'LA': '๐Ÿ‡ฑ๐Ÿ‡ฆ', 'LB': '๐Ÿ‡ฑ๐Ÿ‡ง', 'LC': '๐Ÿ‡ฑ๐Ÿ‡จ',
    'LI': '๐Ÿ‡ฑ๐Ÿ‡ฎ', 'LK': '๐Ÿ‡ฑ๐Ÿ‡ฐ', 'LR': '๐Ÿ‡ฑ๐Ÿ‡ท', 'LS': '๐Ÿ‡ฑ๐Ÿ‡ธ', 'LT': '๐Ÿ‡ฑ๐Ÿ‡น', 'LU': '๐Ÿ‡ฑ๐Ÿ‡บ', 'LV': '๐Ÿ‡ฑ๐Ÿ‡ป', 'LY': '๐Ÿ‡ฑ๐Ÿ‡พ',
    'MA': '๐Ÿ‡ฒ๐Ÿ‡ฆ', 'MC': '๐Ÿ‡ฒ๐Ÿ‡จ', 'MD': '๐Ÿ‡ฒ๐Ÿ‡ฉ', 'ME': '๐Ÿ‡ฒ๐Ÿ‡ช', 'MF': '๐Ÿ‡ฒ๐Ÿ‡ซ', 'MG': '๐Ÿ‡ฒ๐Ÿ‡ฌ', 'MH': '๐Ÿ‡ฒ๐Ÿ‡ญ', 'MK': '๐Ÿ‡ฒ๐Ÿ‡ฐ',
    'ML': '๐Ÿ‡ฒ๐Ÿ‡ฑ', 'MM': '๐Ÿ‡ฒ๐Ÿ‡ฒ', 'MN': '๐Ÿ‡ฒ๐Ÿ‡ณ', 'MO': '๐Ÿ‡ฒ๐Ÿ‡ด', 'MP': '๐Ÿ‡ฒ๐Ÿ‡ต', 'MQ': '๐Ÿ‡ฒ๐Ÿ‡ถ', 'MR': '๐Ÿ‡ฒ๐Ÿ‡ท', 'MS': '๐Ÿ‡ฒ๐Ÿ‡ธ',
    'MT': '๐Ÿ‡ฒ๐Ÿ‡น', 'MU': '๐Ÿ‡ฒ๐Ÿ‡บ', 'MV': '๐Ÿ‡ฒ๐Ÿ‡ป', 'MW': '๐Ÿ‡ฒ๐Ÿ‡ผ', 'MX': '๐Ÿ‡ฒ๐Ÿ‡ฝ', 'MY': '๐Ÿ‡ฒ๐Ÿ‡พ', 'MZ': '๐Ÿ‡ฒ๐Ÿ‡ฟ', 'NA': '๐Ÿ‡ณ๐Ÿ‡ฆ',
    'NC': '๐Ÿ‡ณ๐Ÿ‡จ', 'NE': '๐Ÿ‡ณ๐Ÿ‡ช', 'NF': '๐Ÿ‡ณ๐Ÿ‡ซ', 'NG': '๐Ÿ‡ณ๐Ÿ‡ฌ', 'NI': '๐Ÿ‡ณ๐Ÿ‡ฎ', 'NL': '๐Ÿ‡ณ๐Ÿ‡ฑ', 'NO': '๐Ÿ‡ณ๐Ÿ‡ด', 'NP': '๐Ÿ‡ณ๐Ÿ‡ต',
    'NR': '๐Ÿ‡ณ๐Ÿ‡ท', 'NU': '๐Ÿ‡ณ๐Ÿ‡บ', 'NZ': '๐Ÿ‡ณ๐Ÿ‡ฟ', 'OM': '๐Ÿ‡ด๐Ÿ‡ฒ', 'PA': '๐Ÿ‡ต๐Ÿ‡ฆ', 'PE': '๐Ÿ‡ต๐Ÿ‡ช', 'PF': '๐Ÿ‡ต๐Ÿ‡ซ', 'PG': '๐Ÿ‡ต๐Ÿ‡ฌ',
    'PH': '๐Ÿ‡ต๐Ÿ‡ญ', 'PK': '๐Ÿ‡ต๐Ÿ‡ฐ', 'PL': '๐Ÿ‡ต๐Ÿ‡ฑ', 'PM': '๐Ÿ‡ต๐Ÿ‡ฒ', 'PN': '๐Ÿ‡ต๐Ÿ‡ณ', 'PR': '๐Ÿ‡ต๐Ÿ‡ท', 'PS': '๐Ÿ‡ต๐Ÿ‡ธ', 'PT': '๐Ÿ‡ต๐Ÿ‡น',
    'PW': '๐Ÿ‡ต๐Ÿ‡ผ', 'PY': '๐Ÿ‡ต๐Ÿ‡พ', 'QA': '๐Ÿ‡ถ๐Ÿ‡ฆ', 'RE': '๐Ÿ‡ท๐Ÿ‡ช', 'RO': '๐Ÿ‡ท๐Ÿ‡ด', 'RS': '๐Ÿ‡ท๐Ÿ‡ธ', 'RU': '๐Ÿ‡ท๐Ÿ‡บ', 'RW': '๐Ÿ‡ท๐Ÿ‡ผ',
    'SA': '๐Ÿ‡ธ๐Ÿ‡ฆ', 'SB': '๐Ÿ‡ธ๐Ÿ‡ง', 'SC': '๐Ÿ‡ธ๐Ÿ‡จ', 'SD': '๐Ÿ‡ธ๐Ÿ‡ฉ', 'SE': '๐Ÿ‡ธ๐Ÿ‡ช', 'SG': '๐Ÿ‡ธ๐Ÿ‡ฌ', 'SH': '๐Ÿ‡ธ๐Ÿ‡ญ', 'SI': '๐Ÿ‡ธ๐Ÿ‡ฎ',
    'SJ': '๐Ÿ‡ธ๐Ÿ‡ฏ', 'SK': '๐Ÿ‡ธ๐Ÿ‡ฐ', 'SL': '๐Ÿ‡ธ๐Ÿ‡ฑ', 'SM': '๐Ÿ‡ธ๐Ÿ‡ฒ', 'SN': '๐Ÿ‡ธ๐Ÿ‡ณ', 'SO': '๐Ÿ‡ธ๐Ÿ‡ด', 'SR': '๐Ÿ‡ธ๐Ÿ‡ท', 'SS': '๐Ÿ‡ธ๐Ÿ‡ธ',
    'ST': '๐Ÿ‡ธ๐Ÿ‡น', 'SV': '๐Ÿ‡ธ๐Ÿ‡ป', 'SX': '๐Ÿ‡ธ๐Ÿ‡ฝ', 'SY': '๐Ÿ‡ธ๐Ÿ‡พ', 'SZ': '๐Ÿ‡ธ๐Ÿ‡ฟ', 'TC': '๐Ÿ‡น๐Ÿ‡จ', 'TD': '๐Ÿ‡น๐Ÿ‡ฉ', 'TF': '๐Ÿ‡น๐Ÿ‡ซ',
    'TG': '๐Ÿ‡น๐Ÿ‡ฌ', 'TH': '๐Ÿ‡น๐Ÿ‡ญ', 'TJ': '๐Ÿ‡น๐Ÿ‡ฏ', 'TK': '๐Ÿ‡น๐Ÿ‡ฐ', 'TL': '๐Ÿ‡น๐Ÿ‡ฑ', 'TM': '๐Ÿ‡น๐Ÿ‡ฒ', 'TN': '๐Ÿ‡น๐Ÿ‡ณ', 'TO': '๐Ÿ‡น๐Ÿ‡ด',
    'TR': '๐Ÿ‡น๐Ÿ‡ท', 'TT': '๐Ÿ‡น๐Ÿ‡น', 'TV': '๐Ÿ‡น๐Ÿ‡ป', 'TW': '๐Ÿ‡น๐Ÿ‡ผ', 'TZ': '๐Ÿ‡น๐Ÿ‡ฟ', 'UA': '๐Ÿ‡บ๐Ÿ‡ฆ', 'UG': '๐Ÿ‡บ๐Ÿ‡ฌ', 'UM': '๐Ÿ‡บ๐Ÿ‡ฒ',
    'US': '๐Ÿ‡บ๐Ÿ‡ธ', 'UY': '๐Ÿ‡บ๐Ÿ‡พ', 'UZ': '๐Ÿ‡บ๐Ÿ‡ฟ', 'VA': '๐Ÿ‡ป๐Ÿ‡ฆ', 'VC': '๐Ÿ‡ป๐Ÿ‡จ', 'VE': '๐Ÿ‡ป๐Ÿ‡ช', 'VG': '๐Ÿ‡ป๐Ÿ‡ฌ', 'VI': '๐Ÿ‡ป๐Ÿ‡ฎ',
    'VN': '๐Ÿ‡ป๐Ÿ‡ณ', 'VU': '๐Ÿ‡ป๐Ÿ‡บ', 'WF': '๐Ÿ‡ผ๐Ÿ‡ซ', 'WS': '๐Ÿ‡ผ๐Ÿ‡ธ', 'YE': '๐Ÿ‡พ๐Ÿ‡ช', 'YT': '๐Ÿ‡พ๐Ÿ‡น', 'ZA': '๐Ÿ‡ฟ๐Ÿ‡ฆ', 'ZM': '๐Ÿ‡ฟ๐Ÿ‡ฒ',
    'ZW': '๐Ÿ‡ฟ๐Ÿ‡ผ',
}

class WebInterface:
    def __init__(self, data_manager: DataManager, default_threshold: float = 50):
        """
        Initialize the web interface.

        Parameters:
        data_manager: DataManager instance
        default_threshold: Default confidence threshold
        """
        self.data_manager = data_manager
        self.default_threshold = default_threshold

    def get_country_flag(self, country_code):
        if not country_code or len(country_code) != 2:
            return ""
        return _COUNTRY_FLAGS.get(country_code.upper(), "")

    def multiple_image_search(self, img, threshold, results):
        """Wrapper for the multiple image search function"""
        try:
            return image_search_performers(img, self.data_manager, threshold / 100.0, results)
        except ValueError as e:
            if "No faces found" in str(e):
                return {"error": "No faces detected in the uploaded image. Please try uploading an image with visible faces."}
            else:
                raise e

    def format_results_for_visual_display(self, json_results):
        """
        Convert JSON results to HTML for visual display.

        Parameters:
        json_results: List of face detection results from image_search_performers

        Returns:
        str: HTML content
        """
        if not json_results:
            return "<p>No faces detected or no matches found.</p>"

        # Handle error case
        if isinstance(json_results, dict) and "error" in json_results:
            return f"""
            <div class="performer-card">
                <div class="face-info">
                    <h3 style="color: #ff6b6b;">Error</h3>
                    <p>{json_results['error']}</p>
                </div>
            </div>
            """

        html_parts = []
        
        html_parts.append("""
        <style>
        body, .gradio-container {
            background-color: #1e1e1e !important;
            color: #d4d4d4 !important;
        }
        .performer-card {
            border: 1px solid #404040;
            border-radius: 12px;
            padding: 24px;
            margin: 16px 0;
            background: #2d2d2d;
            box-shadow: 0 4px 12px rgba(0,0,0,0.3);
            color: #d4d4d4;
        }
        .face-info {
            background: #3c3c3c;
            padding: 20px;
            border-radius: 8px;
            margin-bottom: 24px;
            border: 1px solid #4a4a4a;
            display: flex;
            align-items: flex-start;
            gap: 20px;
        }
        .face-info-content {
            flex: 1;
        }
        .face-info h3 {
            color: #ffffff;
            margin-top: 0;
            font-size: 1.4em;
        }
        .performer-grid {
            display: grid;
            grid-template-columns: repeat(auto-fit, minmax(350px, 1fr));
            gap: 24px;
            margin-top: 16px;
        }
        .performer-item {
            border: 1px solid #4a4a4a;
            border-radius: 12px;
            padding: 24px;
            background: #333333;
            text-align: center;
            transition: all 0.3s ease;
            box-shadow: 0 2px 8px rgba(0,0,0,0.2);
            display: flex;
            flex-direction: column;
            align-items: center;
        }
        .performer-item:hover {
            border-color: #569cd6;
            box-shadow: 0 4px 16px rgba(0,0,0,0.4);
            transform: translateY(-2px);
        }
        .performer-image {
            width: 120px;
            height: 120px;
            border-radius: 12px;
            object-fit: cover;
            margin: 0 auto 16px auto;
            display: block;
            border: 2px solid #4a4a4a;
            transition: all 0.3s ease;
            text-align: center;
        }
        .performer-image:hover {
            border-color: #569cd6;
            transform: scale(1.05);
        }
        .performer-item h4 {
            color: #ffffff;
            margin: 16px 0 8px 0;
            font-size: 1.2em;
        }
        .performer-item h4 a {
            color: #569cd6;
            text-decoration: none;
            transition: color 0.3s ease;
        }
        .performer-item h4 a:hover {
            color: #9cdcfe;
            text-decoration: underline;
        }
        .performer-item p {
            color: #cccccc;
            margin: 8px 0;
        }
        .performer-item small {
            color: #999999;
        }
        .confidence-bar {
            background: #404040;
            border-radius: 12px;
            overflow: hidden;
            height: 28px;
            margin: 12px 0;
            border: 1px solid #4a4a4a;
            width: 100%;
            max-width: 200px;
        }
        .confidence-fill {
            height: 100%;
            transition: width 0.5s ease;
            text-align: center;
            line-height: 28px;
            color: white;
            font-size: 13px;
            font-weight: bold;
            text-shadow: 0 1px 2px rgba(0,0,0,0.5);
        }
        .high-confidence { 
            background: linear-gradient(135deg, #4caf50, #66bb6a);
        }
        .medium-confidence { 
            background: linear-gradient(135deg, #ff9800, #ffb74d);
        }
        .low-confidence { 
            background: linear-gradient(135deg, #f44336, #ef5350);
        }
        .face-info p strong {
            color: #9cdcfe;
        }
        .country-flag {
            font-size: 1.2em;
            margin-right: 6px;
            vertical-align: middle;
        }
        .detected-face img {
            width: 120px;
            height: 120px;
            border-radius: 12px;
            object-fit: cover;
            border: 2px solid #569cd6;
            box-shadow: 0 4px 12px rgba(0,0,0,0.3);
        }
        </style>
        """)
        
        for i, face_result in enumerate(json_results):
            face_confidence = face_result['confidence']
            performers = face_result['performers']
            face_image_b64 = f"data:image/jpeg;base64,{face_result['image']}"

            html_parts.append(f"""
            <div class="performer-card">
                <div class="face-info">
                    <div class="detected-face">
                        <img src="{face_image_b64}" alt="Detected Face {i+1}">
                    </div>
                    <div class="face-info-content">
                        <h3>Face {i+1}</h3>
                        <p><strong>Detection Confidence:</strong> {face_confidence:.1%}</p>
                        <p><strong>Matches Found:</strong> {len(performers)}</p>
                    </div>
                </div>
            """)
            
            if performers:
                html_parts.append('<div class="performer-grid">')
                for performer in performers:
                    confidence_class = "high-confidence" if performer['confidence'] >= 80 else "medium-confidence" if performer['confidence'] >= 60 else "low-confidence"
                    country_code = performer.get('country', '')
                    country_flag = self.get_country_flag(country_code)
                    country_display = f"{country_flag} {country_code}" if country_flag else (country_code if country_code else 'Unknown')
                    
                    html_parts.append(f"""
                    <div class="performer-item">
                        <img src="{performer['image']}" alt="{performer['name']}" class="performer-image" onerror="this.style.display='none'">
                        <h4><a href="{performer['performer_url']}" target="_blank">{performer['name']}</a></h4>
                        <p><strong>Country:</strong> {country_display}</p>
                        <div class="confidence-bar">
                            <div class="confidence-fill {confidence_class}" style="width: {performer['confidence']}%">
                                {performer['confidence']}%
                            </div>
                        </div>
                        <p><small>Distance: {performer.get('distance', 'N/A')}</small></p>
                    </div>
                    """)
                html_parts.append('</div>')
            else:
                html_parts.append('<p><em>No performer matches found for this face.</em></p>')
            
            html_parts.append('</div>')
        
        return ''.join(html_parts)

    def multiple_image_search_with_visual(self, img, threshold, results):
        """Run face search and return HTML for visual display."""
        try:
            json_results = self.multiple_image_search(img, threshold, results)
            return self.format_results_for_visual_display(json_results)
        except Exception as e:
            return f"<div class='performer-card'><h3>Error</h3><p>{str(e)}</p></div>"

    def _create_json_search_interface(self):
        """Create the JSON API search interface"""
        with gr.Blocks() as interface:
            gr.Markdown("# Face Recognition API")
            gr.Markdown("Upload an image and get JSON results - perfect for API integration.")

            with gr.Row():
                with gr.Column():
                    img_input = gr.Image(type="pil")
                    threshold = gr.Slider(
                        label="threshold",
                        minimum=1,
                        maximum=100,
                        value=self.default_threshold,
                        step=1
                    )
                    results_count = gr.Slider(
                        label="results",
                        minimum=0,
                        maximum=50,
                        value=3,
                        step=1
                    )
                    search_btn = gr.Button("Search")

                with gr.Column():
                    json_output = gr.JSON(label="JSON Results")

            search_btn.click(
                fn=self.multiple_image_search,
                inputs=[img_input, threshold, results_count],
                outputs=json_output,
                api_name="multiple_image_search"
            )

        return interface

    def _create_visual_search_interface(self):
        """Create the visual search interface"""
        with gr.Blocks() as interface:
            gr.Markdown("# Who is in the photo?")
            gr.Markdown("Upload an image of a person(s) and we'll show you who it is with photos and details.")

            with gr.Row():
                with gr.Column():
                    img_input = gr.Image(type="pil")
                    threshold = gr.Slider(
                        label="threshold",
                        minimum=1,
                        maximum=100,
                        value=self.default_threshold,
                        step=1
                    )
                    results_count = gr.Slider(
                        label="results",
                        minimum=0,
                        maximum=50,
                        value=3,
                        step=1
                    )
                    search_btn = gr.Button("Search")

                with gr.Column():
                    performer_info = gr.HTML(
                        label="Performer Information",
                        value="<p>Upload an image and click search to see results.</p>"
                    )

            search_btn.click(
                fn=self.multiple_image_search_with_visual,
                inputs=[img_input, threshold, results_count],
                outputs=[performer_info],
                api_name="multiple_image_search_with_visual"
            )

        return interface

    def launch(self, server_name="0.0.0.0", server_port=7860, share=True):
        """Launch the web interface"""
        with gr.Blocks(
            css="""
            .gradio-container {
                background-color: #1e1e1e !important;
                color: #d4d4d4 !important;
            }
            .dark {
                --background-fill-primary: #2d2d2d;
                --background-fill-secondary: #3c3c3c;
                --border-color-primary: #404040;
                --block-title-text-color: #ffffff;
                --body-text-color: #d4d4d4;
            }
            """
        ) as demo:
            with gr.Tabs():
                with gr.TabItem("Visual Search"):
                    self._create_visual_search_interface()
                with gr.TabItem("JSON API"):
                    self._create_json_search_interface()

        demo.queue().launch(server_name=server_name, server_port=server_port, share=share, ssr_mode=False)