GChilukala commited on
Commit
8252acc
ยท
verified ยท
1 Parent(s): 2e45a4b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +201 -145
app.py CHANGED
@@ -1209,16 +1209,16 @@ async def translate_caption_interface(base_caption, selected_languages):
1209
  return result
1210
 
1211
 
1212
- # Fixed Gradio Interface with Better Dropdown Styling and More Options
1213
 
1214
  def create_gradio_app():
1215
- """Create the Gradio app with fixed dropdown styling and more options"""
1216
 
1217
  # Status indicators
1218
  hf_status = "โœ… Connected" if generator and generator.hf_client_working else "โš ๏ธ Fallback Mode"
1219
  sambanova_status = "โœ… Connected" if generator and generator.sambanova_client_working else "โš ๏ธ Fallback Mode"
1220
 
1221
- # Enhanced CSS for better dropdown positioning
1222
  css = """
1223
  @import url('https://fonts.googleapis.com/css2?family=Space+Grotesk:wght@300;400;500;600;700&display=swap');
1224
 
@@ -1252,7 +1252,7 @@ def create_gradio_app():
1252
  z-index: 1;
1253
  }
1254
 
1255
- /* FIX: Better dropdown styling */
1256
  .gradio-dropdown {
1257
  position: relative !important;
1258
  z-index: 1000 !important;
@@ -1269,7 +1269,8 @@ def create_gradio_app():
1269
 
1270
  .gradio-dropdown ul {
1271
  position: absolute !important;
1272
- top: 100% !important;
 
1273
  left: 0 !important;
1274
  right: 0 !important;
1275
  background: rgba(255, 255, 255, 0.95) !important;
@@ -1281,6 +1282,8 @@ def create_gradio_app():
1281
  overflow-y: auto !important;
1282
  z-index: 1002 !important;
1283
  margin-top: 5px !important;
 
 
1284
  }
1285
 
1286
  .gradio-dropdown li {
@@ -1301,9 +1304,10 @@ def create_gradio_app():
1301
  font-weight: 600 !important;
1302
  }
1303
 
1304
- /* Ensure dropdowns don't get clipped */
1305
  .gradio-row, .gradio-column {
1306
  overflow: visible !important;
 
1307
  }
1308
 
1309
  .gradio-button-primary {
@@ -1331,8 +1335,22 @@ def create_gradio_app():
1331
  color: white !important;
1332
  box-shadow: 0 8px 16px rgba(254, 202, 87, 0.3) !important;
1333
  }
 
 
 
 
 
 
 
 
 
 
 
1334
  """
1335
 
 
 
 
1336
  with gr.Blocks(css=css, title="๐Ÿ“ฑ Instagram Generator", theme=gr.themes.Glass()) as app:
1337
 
1338
  # Main Header
@@ -1368,7 +1386,6 @@ def create_gradio_app():
1368
 
1369
  gr.Markdown("### โš™๏ธ Configuration")
1370
 
1371
- # ENHANCED DROPDOWN OPTIONS
1372
  with gr.Row():
1373
  caption_style = gr.Dropdown(
1374
  choices=[
@@ -1379,22 +1396,10 @@ def create_gradio_app():
1379
  "๐Ÿ’ช Motivational",
1380
  "๐Ÿ“– Storytelling",
1381
  "๐ŸŒŸ Luxury Lifestyle",
1382
- "๐Ÿ”ฅ Trending Culture",
1383
- "๐ŸŒ™ Mysterious & Intriguing",
1384
- "๐ŸŽญ Behind-the-Scenes",
1385
- "๐Ÿ“š Educational/Tutorial",
1386
- "๐ŸŽช Controversial/Debate",
1387
- "๐ŸŒฑ Minimalist/Zen",
1388
- "๐ŸŽฌ Cinematic/Movie-style",
1389
- "๐ŸŽฎ Gaming/Meme Culture",
1390
- "๐Ÿ† Achievement/Milestone",
1391
- "๐Ÿ’” Vulnerable/Personal",
1392
- "๐ŸŒˆ Inclusive/Community"
1393
  ],
1394
  value="๐ŸŽฏ Viral Engagement",
1395
- label="๐ŸŽจ Caption Style",
1396
- container=True,
1397
- interactive=True
1398
  )
