LYL1015 commited on
Commit
b95d42e
Β·
verified Β·
1 Parent(s): f734b47

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +159 -871
app.py CHANGED
@@ -48,7 +48,7 @@ from utils.lua_converter import LuaConverter
48
  from transformers import Qwen2VLForConditionalGeneration, AutoProcessor
49
  from qwen_vl_utils import process_vision_info
50
  import torch
51
- from utils.lua2lrt import lua_to_lrtemplate
52
  from huggingface_hub import snapshot_download
53
  import spaces
54
 
@@ -1102,888 +1102,183 @@ def process_analysis_pipeline_stream(image_dict, user_prompt, max_new_tokens, to
1102
  # Create Gradio interface
1103
  def create_interface():
1104
  """
1105
- Create and configure the modern chat-style Gradio web interface
1106
 
1107
  Returns:
1108
- gr.Blocks: Configured Gradio interface with chat-style layout
1109
  """
1110
- # Custom CSS styles mimicking modern chat interfaces
1111
- custom_css = """
1112
- /* Global styles */
1113
- .gradio-container {
1114
- max-width: 1200px !important;
1115
- margin: 0 auto !important;
1116
- font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif !important;
1117
- }
1118
 
1119
- /* Header styles - clean white background */
1120
- .app-header {
1121
- background: white;
1122
- color: #1f2937;
1123
- padding: 0.1rem 2rem;
1124
- border-radius: 12px 12px 0 0;
1125
- margin-bottom: 0 !important;
1126
- text-align: center;
1127
- border: 1px solid #e5e7eb;
1128
- border-bottom: 1px solid #e5e7eb;
1129
- }
1130
-
1131
- .app-title {
1132
- display: flex;
1133
- align-items: center;
1134
- justify-content: center;
1135
- font-size: 1.6rem;
1136
- font-weight: 600;
1137
- margin: 0;
1138
- color: #1f2937;
1139
- }
1140
- .centered-image {
1141
- display: flex !important;
1142
- justify-content: center !important;
1143
- align-items: center !important;
1144
- margin: auto !important;
1145
- }
1146
- .centered-image img {
1147
- max-width: 100% !important;
1148
- max-height: 100% !important;
1149
- object-fit: contain;
1150
- }
1151
- .jarvis_image_container {
1152
- display: flex !important;
1153
- justify-content: center !important;
1154
- background: white;
1155
- align-items: center !important;
1156
- }
1157
- .tight-container {
1158
- padding: 0 !important;
1159
- margin: 0 !important;
1160
- height: fit-content !important; /* Container height adapts to content */
1161
- }
1162
- /* Main chat area - ensure borders are visible and connect seamlessly with header */
1163
- .chat-container {
1164
- height: 600px;
1165
- border: 1px solid #e5e7eb !important;
1166
- border-top: 1px solid #e5e7eb !important;
1167
- border-radius: 0 0 12px 12px;
1168
- background: #ffffff !important;
1169
- margin-top: -1px !important;
1170
- margin-bottom: 0 !important;
1171
- overflow-y: auto !important;
1172
- max-height: none !important;
1173
- }
1174
-
1175
- /* Chat message styles */
1176
- .chatbot {
1177
- border: 1px solid #e5e7eb !important;
1178
- border-top: none !important;
1179
- background: #ffffff !important;
1180
- border-radius: 0 0 12px 12px !important;
1181
- margin-top: 0 !important;
1182
- margin-bottom: 0 !important;
1183
- overflow-y: auto !important;
1184
- max-height: none !important;
1185
- }
1186
-
1187
- /* Reduce spacing between messages */
1188
- .chatbot .message {
1189
- margin-bottom: 0 !important;
1190
- padding-bottom: 0 !important;
1191
- margin-top: 0 !important;
1192
- padding-top: 0 !important;
1193
- }
1194
-
1195
- /* Reduce spacing between message containers */
1196
- .chatbot .block {
1197
- gap: 0 !important;
1198
- margin-bottom: -8px !important;
1199
- }
1200
-
1201
- /* Reduce spacing between thinking and recommendation messages */
1202
- .chatbot .message-wrap {
1203
- margin-bottom: -8px !important;
1204
- }
1205
-
1206
- /* Reduce spacing between adjacent messages */
1207
- .chatbot .message + .message {
1208
- margin-top: -10px !important;
1209
- }
1210
-
1211
- /* Reduce spacing between bot messages */
1212
- .chatbot .bot-message {
1213
- margin-top: -5px !important;
1214
- }
1215
-
1216
- /* Special control over spacing between thinking and recommendation messages */
1217
- .chatbot .message:nth-child(odd) + .message:nth-child(even) {
1218
- margin-top: -15px !important;
1219
- }
1220
-
1221
- /* Ensure message content area fully expands */
1222
- .chatbot .message .content {
1223
- max-height: none !important;
1224
- overflow: visible !important;
1225
- white-space: pre-wrap !important;
1226
- word-wrap: break-word !important;
1227
- line-height: 1.2 !important;
1228
- margin: 0 !important;
1229
- padding: 0 !important;
1230
- }
1231
-
1232
- /* Remove any height limitations */
1233
- .chatbot .message-bubble {
1234
- max-height: none !important;
1235
- overflow: visible !important;
1236
- margin: 0 !important;
1237
- padding: 0 !important;
1238
- }
1239
-
1240
- /* Ensure entire chat area can scroll, but individual messages fully expand */
1241
- .chatbot .messages-container {
1242
- max-height: 550px !important;
1243
- overflow-y: auto !important;
1244
- }
1245
-
1246
- /* Image styles in user messages */
1247
- .chatbot .message img {
1248
- max-width: 300px !important;
1249
- max-height: 400px !important;
1250
- border-radius: 12px !important;
1251
- box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1) !important;
1252
- margin-bottom: 4px !important;
1253
- margin-top: 4px !important;
1254
- object-fit: cover !important;
1255
- display: block !important;
1256
- }
1257
-
1258
- /* Processed image styles - larger display for results */
1259
- .chatbot .message img[src*="lr_processed"] {
1260
- max-width: 450px !important;
1261
- max-height: 500px !important;
1262
- border: 2px solid #e5e7eb !important;
1263
- border-radius: 16px !important;
1264
- box-shadow: 0 8px 16px rgba(0, 0, 0, 0.15) !important;
1265
- margin: 8px 0 !important;
1266
- object-fit: contain !important;
1267
- }
1268
-
1269
- /* All processed result images - enhance visibility */
1270
- .chatbot .message img[src*="results/"] {
1271
- max-width: 500px !important;
1272
- max-height: 600px !important;
1273
- border: 3px solid #3b82f6 !important;
1274
- border-radius: 20px !important;
1275
- box-shadow: 0 10px 20px rgba(59, 130, 246, 0.2) !important;
1276
- margin: 12px auto !important;
1277
- object-fit: contain !important;
1278
- display: block !important;
1279
- background: white !important;
1280
- padding: 4px !important;
1281
- }
1282
-
1283
- /* Enhanced display for assistant images */
1284
- .chatbot .bot-message img {
1285
- border: 2px solid #059669 !important;
1286
- border-radius: 16px !important;
1287
- box-shadow: 0 6px 12px rgba(5, 150, 105, 0.15) !important;
1288
- max-width: 100% !important;
1289
- height: auto !important;
1290
- }
1291
-
1292
- /* Processed image container styling */
1293
- .chatbot .message .processed-image-container {
1294
- display: flex !important;
1295
- flex-direction: column !important;
1296
- align-items: center !important;
1297
- margin: 8px 0 !important;
1298
- padding: 8px !important;
1299
- background: #f8fafc !important;
1300
- border-radius: 12px !important;
1301
- border: 1px solid #e2e8f0 !important;
1302
- }
1303
-
1304
- /* Multimodal message container */
1305
- .chatbot .message-content {
1306
- display: flex !important;
1307
- flex-direction: column !important;
1308
- gap: 2px !important;
1309
- }
1310
-
1311
- .chatbot .message .multimodal-content {
1312
- display: flex !important;
1313
- flex-direction: column !important;
1314
- gap: 4px !important;
1315
- }
1316
-
1317
- .chatbot .message .multimodal-content img {
1318
- max-width: 100% !important;
1319
- height: auto !important;
1320
- border-radius: 12px !important;
1321
- box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1) !important;
1322
- margin: 2px 0 !important;
1323
- }
1324
-
1325
- .chatbot .message .multimodal-content .text-content {
1326
- font-size: 0.95rem !important;
1327
- line-height: 1.2 !important;
1328
- color: inherit !important;
1329
- margin: 0 !important;
1330
- padding: 0 !important;
1331
- }
1332
-
1333
- /* User message bubble styles */
1334
- .chatbot .user-message {
1335
- background: #f3f4f6 !important;
1336
- color: #1f2937 !important;
1337
- border-radius: 18px 18px 4px 18px !important;
1338
- padding: 8px 12px !important;
1339
- margin: 4px 0 !important;
1340
- max-width: 80% !important;
1341
- margin-left: auto !important;
1342
- border: 1px solid #e5e7eb !important;
1343
- }
1344
-
1345
- /* AI message bubble styles */
1346
- .chatbot .bot-message {
1347
- background: white !important;
1348
- color: #374151 !important;
1349
- border-radius: 18px 18px 18px 4px !important;
1350
- padding: 8px 12px !important;
1351
- margin: 2px 0 !important;
1352
- max-width: 80% !important;
1353
- border: 1px solid #e5e7eb !important;
1354
- box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1) !important;
1355
- margin-top: -5px !important;
1356
- margin-bottom: 0 !important;
1357
- }
1358
-
1359
- /* Special styles for titles */
1360
- .chatbot .message .content strong {
1361
- display: inline-block !important;
1362
- margin-bottom: 0 !important;
1363
- padding-bottom: 0 !important;
1364
- }
1365
-
1366
- /* Special styles for content following Thinking and Recommendations titles */
1367
- .chatbot .message .content strong + br {
1368
- display: none !important;
1369
- }
1370
-
1371
- /* Further reduce spacing between thinking and recommendation messages */
1372
- .chatbot .message:nth-last-child(n+2) {
1373
- margin-bottom: -12px !important;
1374
- }
1375
-
1376
- /* Override paragraph spacing in messages */
1377
- .chatbot .message p {
1378
- margin: 0 !important;
1379
- padding: 0 !important;
1380
- }
1381
-
1382
- /* Override list spacing in messages */
1383
- .chatbot .message ul,
1384
- .chatbot .message ol {
1385
- margin-top: 2px !important;
1386
- margin-bottom: 2px !important;
1387
- padding-left: 20px !important;
1388
- }
1389
-
1390
- .chatbot .message li {
1391
- margin: 0 !important;
1392
- padding: 0 !important;
1393
- line-height: 1.2 !important;
1394
- }
1395
-
1396
- /* Reduce spacing between emoji and title */
1397
- .chatbot .message .content span {
1398
- margin-right: 0 !important;
1399
- padding-right: 0 !important;
1400
- }
1401
-
1402
- /* Reduce spacing between title and content */
1403
- .chatbot .message .content strong + span {
1404
- margin-left: 0 !important;
1405
- padding-left: 0 !important;
1406
- }
1407
-
1408
- /* Input area styles */
1409
- .input-section {
1410
- background: white;
1411
- padding: 1.5rem;
1412
- border-radius: 12px;
1413
- box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
1414
- margin-top: 1rem;
1415
- border: 1px solid #e5e7eb;
1416
- }
1417
-
1418
- .image-upload-area {
1419
- border: 2px dashed #cbd5e1;
1420
- border-radius: 8px;
1421
- padding: 1.5rem;
1422
- margin-bottom: 1rem;
1423
- transition: all 0.3s ease;
1424
- background: #f8fafc;
1425
- }
1426
-
1427
- .image-upload-area:hover {
1428
- border-color: #667eea;
1429
- background: #f1f5f9;
1430
- }
1431
-
1432
- /* Ensure the image upload component fits within the upload area */
1433
- .image-upload-area .gradio-image {
1434
- border: none !important;
1435
- background: transparent !important;
1436
- margin: 0 !important;
1437
- padding: 0 !important;
1438
- }
1439
-
1440
- .image-upload-area .image-container {
1441
- border: none !important;
1442
- background: transparent !important;
1443
- }
1444
-
1445
- /* Remove borders from all child components in upload area */
1446
- .image-upload-area > * {
1447
- border: none !important;
1448
- }
1449
-
1450
- .image-upload-area .gradio-group {
1451
- border: none !important;
1452
- background: transparent !important;
1453
- margin: 0 !important;
1454
- padding: 0 !important;
1455
- }
1456
-
1457
- .image-upload-area .gradio-column {
1458
- border: none !important;
1459
- background: transparent !important;
1460
- }
1461
-
1462
- /* Style the upload drop zone */
1463
- .image-upload-area .upload-zone {
1464
- border: 1px solid #e2e8f0 !important;
1465
- border-radius: 6px !important;
1466
- background: white !important;
1467
- margin-top: 0.5rem !important;
1468
- }
1469
-
1470
- /* Simplified button styles */
1471
- .simple-button {
1472
- background: #f8fafc !important;
1473
- border: 1px solid #e2e8f0 !important;
1474
- border-radius: 8px !important;
1475
- color: #475569 !important;
1476
- font-weight: 500 !important;
1477
- padding: 0.75rem 1.5rem !important;
1478
- transition: all 0.2s ease !important;
1479
- }
1480
-
1481
- .simple-button:hover {
1482
- background: #e2e8f0 !important;
1483
- border-color: #cbd5e1 !important;
1484
- color: #334155 !important;
1485
- }
1486
-
1487
- .primary-simple-button {
1488
- background: #667eea !important;
1489
- border: 1px solid #667eea !important;
1490
- border-radius: 8px !important;
1491
- color: white !important;
1492
- font-weight: 500 !important;
1493
- padding: 0.75rem 2rem !important;
1494
- transition: all 0.2s ease !important;
1495
- }
1496
-
1497
- .primary-simple-button:hover {
1498
- background: #5a67d8 !important;
1499
- border-color: #5a67d8 !important;
1500
- }
1501
-
1502
- /* Text input styles */
1503
- .prompt-input {
1504
- border-radius: 8px !important;
1505
- border: 1px solid #e1e5e9 !important;
1506
- padding: 0.75rem !important;
1507
- font-size: 0.95rem !important;
1508
- }
1509
-
1510
- .prompt-input:focus {
1511
- border-color: #667eea !important;
1512
- box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1) !important;
1513
- }
1514
-
1515
- /* System prompt area */
1516
- .system-prompt-section {
1517
- margin-top: 2rem;
1518
- padding: 1rem;
1519
- background: #f8fafc;
1520
- border-radius: 8px;
1521
- border: 1px solid #e1e5e9;
1522
- }
1523
-
1524
- /* Example button styles */
1525
- .example-buttons button {
1526
- background: #f1f5f9 !important;
1527
- border: 1px solid #e2e8f0 !important;
1528
- border-radius: 6px !important;
1529
- padding: 8px 12px !important;
1530
- font-size: 0.85rem !important;
1531
- color: #475569 !important;
1532
- transition: all 0.2s ease !important;
1533
- }
1534
-
1535
- .example-buttons button:hover {
1536
- background: #e2e8f0 !important;
1537
- border-color: #667eea !important;
1538
- color: #667eea !important;
1539
- }
1540
-
1541
- /* Welcome screen styles */
1542
- .welcome-message {
1543
- text-align: center;
1544
- padding: 1rem;
1545
- color: #64748b;
1546
- }
1547
-
1548
- .welcome-title {
1549
- font-size: 1.5rem;
1550
- font-weight: 600;
1551
- color: #334155;
1552
- margin-bottom: 0.5rem;
1553
- }
1554
-
1555
- .welcome-subtitle {
1556
- font-size: 1rem;
1557
- margin-bottom: 1rem;
1558
- line-height: 1.4;
1559
- }
1560
-
1561
- .welcome-features {
1562
- display: grid;
1563
- grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
1564
- gap: 0.5rem;
1565
- margin-top: 1rem;
1566
- }
1567
-
1568
- .welcome-feature {
1569
- background: white;
1570
- padding: 0.75rem;
1571
- border-radius: 8px;
1572
- border: 1px solid #e2e8f0;
1573
- text-align: center;
1574
- }
1575
-
1576
- .welcome-feature-icon {
1577
- font-size: 1.5rem;
1578
- margin-bottom: 0.25rem;
1579
- }
1580
-
1581
- .welcome-feature-title {
1582
- font-weight: 600;
1583
- margin-bottom: 0.15rem;
1584
- color: #334155;
1585
- }
1586
-
1587
- .welcome-feature-desc {
1588
- font-size: 0.85rem;
1589
- color: #64748b;
1590
- }
1591
-
1592
- /* Responsive design */
1593
- @media (max-width: 768px) {
1594
- .gradio-container {
1595
- margin: 0 1rem !important;
1596
- }
1597
-
1598
- .app-header {
1599
- padding: 0.75rem 1rem !important;
1600
- }
1601
-
1602
- .app-title {
1603
- font-size: 1.4rem !important;
1604
- }
1605
-
1606
- .input-section {
1607
- padding: 1rem !important;
1608
- }
1609
 
1610
- .chatbot .message img {
1611
- max-width: 250px !important;
1612
- max-height: 300px !important;
1613
- }
1614
-
1615
- .chatbot .user-message,
1616
- .chatbot .bot-message {
1617
- max-width: 90% !important;
1618
- }
1619
-
1620
- .welcome-features {
1621
- grid-template-columns: 1fr !important;
1622
- }
1623
- }
1624
-
1625
- /* Remove gap between header and chatbot */
1626
- .app-header + .gradio-row {
1627
- margin-top: 0 !important;
1628
- gap: 0 !important;
1629
- }
1630
-
1631
- /* Ensure no gaps between Row components */
1632
- .gradio-row {
1633
- gap: 0 !important;
1634
- margin: 0 !important;
1635
- }
1636
-
1637
- /* Remove unnecessary margins and padding */
1638
- .block {
1639
- margin: 0 !important;
1640
- padding: 0 !important;
1641
- }
1642
-
1643
- /* Ensure header row has no gaps */
1644
- .gradio-container > .gradio-row:first-child {
1645
- margin: 0 !important;
1646
- padding: 0 !important;
1647
- }
1648
-
1649
- /* Use negative margin to force components closer - most aggressive approach */
1650
- .chat-container {
1651
- margin-top: -30px !important;
1652
- }
1653
-
1654
- /* Ensure row containing chatbot has no top margin */
1655
- .gradio-container > .gradio-row:nth-child(2) {
1656
- margin-top: 0 !important;
1657
- padding-top: 0 !important;
1658
- }
1659
-
1660
- /* Enforce message interval constraints */
1661
- .chatbot .message-wrap {
1662
- margin-bottom: -30px !important;
1663
- position: relative !important;
1664
- z-index: 1 !important;
1665
- }
1666
-
1667
- /* Enforce reduced spacing between adjacent messages */
1668
- .chatbot .message + .message {
1669
- margin-top: -30px !important;
1670
- }
1671
-
1672
- /* Special constraints for bot messages */
1673
- .chatbot .bot-message {
1674
- background: white !important;
1675
- color: #374151 !important;
1676
- border-radius: 18px 18px 18px 4px !important;
1677
- padding: 8px 12px !important;
1678
- margin: 0 !important;
1679
- max-width: 80% !important;
1680
- border: 1px solid #e5e7eb !important;
1681
- box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1) !important;
1682
- margin-top: -15px !important;
1683
- margin-bottom: -10px !important;
1684
- position: relative !important;
1685
- z-index: 0 !important;
1686
- }
1687
-
1688
- /* Enforce removal of whitespace between messages */
1689
- .chatbot .block {
1690
- gap: 0 !important;
1691
- margin: 0 !important;
1692
- padding: 0 !important;
1693
- }
1694
-
1695
- /* Enforce message container constraints */
1696
- .chatbot .messages-container {
1697
- display: flex !important;
1698
- flex-direction: column !important;
1699
- gap: 0 !important;
1700
- }
1701
-
1702
- /* Enforce removal of spacing between messages */
1703
- .chatbot .message {
1704
- margin: 0 !important;
1705
- padding: 0 !important;
1706
- }
1707
-
1708
- /* Enforce removal of spacing between title and content */
1709
- .chatbot .message .content {
1710
- display: inline-block !important;
1711
- }
1712
-
1713
- /* Special styles for titles */
1714
- .chatbot .message .content strong {
1715
- display: inline-block !important;
1716
- margin: 0 !important;
1717
- padding: 0 !important;
1718
- }
1719
-
1720
- /* Extreme reduction of spacing between thinking and recommendation messages */
1721
- .chatbot .message:nth-child(n+2):nth-child(-n+3) {
1722
- margin-top: -50px !important;
1723
- }
1724
-
1725
- /* Use transform to move element position */
1726
- .chatbot .message:nth-child(3) {
1727
- transform: translateY(-30px) !important;
1728
- }
1729
-
1730
- /* Use negative margin to force elements overlap */
1731
- .chatbot .message:nth-child(2) {
1732
- margin-bottom: -40px !important;
1733
- }
1734
-
1735
- /* Use absolute positioning to control element position */
1736
- .chatbot .messages-container {
1737
- position: relative !important;
1738
- }
1739
-
1740
- /* Enforce removal of any potential spacing */
1741
- .chatbot * {
1742
- margin-bottom: 0 !important;
1743
- }
1744
- """
1745
-
1746
- with gr.Blocks(
1747
- title="JarvisArt",
1748
- css=custom_css
1749
- ) as demo:
1750
 
1751
- # Header area
1752
- with gr.Row(elem_classes="app-header"):
1753
- gr.HTML("""
1754
- <div class="app-title">
1755
- <svg t="1748332876263" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg"
1756
- width="24" height="24" style="vertical-align: middle; margin-right: 8px;">
1757
- <path d="M938.56 511.36a238.72 238.72 0 0 1-238.72 238.72H659.2c-35.84 0-70.08-14.72-95.04-40.32-2.24-2.24-4.16-4.48-7.04-7.04l-6.08-7.36a130.176 130.176 0 0 0-65.28-42.24 131.456 131.456 0 0 0-149.12 58.88L304 767.68c-9.28 15.68-22.4 28.16-38.08 37.12a104.48 104.48 0 0 1-113.28-7.04c-17.6-12.8-31.04-31.68-37.76-53.44-19.2-64-28.8-130.24-28.8-196.8v-35.84c0-117.76 47.68-224.32 124.8-301.44s183.68-124.8 301.44-124.8c104.96 0 201.28 38.08 275.52 101.12l-47.36 73.6-74.24 114.88-44.48 68.48c-51.2 0.64-92.8 42.24-92.8 93.76 0 13.44 2.88 26.24 8 37.76 12.48 28.16 38.4 49.28 69.76 54.4 5.12 0.96 10.56 1.6 16 1.6 51.84 0 93.76-41.92 93.76-93.76 0-25.28-9.92-48.32-26.24-64.96l133.44-251.2c71.36 75.84 114.88 178.24 114.88 290.24z" fill="#E2CCA8"></path>
1758
- <path d="M564.16 709.76l-11.52 21.76c-10.24 19.2-31.36 28.48-51.52 24.96-3.52-3.52-7.36-6.08-11.52-8.64-5.44-3.2-10.88-5.44-16.32-7.04-14.72-16-17.28-40.64-4.8-59.52l18.24-28.16a133.12 133.12 0 0 1 65.28 42.24l6.08 7.36 6.08 7.04z" fill="#AA571B"></path>
1759
- <path d="M517.44 852.8c-21.12 36.8-102.08 108.16-138.88 87.04-36.8-21.12-15.04-127.04 6.08-163.84a76.832 76.832 0 0 1 104.64-28.16c4.16 2.24 8 5.12 11.52 8.64 27.84 23.04 35.52 63.68 16.64 96.32z" fill="#F2C05C"></path>
1760
- <path d="M231.04 639.36m-59.52 0a59.52 59.52 0 1 0 119.04 0 59.52 59.52 0 1 0-119.04 0Z" fill="#61A838"></path>
1761
- <path d="M265.28 417.6m-76.8 0a76.8 76.8 0 1 0 153.6 0 76.8 76.8 0 1 0-153.6 0Z" fill="#FF737D"></path>
1762
- <path d="M435.52 247.36m-76.8 0a76.8 76.8 0 1 0 153.6 0 76.8 76.8 0 1 0-153.6 0Z" fill="#FAAD14"></path>
1763
- <path d="M740.48 259.84l-74.24 114.88a76.768 76.768 0 0 1-68.8-76.48c0-42.56 34.24-76.8 76.8-76.8 28.16 0.32 53.12 15.68 66.24 38.4z" fill="#40A9FF"></path>
1764
- </svg>
1765
- <span>JarvisArt</span>
1766
- </div>
1767
- """)
1768
- # Main chat area
1769
  with gr.Row():
1770
  with gr.Column(scale=1):
1771
- # Create initial welcome interface - fixed to messages format
1772
- initial_welcome = [
1773
- {
1774
- "role": "assistant",
1775
- "content": """<div class="welcome-message">
1776
- <div class="welcome-title">πŸ‘‹ Welcome to JarvisArt!</div>
1777
- <div class="welcome-subtitle">Your AI-powered photo editing assistant is ready to help you transform your images with professional recommendations.</div>
1778
- <div class="welcome-features">
1779
- <div class="welcome-feature">
1780
- <div class="welcome-feature-icon">πŸ“Έ</div>
1781
- <div class="welcome-feature-title">Upload Image</div>
1782
- <div class="welcome-feature-desc">Upload any photo you'd like to enhance</div>
1783
- </div>
1784
- <div class="welcome-feature">
1785
- <div class="welcome-feature-icon">✨</div>
1786
- <div class="welcome-feature-title">Describe Vision</div>
1787
- <div class="welcome-feature-desc">Tell me your creative vision and style preferences</div>
1788
- </div>
1789
- <div class="welcome-feature">
1790
- <div class="welcome-feature-icon">🎨</div>
1791
- <div class="welcome-feature-title">Get Recommendations</div>
1792
- <div class="welcome-feature-desc">Receive detailed editing suggestions tailored to your needs</div>
1793
- </div>
1794
- </div>
1795
- </div>"""
1796
- }
1797
- ]
1798
-
1799
- chatbot = gr.Chatbot(
1800
- value=initial_welcome,
1801
- label="",
1802
- show_label=False,
1803
- elem_classes="chat-container",
1804
- height=600,
1805
- avatar_images=(USER_AVATAR_PATH, AI_AVATAR_PATH),
1806
- show_copy_button=True,
1807
- type='messages' # Use new message format to avoid deprecation warnings
1808
  )
1809
-
1810
- # Input area
1811
- with gr.Row(elem_classes="input-section"):
1812
- with gr.Column(scale=1):
1813
- # Image upload area
1814
- with gr.Group(elem_classes="image-upload-area"):
1815
- gr.Markdown("### πŸ“Έ Upload Your Image & Draw Bounding Box")
1816
- with gr.Column(elem_classes='jarvis_image_container'):
1817
- input_image = image_annotator(
1818
- label="Upload Image & Draw Bounding Box",
1819
- disable_edit_boxes=True,
1820
- image_type="filepath",
1821
- single_box=True,
1822
- show_label=False,
1823
- width=300
1824
- )
1825
- coordinates_output = gr.Textbox(label="BBox Coordinates", interactive=False)
1826
-
1827
  # Prompt input
1828
- with gr.Group():
1829
- gr.Markdown("### πŸ’¬ Describe Your Vision")
1830
  user_prompt = gr.Textbox(
1831
- label="",
1832
- show_label=False,
1833
- placeholder="Describe your desired editing style(Use '<box></box>' to represent the selected region of interest in the image.)... (e.g., 'I want a blue-toned look, a calm evening. Melancholy blue style')",
1834
- # value=default_user_prompt,
1835
  lines=3,
1836
- max_lines=5,
1837
- elem_classes="prompt-input"
1838
- )
 
 
 
 
 
 
 
 
 
1839
 
1840
- # Action buttons
1841
- with gr.Row():
1842
- clear_btn = gr.Button(
1843
- "πŸ—‘οΈ Clear Chat",
1844
- variant="secondary",
1845
- scale=1,
1846
- elem_classes="simple-button"
1847
- )
1848
- process_btn = gr.Button(
1849
- "✨ Generate Recommendations",
1850
- variant="primary",
1851
- scale=1,
1852
- elem_classes="primary-simple-button"
1853
- )
1854
 
1855
  # Download section
1856
- with gr.Row():
1857
- download_files = gr.File(
1858
- label="πŸ’Ύ Download Lightroom Preset Files",
1859
- file_count="multiple",
1860
- visible=True,
1861
- interactive=False
1862
- )
1863
-
1864
- with gr.Row():
1865
- gr.Markdown("""
1866
- 🎨 **How to use Lightroom Presets:**
1867
- 1. Open Adobe Lightroom
1868
- 2. Go to the **Presets** panel
1869
- 3. Click on the **+** icon
1870
- 4. Select **Import Presets**
1871
- 5. Choose the `.lrtemplate` file(s) you downloaded and click **Import**
1872
-
1873
- The imported presets will now be available in your Presets panel for use on your photos.
1874
- """)
 
1875
 
1876
- # System prompt viewing area (collapsible)
1877
- with gr.Accordion("πŸ”§ System Prompt Settings", open=False):
1878
- system_prompt_display = gr.Textbox(
1879
- value=system_prompt,
1880
- label="Current System Prompt (Preview)",
1881
- interactive=False,
1882
- lines=8,
1883
- max_lines=15
1884
- )
1885
-
1886
- gr.Markdown("""
1887
- **Note:** This system provides AI-powered image editing recommendations.
1888
- Upload your image, describe your vision, and get professional editing suggestions powered by JarvisArt.
1889
- """)
1890
 
1891
- # Advanced parameter control panel (collapsible)
1892
- with gr.Accordion("βš™οΈ Advanced Generation Parameters", open=False):
1893
- gr.Markdown("### Generation Parameter Controls")
1894
-
1895
- with gr.Row():
1896
- max_new_tokens = gr.Slider(
1897
- minimum=512,
1898
- maximum=20480,
1899
- value=10240,
1900
- step=256,
1901
- label="Max New Tokens",
1902
- info="Maximum number of tokens to generate"
1903
- )
1904
-
1905
- with gr.Row():
1906
- top_k = gr.Slider(
1907
- minimum=1,
1908
- maximum=100,
1909
- value=50,
1910
- step=1,
1911
- label="Top-K",
1912
- info="Sample from top K tokens with highest probability"
1913
- )
1914
-
1915
- top_p = gr.Slider(
1916
- minimum=0.1,
1917
- maximum=1.0,
1918
- value=0.8,
1919
- step=0.05,
1920
- label="Top-P (Nucleus Sampling)",
1921
- info="Cumulative probability threshold, controls generation diversity"
1922
- )
1923
-
1924
- with gr.Row():
1925
- temperature = gr.Slider(
1926
- minimum=0.1,
1927
- maximum=2.0,
1928
- value=0.7,
1929
- step=0.1,
1930
- label="Temperature",
1931
- info="Generation randomness, higher values mean more random"
1932
- )
1933
-
1934
- with gr.Row():
1935
- reset_params_btn = gr.Button(
1936
- "πŸ”„ Reset to Default",
1937
- variant="secondary",
1938
- size="sm"
1939
- )
1940
-
1941
- # Preset parameter buttons
1942
- conservative_btn = gr.Button(
1943
- "🎯 Conservative",
1944
- variant="secondary",
1945
- size="sm"
1946
- )
1947
-
1948
- creative_btn = gr.Button(
1949
- "🎨 Creative",
1950
- variant="secondary",
1951
- size="sm"
1952
- )
1953
-
1954
- balanced_btn = gr.Button(
1955
- "βš–οΈ Balanced",
1956
- variant="secondary",
1957
- size="sm"
1958
- )
1959
 
1960
  # Quick examples
 
 
 
 
 
 
 
 
 
 
1961
  with gr.Row():
1962
- with gr.Column(scale=1):
1963
- gr.Markdown("### πŸ’‘ Quick Examples")
1964
- example_buttons = []
1965
- examples = [
1966
- "Make it feel like a magical moment with vivid hues and a touch of fantasy style.",
1967
- "I want a blue-toned look, a calm evening. Melancholy blue style.",
1968
- "Create a vintage film look with soft highlights and muted tones.",
1969
- "Give it a Hong Kong cinema feel with vibrant contrasts and moody atmosphere.",
1970
- "Make this photo more vibrant and cinematic with warm colors."
1971
- ]
1972
-
1973
- with gr.Row():
1974
- for i, example in enumerate(examples):
1975
- btn = gr.Button(
1976
- example[:40] + "...",
1977
- size="sm",
1978
- scale=1,
1979
- elem_classes="example-buttons"
1980
- )
1981
- example_buttons.append(btn)
1982
- # Bind click event to set prompt
1983
- btn.click(
1984
- lambda ex=example: ex,
1985
- outputs=user_prompt
1986
- )
1987
 
1988
  # Event binding
1989
 
@@ -2004,12 +1299,6 @@ def create_interface():
2004
  outputs=[chatbot, download_files]
2005
  )
