Update app.py
Browse files
app.py
CHANGED
|
@@ -1209,16 +1209,16 @@ async def translate_caption_interface(base_caption, selected_languages):
|
|
| 1209 |
return result
|
| 1210 |
|
| 1211 |
|
| 1212 |
-
#
|
| 1213 |
|
| 1214 |
def create_gradio_app():
|
| 1215 |
-
"""Create the Gradio app with
|
| 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 |
-
#
|
| 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
|
| 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
|
| 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'
|
| 1451 |
-
lines=
|
| 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=
|
| 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
|
| 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 |
-
#
|
| 1537 |
-
with gr.Tab("
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1538 |
with gr.Row():
|
| 1539 |
with gr.Column(elem_classes=["feature-card"]):
|
| 1540 |
-
gr.
|
| 1541 |
-
|
| 1542 |
-
|
| 1543 |
-
|
| 1544 |
-
|
| 1545 |
-
|
| 1546 |
-
|
| 1547 |
-
|
| 1548 |
-
|
| 1549 |
-
|
| 1550 |
-
|
| 1551 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1552 |
|
| 1553 |
with gr.Column(elem_classes=["feature-card"]):
|
| 1554 |
-
|
| 1555 |
-
|
| 1556 |
-
|
| 1557 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1558 |
)
|
| 1559 |
-
|
| 1560 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1561 |
|
|
|
|
| 1562 |
|
| 1563 |
-
|
| 1564 |
-
|
| 1565 |
-
|
| 1566 |
-
|
| 1567 |
-
|
| 1568 |
-
|
| 1569 |
-
|
| 1570 |
-
|
| 1571 |
-
|
| 1572 |
-
|
| 1573 |
-
|
| 1574 |
-
|
| 1575 |
-
|
| 1576 |
-
|
| 1577 |
-
|
| 1578 |
-
|
| 1579 |
-
|
| 1580 |
-
|
| 1581 |
-
|
| 1582 |
-
|
| 1583 |
-
|
| 1584 |
-
|
| 1585 |
-
|
| 1586 |
-
|
| 1587 |
-
|
| 1588 |
-
|
| 1589 |
-
""
|
| 1590 |
-
|
| 1591 |
-
|
| 1592 |
-
|
| 1593 |
-
|
| 1594 |
-
|
| 1595 |
-
|
| 1596 |
-
|
| 1597 |
-
|
| 1598 |
-
|
| 1599 |
-
|
| 1600 |
-
|
| 1601 |
|
| 1602 |
-
|
| 1603 |
-
|
| 1604 |
-
|
| 1605 |
-
|
| 1606 |
-
|
| 1607 |
-
|
| 1608 |
-
elif start_capturing and line.strip():
|
| 1609 |
-
caption_lines.append(line)
|
| 1610 |
|
| 1611 |
-
|
| 1612 |
-
|
| 1613 |
-
|
| 1614 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1615 |
|
| 1616 |
-
return
|
|
|
|
| 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"""
|