1399
 
1400
  target_audience = gr.Dropdown(
@@ -1406,49 +1411,16 @@ def create_gradio_app():
1406
  "๐Ÿ’ช Fitness Community",
1407
  "๐Ÿ‘— Fashion Forward",
1408
  "๐Ÿ’ป Tech Innovators",
1409
- "๐ŸŽจ Creative Artists",
1410
- "๐ŸŽ“ Students & Academia",
1411
- "๐Ÿ‘ถ Parents & Families",
1412
- "๐ŸŒ Environmental Activists",
1413
- "๐Ÿ’ฐ Entrepreneurs",
1414
- "๐ŸŽต Music Lovers",
1415
- "๐Ÿƒ Athletes & Sports",
1416
- "๐Ÿ‘— Beauty & Skincare",
1417
- "๐Ÿ  Home & Lifestyle",
1418
- "๐Ÿพ Pet Owners",
1419
- "๐Ÿƒ Wellness & Mental Health",
1420
- "๐ŸŽญ Entertainment Industry"
1421
  ],
1422
  value="๐ŸŒŸ General Audience",
1423
- label="๐Ÿ‘ฅ Target Audience",
1424
- container=True,
1425
- interactive=True
1426
  )
1427
 
1428
- # Content Type Selection
1429
- content_type = gr.Dropdown(
1430
- choices=[
1431
- "๐Ÿ“ธ Photo Caption",
1432
- "๐ŸŽฅ Video/Reels Caption",
1433
- "๐Ÿ“ฑ Stories Text",
1434
- "๐Ÿ›๏ธ Product Showcase",
1435
- "๐ŸŽ‰ Event Promotion",
1436
- "๐Ÿ“ฐ News Commentary",
1437
- "๐ŸŽ‚ Celebration Post",
1438
- "๐Ÿ“ข Announcement",
1439
- "๐Ÿค Collaboration Post",
1440
- "๐ŸŽ Giveaway/Contest"
1441
- ],
1442
- value="๐Ÿ“ธ Photo Caption",
1443
- label="๐Ÿ“ Content Type",
1444
- container=True,
1445
- interactive=True
1446
- )
1447
-
1448
  custom_prompt = gr.Textbox(
1449
  label="๐Ÿ’ฌ Additional Instructions",
1450
- placeholder="e.g., 'Focus on sustainability', 'Include product details', 'Add call-to-action'...",
1451
- lines=3
1452
  )
1453
 
1454
  generate_btn = gr.Button(
@@ -1464,7 +1436,7 @@ def create_gradio_app():
1464
  output = gr.Textbox(
1465
  label="๐ŸŽฏ Generated Caption",
1466
  lines=15,
1467
- max_lines=25,
1468
  show_copy_button=True,
1469
  placeholder="Upload images and generate your Instagram content..."
1470
  )
@@ -1475,11 +1447,6 @@ def create_gradio_app():
1475
  variant="secondary",
1476
  scale=1
1477
  )
1478
- analytics_btn = gr.Button(
1479
- "๐Ÿ“Š Analyze Performance",
1480
- variant="secondary",
1481
- scale=1
1482
- )
1483
 
1484
  alternatives_output = gr.Textbox(
1485
  label="โœจ Alternative Captions",
@@ -1488,7 +1455,7 @@ def create_gradio_app():
1488
  placeholder="Generate 3 different caption alternatives using Meta-Llama-3.2-3B-Instruct..."
1489
  )
1490
 
1491
- # Multi-Language Tab with Enhanced Options
1492
  with gr.Tab("๐ŸŒ Multi-Language"):
1493
  with gr.Row():
1494
  with gr.Column(elem_classes=["feature-card"]):
@@ -1506,15 +1473,7 @@ def create_gradio_app():
1506
  "๐Ÿ‡ฉ๐Ÿ‡ช German",
1507
  "๐Ÿ‡จ๐Ÿ‡ณ Chinese",