2006
 
2007
- # Clear chat history
2008
- clear_btn.click(
2009
- lambda: ([], None),
2010
- outputs=[chatbot, download_files]
2011
- )
2012
-
2013
  # Submit on Enter, pass all parameters
2014
  user_prompt.submit(
2015
  fn=process_analysis_pipeline_stream,
@@ -2043,7 +1332,6 @@ def create_interface():
2043
  )
2044
 
2045
  return demo
2046
-
2047
  if __name__ == "__main__":
2048
  local_dict={}
2049
  latest_session_dir = None # Track latest session for downloads
@@ -2124,4 +1412,4 @@ if __name__ == "__main__":
2124
  print(" 1. Close other programs occupying the port")
2125
  print(" 2. Use --server_port parameter to specify a different port")
2126
  print(" 3. Check firewall settings")
2127
- sys.exit(1)
 
48
  from transformers import Qwen2VLForConditionalGeneration, AutoProcessor
49
  from qwen_vl_utils import process_vision_info
50
  import torch
51
+ from lua2lrt import lua_to_lrtemplate
52
  from huggingface_hub import snapshot_download
53
  import spaces
54
 
 
1102
  # Create Gradio interface
1103
  def create_interface():
1104
  """
1105
+ Create and configure the Gradio web interface similar to example.py style
1106
 
1107
  Returns:
1108
+ gr.Blocks: Configured Gradio interface
1109
  """
 
 
 
 
 
 
 
 