1508
  "๐Ÿ‡ฎ๐Ÿ‡ณ Hindi",
1509
- "๐Ÿ‡ธ๐Ÿ‡ฆ Arabic",
1510
- "๐Ÿ‡ซ๐Ÿ‡ท French",
1511
- "๐Ÿ‡ช๐Ÿ‡ธ Spanish",
1512
- "๐Ÿ‡ต๐Ÿ‡น Portuguese",
1513
- "๐Ÿ‡ฎ๐Ÿ‡น Italian",
1514
- "๐Ÿ‡ฏ๐Ÿ‡ต Japanese",
1515
- "๐Ÿ‡ฐ๐Ÿ‡ท Korean",
1516
- "๐Ÿ‡ท๐Ÿ‡บ Russian",
1517
- "๐Ÿ‡น๐Ÿ‡ท Turkish"
1518
  ],
1519
  label="๐ŸŒ Select Languages",
1520
  value=["๐Ÿ‡ฉ๐Ÿ‡ช German", "๐Ÿ‡ฎ๐Ÿ‡ณ Hindi"]
@@ -1533,87 +1492,184 @@ def create_gradio_app():
1533
  placeholder="Culturally adapted captions for global audiences..."
1534
  )
1535
 
1536
- # Analytics Tab
1537
- with gr.Tab("๐Ÿ“Š Analytics"):
 
 
 
 
 
 
1538
  with gr.Row():
1539
  with gr.Column(elem_classes=["feature-card"]):
1540
- gr.Markdown("### ๐Ÿ“ˆ Caption Performance Analysis")
1541
-
1542
- analytics_caption = gr.Textbox(
1543
- label="๐Ÿ“ Caption to Analyze",
1544
- placeholder="Paste caption for performance analysis...",
1545
- lines=5
1546
- )
1547
-
1548
- analyze_btn = gr.Button(
1549
- "๐Ÿ” Analyze Performance",
1550
- variant="primary"
1551
- )
 
 
 
 
 
 
 
 
 
 
 
1552
 
1553
  with gr.Column(elem_classes=["feature-card"]):
1554
- analytics_output = gr.Textbox(
1555
- label="๐Ÿ“Š Analytics Results",
1556
- lines=15,
1557
- placeholder="Performance metrics and recommendations..."
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1558
  )
1559
-
1560
- return app
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1561
 
 
1562
 
1563
- # Enhanced caption generation function with content type support
1564
- async def generate_enhanced_caption_interface(uploaded_files, style, audience,
1565
- content_type, custom_prompt):
1566
- """Enhanced interface function with content type support"""
1567
- if not setup_success:
1568
- return f"โŒ Setup Error: {setup_error}", ""
1569
-
1570
- images = []
1571
- if uploaded_files:
1572
- for file in uploaded_files[:3]:
1573
- try:
1574
- image = Image.open(file.name)
1575
- images.append(image)
1576
- except Exception as e:
1577
- return f"โŒ Error processing file: {e}", ""
1578
-
1579
- # Enhanced prompt with content type
1580
- enhanced_prompt = f"""
1581
- Create an Instagram caption with these specifications:
1582
-
1583
- STYLE: {style}
1584
- AUDIENCE: {audience}
1585
- CONTENT TYPE: {content_type}
1586
- SPECIAL REQUIREMENTS: {custom_prompt if custom_prompt else 'None'}
1587
-
1588
- Based on the content type '{content_type}', adjust the format and tone accordingly.
1589
- """
1590
-
1591
- result = await generator.generate_advanced_caption(
1592
- images, style, audience, enhanced_prompt
1593
- )
1594
-
1595
- # Extract clean caption for multi-language processing
1596
- caption_only = ""
1597
- if "โœจ AI-GENERATED INSTAGRAM CONTENT:" in result:
1598
- lines = result.split('\n')
1599
- caption_lines = []
1600
- start_capturing = False
1601
 