1110
 
1111
+ with gr.Blocks(title="JarvisArt: AI-Powered Photo Editing Assistant", theme=gr.themes.Soft()) as demo:
1112
+ # Header with title
1113
+ gr.Markdown("""
1114
+ # 🎨 JarvisArt: AI-Powered Photo Editing Assistant
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1115
 
1116
+ Upload an image, describe your vision, and get professional Lightroom presets!
1117
+ """)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1118
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1119
  with gr.Row():
1120
  with gr.Column(scale=1):
1121
+ # Input image upload component
1122
+ input_image = image_annotator(
1123
+ label="πŸ“Έ Upload Your Image & Draw Bounding Box",
1124
+ disable_edit_boxes=True,
1125
+ image_type="filepath",
1126
+ single_box=True,
1127
+ show_label=True,
1128
+ height=400
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1129
  )
1130
+
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1131
  # Prompt input
 
 
1132
  user_prompt = gr.Textbox(
1133
+ label="πŸ’¬ Describe Your Vision",
1134
+ placeholder="Describe your desired editing style (Use '<box></box>' to represent the selected region)... (e.g., 'I want a dreamy, romantic sunset vibe with soft, warm colors')",
 
 
1135
  lines=3,
1136
+ max_lines=5
1137
+ )
1138
+
1139
+ # Process button
1140
+ process_btn = gr.Button(
1141
+ "✨ Generate Recommendations & Presets",
1142
+ variant="primary",
1143
+ size="lg"
1144
+ )
1145
+
1146
+ # Coordinates output (hidden for simplicity)
1147
+ coordinates_output = gr.Textbox(label="BBox Coordinates", interactive=False, visible=False)
1148
 