1602
- for line in lines:
1603
- if "โœจ AI-GENERATED INSTAGRAM CONTENT:" in line:
1604
- start_capturing = True
1605
- continue
1606
- elif "๐Ÿค– Powered by SambaNova" in line:
1607
- break
1608
- elif start_capturing and line.strip():
1609
- caption_lines.append(line)
1610
 
1611
- caption_only = '\n'.join(caption_lines).strip()
1612
-
1613
- if not caption_only:
1614
- caption_only = result
 
 
 
 
 
 
 
 
 
1615
 
1616
- return result, caption_only
 
1617
 
1618
  def main():
1619
  """Main function to launch the Instagram Caption Generator"""
 
1209
  return result
1210
 
1211
 
1212
+ # Just replace the CSS section in your create_gradio_app() function:
1213
 
1214
  def create_gradio_app():
1215
+ """Create the Gradio app with good UI styling"""
1216
 
1217
  # Status indicators
1218
  hf_status = "โœ… Connected" if generator and generator.hf_client_working else "โš ๏ธ Fallback Mode"
1219
  sambanova_status = "โœ… Connected" if generator and generator.sambanova_client_working else "โš ๏ธ Fallback Mode"
1220
 
1221
+ # FIXED CSS - Only dropdown positioning changes
1222
  css = """
1223
  @import url('https://fonts.googleapis.com/css2?family=Space+Grotesk:wght@300;400;500;600;700&display=swap');
1224
 
 
1252
  z-index: 1;
1253
  }
1254
 
1255
+ /* DROPDOWN FIX - Force dropdowns to open downward */
1256
  .gradio-dropdown {
1257
  position: relative !important;
1258
  z-index: 1000 !important;
 
1269
 
1270
  .gradio-dropdown ul {
1271
  position: absolute !important;
1272
+ top: 100% !important; /* This forces dropdown to open below */
1273
+ bottom: auto !important; /* Prevent upward opening */
1274
  left: 0 !important;
1275
  right: 0 !important;
1276
  background: rgba(255, 255, 255, 0.95) !important;
 
1282
  overflow-y: auto !important;
1283
  z-index: 1002 !important;
1284
  margin-top: 5px !important;
1285
+ margin-bottom: 0 !important;
1286
+ transform: none !important; /* Prevent any transformations */
1287
  }
1288
 
1289
  .gradio-dropdown li {
 
1304
  font-weight: 600 !important;
1305
  }
1306
 
1307
+ /* Ensure parent containers don't clip dropdowns */
1308
  .gradio-row, .gradio-column {
1309
  overflow: visible !important;
1310
+ position: relative !important;
1311
  }
1312
 
1313
  .gradio-button-primary {
 
1335
  color: white !important;
1336
  box-shadow: 0 8px 16px rgba(254, 202, 87, 0.3) !important;
1337
  }
1338
+
1339
+ .status-badge {
1340
+ background: linear-gradient(90deg, #2ecc71, #27ae60);
1341
+ color: white;
1342
+ padding: 10px 20px;
1343
+ border-radius: 10px;
1344
+ text-align: center;
1345
+ font-weight: 600;
1346
+ box-shadow: 0 8px 16px rgba(46, 204, 113, 0.3);
1347
+ margin: 10px 0;
1348
+ }
1349
  """
1350
 
1351
+ # Rest of your function remains exactly the same...
1352
+ with gr.Blocks(css=css, title="๐Ÿ“ฑ Instagram Generator", theme=gr.themes.Glass()) as app:
1353
+
1354
  with gr.Blocks(css=css, title="๐Ÿ“ฑ Instagram Generator", theme=gr.themes.Glass()) as app:
1355
 
1356
  # Main Header
 
1386
 
1387
  gr.Markdown("### โš™๏ธ Configuration")
1388
 
 
1389
  with gr.Row():
1390
  caption_style = gr.Dropdown(
1391
  choices=[
 
1396
  "๐Ÿ’ช Motivational",
1397
  "๐Ÿ“– Storytelling",
1398
  "๐ŸŒŸ Luxury Lifestyle",
1399
+ "๐Ÿ”ฅ Trending Culture"
 
 
 
 
 
 
 
 
 
 
1400
  ],
1401
  value="๐ŸŽฏ Viral Engagement",
1402
+ label="๐ŸŽจ Caption Style"
 
 
1403
  )