1149
+ with gr.Column(scale=1):
1150
+ # Chat interface to show analysis
1151
+ chatbot = gr.Chatbot(
1152
+ label="πŸ’¬ AI Analysis & Recommendations",
1153
+ height=400,
1154
+ show_label=True,
1155
+ bubble_full_width=False
1156
+ )
 
 
 
 
 
 
1157
 
1158
  # Download section
1159
+ download_files = gr.File(
1160
+ label="πŸ“Ύ Download Lightroom Preset Files",
1161
+ file_count="multiple",
1162
+ visible=True,
1163
+ interactive=False
1164
+ )
1165
+
1166
+ # Advanced parameter control panel (collapsible)
1167
+ with gr.Accordion("βš™οΈ Advanced Generation Parameters", open=False):
1168
+ gr.Markdown("### Generation Parameter Controls")
1169
+
1170
+ with gr.Row():
1171
+ max_new_tokens = gr.Slider(
1172
+ minimum=512,
1173
+ maximum=20480,
1174
+ value=10240,
1175
+ step=256,
1176
+ label="Max New Tokens",
1177
+ info="Maximum number of tokens to generate"
1178
+ )
1179
 
1180
+ with gr.Row():
1181
+ top_k = gr.Slider(
1182
+ minimum=1,
1183
+ maximum=100,
1184
+ value=50,
1185
+ step=1,
1186
+ label="Top-K",
1187
+ info="Sample from top K tokens with highest probability"
1188
+ )
 
 
 
 
 