1404
 
1405
  target_audience = gr.Dropdown(
 
1411
  "๐Ÿ’ช Fitness Community",
1412
  "๐Ÿ‘— Fashion Forward",
1413
  "๐Ÿ’ป Tech Innovators",
1414
+ "๐ŸŽจ Creative Artists"
 
 
 
 
 
 
 
 
 
 
 
1415
  ],
1416
  value="๐ŸŒŸ General Audience",
1417
+ label="๐Ÿ‘ฅ Target Audience"
 
 
1418
  )
1419
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1420
  custom_prompt = gr.Textbox(
1421
  label="๐Ÿ’ฌ Additional Instructions",
1422
+ placeholder="e.g., 'Focus on sustainability', 'Include product details'...",
1423
+ lines=2
1424
  )
1425
 
1426
  generate_btn = gr.Button(
 
1436
  output = gr.Textbox(
1437
  label="๐ŸŽฏ Generated Caption",
1438
  lines=15,
1439
+ max_lines=20,
1440
  show_copy_button=True,
1441
  placeholder="Upload images and generate your Instagram content..."
1442
  )
 
1447
  variant="secondary",
1448
  scale=1
1449
  )
 
 
 
 
 
1450
 
1451
  alternatives_output = gr.Textbox(
1452
  label="โœจ Alternative Captions",
 
1455
  placeholder="Generate 3 different caption alternatives using Meta-Llama-3.2-3B-Instruct..."
1456
  )
1457
 
1458
+ # Multi-Language Tab
1459
  with gr.Tab("๐ŸŒ Multi-Language"):
1460
  with gr.Row():
1461
  with gr.Column(elem_classes=["feature-card"]):
 
1473
  "๐Ÿ‡ฉ๐Ÿ‡ช German",
1474
  "๐Ÿ‡จ๐Ÿ‡ณ Chinese",
1475
  "๐Ÿ‡ฎ๐Ÿ‡ณ Hindi",
1476
+ "๐Ÿ‡ธ๐Ÿ‡ฆ Arabic"
 
 
 
 
 
 
 
 
1477
  ],
1478
  label="๐ŸŒ Select Languages",
1479
  value=["๐Ÿ‡ฉ๐Ÿ‡ช German", "๐Ÿ‡ฎ๐Ÿ‡ณ Hindi"]
 
1492
  placeholder="Culturally adapted captions for global audiences..."
1493
  )
1494
 
1495
+ # SambaNova Features Tab
1496
+ with gr.Tab("๐Ÿค– SambaNova Features"):
1497
+ gr.HTML(f"""
1498
+ <div class="status-badge">
1499
+ ๐Ÿš€ SambaNova Status: {sambanova_status} โ€ข ๐Ÿฆ™ Llama-4-Maverick + Llama-3.2-3B
1500
+ </div>
1501
+ """)
1502
+
1503
  with gr.Row():
1504
  with gr.Column(elem_classes=["feature-card"]):