1189
 
1190
+ top_p = gr.Slider(
1191
+ minimum=0.1,
1192
+ maximum=1.0,
1193
+ value=0.8,
1194
+ step=0.05,
1195
+ label="Top-P (Nucleus Sampling)",
1196
+ info="Cumulative probability threshold, controls generation diversity"
1197
+ )
1198
+
1199
+ with gr.Row():
1200
+ temperature = gr.Slider(
1201
+ minimum=0.1,
1202
+ maximum=2.0,
1203
+ value=0.7,
1204
+ step=0.1,
1205
+ label="Temperature",
1206
+ info="Generation randomness, higher values mean more random"
1207
+ )
1208
+
1209
+ with gr.Row():
1210
+ reset_params_btn = gr.Button(
1211
+ "πŸ”„ Reset to Default",
1212
+ variant="secondary",
1213
+ size="sm"
1214
+ )
1215
+
1216
+ # Preset parameter buttons
1217
+ conservative_btn = gr.Button(
1218
+ "🎯 Conservative",
1219
+ variant="secondary",
1220
+ size="sm"
1221
+ )
1222
+
1223
+ creative_btn = gr.Button(
1224
+ "🎨 Creative",
1225
+ variant="secondary",
1226
+ size="sm"
1227
+ )
1228
+
1229
+ balanced_btn = gr.Button(
1230
+ "βš–οΈ Balanced",
1231
+ variant="secondary",
1232
+ size="sm"
1233
+ )
1234
+
1235
+ # Instructions section at the bottom
1236
+ gr.Markdown("### πŸ“ How to Use:")
1237
+ gr.Markdown("""
1238
+ 1. **Upload an image** you'd like to enhance (any photo format)
1239
+ 2. **Optional**: Draw a bounding box on specific regions you want to focus on
1240
+ 3. **Describe your vision** - what style or mood you want to achieve
1241
+ 4. **Click 'Generate'** to get AI-powered editing recommendations
1242
+ 5. **Download** the generated Lightroom preset files (.lrtemplate)
1243
+ 6. **Import** the presets into Adobe Lightroom using the guide below
1244
+ """)
1245
+
1246
+ # Lightroom import guide
1247
+ gr.Markdown("### 🎨 How to Import Lightroom Presets:")
1248
+ gr.Markdown("""
1249
+ 1. Open Adobe Lightroom
1250
+ 2. Go to the **Presets** panel
1251
+ 3. Click on the **+** icon
1252
+ 4. Select **Import Presets**
1253
+ 5. Choose the `.lrtemplate` file(s) you downloaded and click **Import**
1254
+
1255
+ The imported presets will now be available in your Presets panel for use on your photos.
1256
+ """)
 