1505
+ gr.HTML("""
1506
+ <div style="text-align: center; padding: 20px;">
1507
+ <h3>โšก SambaNova AI Capabilities</h3>
1508
+ <div style="display: grid; grid-template-columns: repeat(2, 1fr); gap: 15px; margin-top: 20px;">
1509
+ <div style="padding: 15px; background: rgba(46, 204, 113, 0.2); border-radius: 10px; border: 2px solid #2ecc71;">
1510
+ <h4 style="color: #ffffff; margin: 0; text-shadow: 0 0 10px #2ecc71;">Llama-4-Maverick</h4>
1511
+ <p style="margin: 5px 0; color: #e8f8f5; font-weight: 500;">Main Caption Generation</p>
1512
+ </div>
1513
+ <div style="padding: 15px; background: rgba(52, 152, 219, 0.2); border-radius: 10px; border: 2px solid #3498db;">
1514
+ <h4 style="color: #ffffff; margin: 0; text-shadow: 0 0 10px #3498db;">Llama-3.2-3B</h4>
1515
+ <p style="margin: 5px 0; color: #ebf3fd; font-weight: 500;">Caption Variations</p>
1516
+ </div>
1517
+ <div style="padding: 15px; background: rgba(231, 76, 60, 0.2); border-radius: 10px; border: 2px solid #e74c3c;">
1518
+ <h4 style="color: #ffffff; margin: 0; text-shadow: 0 0 10px #e74c3c;">Multi-Modal</h4>
1519
+ <p style="margin: 5px 0; color: #fdedec; font-weight: 500;">Vision + Text Analysis</p>
1520
+ </div>
1521
+ <div style="padding: 15px; background: rgba(155, 89, 182, 0.2); border-radius: 10px; border: 2px solid #9b59b6;">
1522
+ <h4 style="color: #ffffff; margin: 0; text-shadow: 0 0 10px #9b59b6;">Advanced</h4>
1523
+ <p style="margin: 5px 0; color: #f4ecf7; font-weight: 500;">Style & Audience Targeting</p>
1524
+ </div>
1525
+ </div>
1526
+ </div>
1527
+ """)
1528
 
1529
  with gr.Column(elem_classes=["feature-card"]):
1530
+ gr.Code(
1531
+ value="""
1532
+ # SambaNova API Integration:
1533
+
1534
+ from openai import OpenAI
1535
+
1536
+ client = OpenAI(
1537
+ api_key=os.environ["SAMBANOVA_API_KEY"],
1538
+ base_url="https://api.sambanova.ai/v1",
1539
+ )
1540
+
1541
+ # Main caption generation
1542
+ response = client.chat.completions.create(
1543
+ model="Llama-4-Maverick-17B-128E-Instruct",
1544
+ messages=[{
1545
+ "role": "user",
1546
+ "content": [
1547
+ {"type": "text", "text": "Create Instagram caption"},
1548
+ {"type": "image_url", "image_url": {"url": "data:image/jpeg;base64,..."}}
1549
+ ]
1550
+ }],
1551
+ temperature=0.1,
1552
+ top_p=0.1
1553
+ )
1554
+
1555
+ # Caption variations
1556
+ variations = client.chat.completions.create(
1557
+ model="Meta-Llama-3.2-3B-Instruct",
1558
+ messages=[{
1559
+ "role": "user",
1560
+ "content": "Create different version of this caption..."
1561
+ }],
1562
+ temperature=0.9,
1563
+ top_p=0.95
1564
+ )
1565
+ """,
1566
+ language="python",
1567
+ label="๐Ÿ”ง SambaNova Integration Code"
1568
  )