1257
 
1258
  # Quick examples
1259
+ gr.Markdown("### πŸ’‘ Example Prompts:")
1260
+ examples = [
1261
+ "Make it feel like a magical moment with vivid hues and a touch of fantasy style.",
1262
+ "I want a blue-toned look, a calm evening. Melancholy blue style.",
1263
+ "Create a vintage film look with soft highlights and muted tones.",
1264
+ "Give it a Hong Kong cinema feel with vibrant contrasts and moody atmosphere.",
1265
+ "Make this photo more vibrant and cinematic with warm colors."
1266
+ ]
1267
+
1268
+ example_buttons = []
1269
  with gr.Row():
1270
+ for i, example in enumerate(examples):
1271
+ btn = gr.Button(
1272
+ example[:30] + "...",
1273
+ size="sm",
1274
+ scale=1
1275
+ )
1276
+ example_buttons.append(btn)
1277
+ # Bind click event to set prompt
1278
+ btn.click(
1279
+ lambda ex=example: ex,
1280
+ outputs=user_prompt
1281
+ )
 
 
 
 
 
 
 
 
 
 
 
 
 
1282
 
1283
  # Event binding
1284
 
 
1299
  outputs=[chatbot, download_files]
1300
  )
1301
 
 
 
 
 
 
 
1302
  # Submit on Enter, pass all parameters
1303
  user_prompt.submit(
1304
  fn=process_analysis_pipeline_stream,
 
1332
  )
1333
 
1334
  return demo
 
1335
  if __name__ == "__main__":
1336
  local_dict={}
1337
  latest_session_dir = None # Track latest session for downloads
 
1412
  print(" 1. Close other programs occupying the port")
1413
  print(" 2. Use --server_port parameter to specify a different port")
1414
  print(" 3. Check firewall settings")
1415
+ sys.exit(1)