1569
+
1570
+ # Hugging Face Features Tab
1571
+ with gr.Tab("๐Ÿค— Hugging Face Features"):
1572
+ gr.HTML(f"""
1573
+ <div class="status-badge">
1574
+ ๐Ÿค— Hugging Face Status: {hf_status} โ€ข ๐ŸŒ Multi-Language Translation
1575
+ </div>
1576
+ """)
1577
+
1578
+ with gr.Row():
1579
+ with gr.Column(elem_classes=["feature-card"]):
1580
+ gr.HTML("""
1581
+ <div style="text-align: center; padding: 20px;">
1582
+ <h3>๐ŸŒ Translation Models</h3>
1583
+ <div style="display: grid; grid-template-columns: repeat(2, 1fr); gap: 15px; margin-top: 20px;">
1584
+ <div style="padding: 15px; background: rgba(46, 204, 113, 0.2); border-radius: 10px; border: 2px solid #2ecc71;">
1585
+ <h4 style="color: #ffffff; margin: 0; text-shadow: 0 0 10px #2ecc71;">๐Ÿ‡ฉ๐Ÿ‡ช German</h4>
1586
+ <p style="margin: 5px 0; color: #e8f8f5; font-weight: 500;">google-t5/t5-small</p>
1587
+ </div>
1588
+ <div style="padding: 15px; background: rgba(52, 152, 219, 0.2); border-radius: 10px; border: 2px solid #3498db;">
1589
+ <h4 style="color: #ffffff; margin: 0; text-shadow: 0 0 10px #3498db;">๐Ÿ‡จ๐Ÿ‡ณ Chinese</h4>
1590
+ <p style="margin: 5px 0; color: #ebf3fd; font-weight: 500;">chence08/mt5-small-iwslt2017-zh-en</p>
1591
+ </div>
1592
+ <div style="padding: 15px; background: rgba(231, 76, 60, 0.2); border-radius: 10px; border: 2px solid #e74c3c;">
1593
+ <h4 style="color: #ffffff; margin: 0; text-shadow: 0 0 10px #e74c3c;">๐Ÿ‡ฎ๐Ÿ‡ณ Hindi</h4>
1594
+ <p style="margin: 5px 0; color: #fdedec; font-weight: 500;">Helsinki-NLP/opus-mt-en-hi</p>
1595
+ </div>
1596
+ <div style="padding: 15px; background: rgba(155, 89, 182, 0.2); border-radius: 10px; border: 2px solid #9b59b6;">
1597
+ <h4 style="color: #ffffff; margin: 0; text-shadow: 0 0 10px #9b59b6;">๐Ÿ‡ธ๐Ÿ‡ฆ Arabic</h4>
1598
+ <p style="margin: 5px 0; color: #f4ecf7; font-weight: 500;">marefa-nlp/marefa-mt-en-ar</p>
1599
+ </div>
1600
+ </div>
1601
+ </div>
1602
+ """)
1603
+
1604
+ with gr.Column(elem_classes=["feature-card"]):
1605
+ gr.Code(
1606
+ value="""
1607
+ # Hugging Face Translation Integration:
1608
 
1609
+ from huggingface_hub import InferenceClient
1610
 
1611
+ client = InferenceClient(
1612
+ provider="hf-inference",
1613
+ api_key=os.environ["HF_TOKEN"],
1614
+ )
1615
+
1616
+ # German translation
1617
+ german_result = client.translation(
1618
+ "This is an amazing moment! โœจ",
1619
+ model="google-t5/t5-small",
1620
+ )
1621
+
1622
+ # Chinese translation
1623
+ chinese_result = client.translation(
1624
+ "Amazing content for Instagram",
1625
+ model="chence08/mt5-small-iwslt2017-zh-en",
1626
+ )
1627
+
1628
+ # Hindi translation
1629
+ hindi_result = client.translation(
1630
+ "Beautiful content creation",
1631
+ model="Helsinki-NLP/opus-mt-en-hi",
1632
+ )
1633
+
1634
+ # Arabic translation
1635
+ arabic_result = client.translation(
1636
+ "Social media content",
1637
+ model="marefa-nlp/marefa-mt-en-ar",
1638
+ )
1639
+
1640
+ # Features:
1641
+ # โœ… 4 language models
1642
+ # โœ… Fallback support
1643
+ # โœ… Instagram-optimized output
1644
+ # โœ… Cultural adaptation
1645
+ """,
1646
+ language="python",
1647
+ label="๐Ÿ”ง Hugging Face Translation Code"
1648
+ )
1649
 
1650
+ # Event Handlers
1651
+ generate_btn.click(
1652
+ fn=generate_advanced_caption_interface,
1653
+ inputs=[images, caption_style, target_audience, custom_prompt],
1654
+ outputs=[output, base_caption_input]
1655
+ )
 
 
1656
 
1657
+ # Generate multiple alternatives
1658
+ alternatives_btn.click(
1659
+ fn=generate_multiple_captions_interface,
1660
+ inputs=[images, caption_style, target_audience, custom_prompt],
1661
+ outputs=alternatives_output
1662
+ )
1663
+
1664
+ # Multi-language translation
1665
+ translate_btn.click(
1666
+ fn=translate_caption_interface,
1667
+ inputs=[base_caption_input, language_selector],
1668
+ outputs=multilingual_output
1669
+ )
1670
 
1671
+ return app
1672
+
1673
 
1674
  def main():
1675
  """Main function to launch the Instagram Caption Generator"""