Update app.py
Browse files
app.py
CHANGED
|
@@ -1211,250 +1211,66 @@ async def translate_caption_interface(base_caption, selected_languages):
|
|
| 1211 |
|
| 1212 |
# Replace the CSS section in your create_gradio_app() function with this fixed version:
|
| 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 |
-
|
| 1223 |
-
@import url('https://fonts.googleapis.com/css2?family=Space+Grotesk:wght@300;400;500;600;700&display=swap');
|
| 1224 |
-
|
| 1225 |
-
.gradio-container {
|
| 1226 |
-
background: linear-gradient(135deg, #667eea 0%, #764ba2 25%, #f093fb 50%, #f5576c 75%, #4facfe 100%);
|
| 1227 |
-
font-family: 'Space Grotesk', 'Inter', system-ui, sans-serif;
|
| 1228 |
-
min-height: 100vh;
|
| 1229 |
-
}
|
| 1230 |
-
|
| 1231 |
-
.main-header {
|
| 1232 |
-
text-align: center;
|
| 1233 |
-
color: white;
|
| 1234 |
-
margin-bottom: 30px;
|
| 1235 |
-
padding: 30px;
|
| 1236 |
-
background: rgba(255,255,255,0.1);
|
| 1237 |
-
border-radius: 20px;
|
| 1238 |
-
backdrop-filter: blur(20px);
|
| 1239 |
-
border: 1px solid rgba(255,255,255,0.2);
|
| 1240 |
-
box-shadow: 0 20px 40px rgba(0,0,0,0.1);
|
| 1241 |
-
position: relative;
|
| 1242 |
-
z-index: 1;
|
| 1243 |
-
}
|
| 1244 |
-
|
| 1245 |
-
.feature-card {
|
| 1246 |
-
background: rgba(255,255,255,0.1);
|
| 1247 |
-
border-radius: 15px;
|
| 1248 |
-
padding: 20px;
|
| 1249 |
-
backdrop-filter: blur(15px);
|
| 1250 |
-
border: 1px solid rgba(255,255,255,0.2);
|
| 1251 |
-
box-shadow: 0 15px 30px rgba(0,0,0,0.1);
|
| 1252 |
-
margin: 10px 0;
|
| 1253 |
-
position: relative;
|
| 1254 |
-
z-index: 1;
|
| 1255 |
-
}
|
| 1256 |
-
|
| 1257 |
-
/* FIX: Dropdown positioning */
|
| 1258 |
-
.gradio-dropdown {
|
| 1259 |
-
position: relative !important;
|
| 1260 |
-
z-index: 100 !important;
|
| 1261 |
-
}
|
| 1262 |
-
|
| 1263 |
-
.gradio-dropdown .wrap {
|
| 1264 |
-
position: relative !important;
|
| 1265 |
-
}
|
| 1266 |
-
|
| 1267 |
-
.gradio-dropdown .wrap .wrap {
|
| 1268 |
-
position: relative !important;
|
| 1269 |
-
}
|
| 1270 |
-
|
| 1271 |
-
/* FIX: Dropdown menu positioning */
|
| 1272 |
-
.gradio-dropdown [role="listbox"],
|
| 1273 |
-
.gradio-dropdown .options,
|
| 1274 |
-
.gradio-dropdown .dropdown-menu {
|
| 1275 |
-
position: absolute !important;
|
| 1276 |
-
top: 100% !important;
|
| 1277 |
-
left: 0 !important;
|
| 1278 |
-
right: 0 !important;
|
| 1279 |
-
z-index: 1000 !important;
|
| 1280 |
-
transform: none !important;
|
| 1281 |
-
margin-top: 2px !important;
|
| 1282 |
-
background: rgba(255, 255, 255, 0.95) !important;
|
| 1283 |
-
backdrop-filter: blur(10px) !important;
|
| 1284 |
-
border-radius: 10px !important;
|
| 1285 |
-
border: 1px solid rgba(255,255,255,0.3) !important;
|
| 1286 |
-
box-shadow: 0 10px 25px rgba(0,0,0,0.2) !important;
|
| 1287 |
-
max-height: 200px !important;
|
| 1288 |
-
overflow-y: auto !important;
|
| 1289 |
-
}
|
| 1290 |
-
|
| 1291 |
-
/* FIX: Dropdown options styling */
|
| 1292 |
-
.gradio-dropdown [role="option"],
|
| 1293 |
-
.gradio-dropdown .option {
|
| 1294 |
-
padding: 10px 15px !important;
|
| 1295 |
-
color: #333 !important;
|
| 1296 |
-
font-weight: 500 !important;
|
| 1297 |
-
border-bottom: 1px solid rgba(0,0,0,0.1) !important;
|
| 1298 |
-
}
|
| 1299 |
-
|
| 1300 |
-
.gradio-dropdown [role="option"]:hover,
|
| 1301 |
-
.gradio-dropdown .option:hover {
|
| 1302 |
-
background: rgba(52, 152, 219, 0.2) !important;
|
| 1303 |
-
color: #2c3e50 !important;
|
| 1304 |
-
}
|
| 1305 |
-
|
| 1306 |
-
.gradio-button-primary {
|
| 1307 |
-
background: linear-gradient(45deg, #ff6b6b, #ee5a24, #ff9ff3, #54a0ff) !important;
|
| 1308 |
-
border: none !important;
|
| 1309 |
-
border-radius: 15px !important;
|
| 1310 |
-
padding: 15px 25px !important;
|
| 1311 |
-
font-weight: 600 !important;
|
| 1312 |
-
color: white !important;
|
| 1313 |
-
box-shadow: 0 10px 20px rgba(255, 107, 107, 0.3) !important;
|
| 1314 |
-
transition: all 0.3s ease !important;
|
| 1315 |
-
position: relative !important;
|
| 1316 |
-
z-index: 10 !important;
|
| 1317 |
-
}
|
| 1318 |
-
|
| 1319 |
-
.gradio-button-primary:hover {
|
| 1320 |
-
transform: translateY(-2px) !important;
|
| 1321 |
-
box-shadow: 0 15px 30px rgba(255, 107, 107, 0.5) !important;
|
| 1322 |
-
}
|
| 1323 |
-
|
| 1324 |
-
.gradio-button-secondary {
|
| 1325 |
-
background: linear-gradient(45deg, #feca57, #ff9ff3, #54a0ff, #5f27cd) !important;
|
| 1326 |
-
border: none !important;
|
| 1327 |
-
border-radius: 12px !important;
|
| 1328 |
-
padding: 12px 20px !important;
|
| 1329 |
-
font-weight: 600 !important;
|
| 1330 |
-
color: white !important;
|
| 1331 |
-
box-shadow: 0 8px 16px rgba(254, 202, 87, 0.3) !important;
|
| 1332 |
-
position: relative !important;
|
| 1333 |
-
z-index: 10 !important;
|
| 1334 |
-
}
|
| 1335 |
-
|
| 1336 |
-
.status-badge {
|
| 1337 |
-
background: linear-gradient(90deg, #2ecc71, #27ae60);
|
| 1338 |
-
color: white;
|
| 1339 |
-
padding: 10px 20px;
|
| 1340 |
-
border-radius: 10px;
|
| 1341 |
-
text-align: center;
|
| 1342 |
-
font-weight: 600;
|
| 1343 |
-
box-shadow: 0 8px 16px rgba(46, 204, 113, 0.3);
|
| 1344 |
-
margin: 10px 0;
|
| 1345 |
-
position: relative;
|
| 1346 |
-
z-index: 1;
|
| 1347 |
-
}
|
| 1348 |
-
|
| 1349 |
-
/* FIX: Ensure proper stacking context */
|
| 1350 |
-
.gradio-row {
|
| 1351 |
-
position: relative !important;
|
| 1352 |
-
z-index: auto !important;
|
| 1353 |
-
}
|
| 1354 |
-
|
| 1355 |
-
.gradio-column {
|
| 1356 |
-
position: relative !important;
|
| 1357 |
-
z-index: auto !important;
|
| 1358 |
-
}
|
| 1359 |
-
|
| 1360 |
-
/* FIX: Tab content positioning */
|
| 1361 |
-
.gradio-tabs {
|
| 1362 |
-
position: relative !important;
|
| 1363 |
-
z-index: 1 !important;
|
| 1364 |
-
}
|
| 1365 |
-
|
| 1366 |
-
.gradio-tabitem {
|
| 1367 |
-
position: relative !important;
|
| 1368 |
-
z-index: 1 !important;
|
| 1369 |
-
}
|
| 1370 |
-
|
| 1371 |
-
/* Fix dropdown positioning directly */
|
| 1372 |
-
.dropdown-container,
|
| 1373 |
-
.gradio-dropdown,
|
| 1374 |
-
[data-testid="dropdown"] {
|
| 1375 |
-
position: relative !important;
|
| 1376 |
-
z-index: auto !important;
|
| 1377 |
-
transform: none !important;
|
| 1378 |
-
}
|
| 1379 |
-
|
| 1380 |
-
/* Force dropdown menu to appear below */
|
| 1381 |
-
.dropdown-container .options,
|
| 1382 |
-
.gradio-dropdown .options,
|
| 1383 |
-
[role="listbox"] {
|
| 1384 |
-
position: absolute !important;
|
| 1385 |
-
top: 100% !important;
|
| 1386 |
-
left: 0 !important;
|
| 1387 |
-
right: 0 !important;
|
| 1388 |
-
z-index: 9999 !important;
|
| 1389 |
-
transform: translateY(0) !important;
|
| 1390 |
-
}
|
| 1391 |
-
"""
|
| 1392 |
-
|
| 1393 |
-
with gr.Blocks(css=css, title="📱 Instagram Generator", theme=gr.themes.Glass()) as app:
|
| 1394 |
|
| 1395 |
-
#
|
| 1396 |
gr.HTML(f"""
|
| 1397 |
-
<
|
| 1398 |
-
|
| 1399 |
-
|
| 1400 |
-
</h1>
|
| 1401 |
-
<h2 style="font-size: 1.2rem; margin-bottom: 20px; opacity: 0.9;">
|
| 1402 |
-
🚀 AI-Powered Content Creation • SambaNova + Hugging Face
|
| 1403 |
-
</h2>
|
| 1404 |
-
<div style="display: flex; justify-content: center; gap: 20px; margin-top: 15px;">
|
| 1405 |
-
<span style="background: rgba(255,255,255,0.2); padding: 8px 16px; border-radius: 15px;">🤖 SambaNova: {sambanova_status}</span>
|
| 1406 |
-
<span style="background: rgba(255,255,255,0.2); padding: 8px 16px; border-radius: 15px;">🤗 Hugging Face: {hf_status}</span>
|
| 1407 |
-
</div>
|
| 1408 |
-
</div>
|
| 1409 |
""")
|
| 1410 |
|
| 1411 |
# Main Interface
|
| 1412 |
with gr.Tab("🎯 Caption Generator"):
|
| 1413 |
with gr.Row():
|
| 1414 |
# Left Column - Controls
|
| 1415 |
-
with gr.Column(scale=2
|
| 1416 |
gr.Markdown("### 🖼️ Upload Images")
|
| 1417 |
-
gr.Markdown("*SambaNova AI vision analysis with quality scoring*")
|
| 1418 |
|
| 1419 |
images = gr.File(
|
| 1420 |
label="📸 Upload Images (Max 3)",
|
| 1421 |
file_count="multiple",
|
| 1422 |
-
file_types=["image"]
|
| 1423 |
-
height=200
|
| 1424 |
)
|
| 1425 |
|
| 1426 |
gr.Markdown("### ⚙️ Configuration")
|
| 1427 |
|
| 1428 |
-
|
| 1429 |
-
|
| 1430 |
-
|
| 1431 |
-
|
| 1432 |
-
|
| 1433 |
-
|
| 1434 |
-
|
| 1435 |
-
|
| 1436 |
-
|
| 1437 |
-
|
| 1438 |
-
|
| 1439 |
-
|
| 1440 |
-
|
| 1441 |
-
|
| 1442 |
-
|
| 1443 |
-
|
| 1444 |
-
|
| 1445 |
-
|
| 1446 |
-
|
| 1447 |
-
|
| 1448 |
-
|
| 1449 |
-
|
| 1450 |
-
|
| 1451 |
-
|
| 1452 |
-
|
| 1453 |
-
|
| 1454 |
-
],
|
| 1455 |
-
value="🌟 General Audience",
|
| 1456 |
-
label="👥 Target Audience"
|
| 1457 |
-
)
|
| 1458 |
|
| 1459 |
custom_prompt = gr.Textbox(
|
| 1460 |
label="💬 Additional Instructions",
|
|
@@ -1464,42 +1280,37 @@ def create_gradio_app():
|
|
| 1464 |
|
| 1465 |
generate_btn = gr.Button(
|
| 1466 |
"🚀 Generate Caption",
|
| 1467 |
-
variant="primary"
|
| 1468 |
-
size="lg"
|
| 1469 |
)
|
| 1470 |
|
| 1471 |
# Right Column - Results
|
| 1472 |
-
with gr.Column(scale=3
|
| 1473 |
gr.Markdown("### 📊 Generated Content")
|
| 1474 |
|
| 1475 |
output = gr.Textbox(
|
| 1476 |
label="🎯 Generated Caption",
|
| 1477 |
lines=15,
|
| 1478 |
-
max_lines=20,
|
| 1479 |
show_copy_button=True,
|
| 1480 |
placeholder="Upload images and generate your Instagram content..."
|
| 1481 |
)
|
| 1482 |
|
| 1483 |
-
|
| 1484 |
-
|
| 1485 |
-
|
| 1486 |
-
|
| 1487 |
-
scale=1
|
| 1488 |
-
)
|
| 1489 |
|
| 1490 |
alternatives_output = gr.Textbox(
|
| 1491 |
label="✨ Alternative Captions",
|
| 1492 |
lines=15,
|
| 1493 |
show_copy_button=True,
|
| 1494 |
-
placeholder="Generate 3 different caption alternatives
|
| 1495 |
)
|
| 1496 |
|
| 1497 |
# Multi-Language Tab
|
| 1498 |
with gr.Tab("🌍 Multi-Language"):
|
| 1499 |
with gr.Row():
|
| 1500 |
-
with gr.Column(
|
| 1501 |
gr.Markdown("### 🗣️ Global Content Creation")
|
| 1502 |
-
gr.Markdown("*Powered by Hugging Face Translation Models*")
|
| 1503 |
|
| 1504 |
base_caption_input = gr.Textbox(
|
| 1505 |
label="📝 Base Caption",
|
|
@@ -1523,7 +1334,7 @@ def create_gradio_app():
|
|
| 1523 |
variant="primary"
|
| 1524 |
)
|
| 1525 |
|
| 1526 |
-
with gr.Column(
|
| 1527 |
multilingual_output = gr.Textbox(
|
| 1528 |
label="🗺️ Multi-Language Captions",
|
| 1529 |
lines=20,
|
|
@@ -1531,161 +1342,6 @@ def create_gradio_app():
|
|
| 1531 |
placeholder="Culturally adapted captions for global audiences..."
|
| 1532 |
)
|
| 1533 |
|
| 1534 |
-
# SambaNova Features Tab
|
| 1535 |
-
with gr.Tab("🤖 SambaNova Features"):
|
| 1536 |
-
gr.HTML(f"""
|
| 1537 |
-
<div class="status-badge">
|
| 1538 |
-
🚀 SambaNova Status: {sambanova_status} • 🦙 Llama-4-Maverick + Llama-3.2-3B
|
| 1539 |
-
</div>
|
| 1540 |
-
""")
|
| 1541 |
-
|
| 1542 |
-
with gr.Row():
|
| 1543 |
-
with gr.Column(elem_classes=["feature-card"]):
|
| 1544 |
-
gr.HTML("""
|
| 1545 |
-
<div style="text-align: center; padding: 20px;">
|
| 1546 |
-
<h3>⚡ SambaNova AI Capabilities</h3>
|
| 1547 |
-
<div style="display: grid; grid-template-columns: repeat(2, 1fr); gap: 15px; margin-top: 20px;">
|
| 1548 |
-
<div style="padding: 15px; background: rgba(46, 204, 113, 0.2); border-radius: 10px; border: 2px solid #2ecc71;">
|
| 1549 |
-
<h4 style="color: #ffffff; margin: 0; text-shadow: 0 0 10px #2ecc71;">Llama-4-Maverick</h4>
|
| 1550 |
-
<p style="margin: 5px 0; color: #e8f8f5; font-weight: 500;">Main Caption Generation</p>
|
| 1551 |
-
</div>
|
| 1552 |
-
<div style="padding: 15px; background: rgba(52, 152, 219, 0.2); border-radius: 10px; border: 2px solid #3498db;">
|
| 1553 |
-
<h4 style="color: #ffffff; margin: 0; text-shadow: 0 0 10px #3498db;">Llama-3.2-3B</h4>
|
| 1554 |
-
<p style="margin: 5px 0; color: #ebf3fd; font-weight: 500;">Caption Variations</p>
|
| 1555 |
-
</div>
|
| 1556 |
-
<div style="padding: 15px; background: rgba(231, 76, 60, 0.2); border-radius: 10px; border: 2px solid #e74c3c;">
|
| 1557 |
-
<h4 style="color: #ffffff; margin: 0; text-shadow: 0 0 10px #e74c3c;">Multi-Modal</h4>
|
| 1558 |
-
<p style="margin: 5px 0; color: #fdedec; font-weight: 500;">Vision + Text Analysis</p>
|
| 1559 |
-
</div>
|
| 1560 |
-
<div style="padding: 15px; background: rgba(155, 89, 182, 0.2); border-radius: 10px; border: 2px solid #9b59b6;">
|
| 1561 |
-
<h4 style="color: #ffffff; margin: 0; text-shadow: 0 0 10px #9b59b6;">Advanced</h4>
|
| 1562 |
-
<p style="margin: 5px 0; color: #f4ecf7; font-weight: 500;">Style & Audience Targeting</p>
|
| 1563 |
-
</div>
|
| 1564 |
-
</div>
|
| 1565 |
-
</div>
|
| 1566 |
-
""")
|
| 1567 |
-
|
| 1568 |
-
with gr.Column(elem_classes=["feature-card"]):
|
| 1569 |
-
gr.Code(
|
| 1570 |
-
value="""
|
| 1571 |
-
# SambaNova API Integration:
|
| 1572 |
-
|
| 1573 |
-
from openai import OpenAI
|
| 1574 |
-
|
| 1575 |
-
client = OpenAI(
|
| 1576 |
-
api_key=os.environ["SAMBANOVA_API_KEY"],
|
| 1577 |
-
base_url="https://api.sambanova.ai/v1",
|
| 1578 |
-
)
|
| 1579 |
-
|
| 1580 |
-
# Main caption generation
|
| 1581 |
-
response = client.chat.completions.create(
|
| 1582 |
-
model="Llama-4-Maverick-17B-128E-Instruct",
|
| 1583 |
-
messages=[{
|
| 1584 |
-
"role": "user",
|
| 1585 |
-
"content": [
|
| 1586 |
-
{"type": "text", "text": "Create Instagram caption"},
|
| 1587 |
-
{"type": "image_url", "image_url": {"url": "data:image/jpeg;base64,..."}}
|
| 1588 |
-
]
|
| 1589 |
-
}],
|
| 1590 |
-
temperature=0.1,
|
| 1591 |
-
top_p=0.1
|
| 1592 |
-
)
|
| 1593 |
-
|
| 1594 |
-
# Caption variations
|
| 1595 |
-
variations = client.chat.completions.create(
|
| 1596 |
-
model="Meta-Llama-3.2-3B-Instruct",
|
| 1597 |
-
messages=[{
|
| 1598 |
-
"role": "user",
|
| 1599 |
-
"content": "Create different version of this caption..."
|
| 1600 |
-
}],
|
| 1601 |
-
temperature=0.9,
|
| 1602 |
-
top_p=0.95
|
| 1603 |
-
)
|
| 1604 |
-
""",
|
| 1605 |
-
language="python",
|
| 1606 |
-
label="🔧 SambaNova Integration Code"
|
| 1607 |
-
)
|
| 1608 |
-
|
| 1609 |
-
# Hugging Face Features Tab
|
| 1610 |
-
with gr.Tab("🤗 Hugging Face Features"):
|
| 1611 |
-
gr.HTML(f"""
|
| 1612 |
-
<div class="status-badge">
|
| 1613 |
-
🤗 Hugging Face Status: {hf_status} • 🌍 Multi-Language Translation
|
| 1614 |
-
</div>
|
| 1615 |
-
""")
|
| 1616 |
-
|
| 1617 |
-
with gr.Row():
|
| 1618 |
-
with gr.Column(elem_classes=["feature-card"]):
|
| 1619 |
-
gr.HTML("""
|
| 1620 |
-
<div style="text-align: center; padding: 20px;">
|
| 1621 |
-
<h3>🌍 Translation Models</h3>
|
| 1622 |
-
<div style="display: grid; grid-template-columns: repeat(2, 1fr); gap: 15px; margin-top: 20px;">
|
| 1623 |
-
<div style="padding: 15px; background: rgba(46, 204, 113, 0.2); border-radius: 10px; border: 2px solid #2ecc71;">
|
| 1624 |
-
<h4 style="color: #ffffff; margin: 0; text-shadow: 0 0 10px #2ecc71;">🇩🇪 German</h4>
|
| 1625 |
-
<p style="margin: 5px 0; color: #e8f8f5; font-weight: 500;">google-t5/t5-small</p>
|
| 1626 |
-
</div>
|
| 1627 |
-
<div style="padding: 15px; background: rgba(52, 152, 219, 0.2); border-radius: 10px; border: 2px solid #3498db;">
|
| 1628 |
-
<h4 style="color: #ffffff; margin: 0; text-shadow: 0 0 10px #3498db;">🇨🇳 Chinese</h4>
|
| 1629 |
-
<p style="margin: 5px 0; color: #ebf3fd; font-weight: 500;">chence08/mt5-small-iwslt2017-zh-en</p>
|
| 1630 |
-
</div>
|
| 1631 |
-
<div style="padding: 15px; background: rgba(231, 76, 60, 0.2); border-radius: 10px; border: 2px solid #e74c3c;">
|
| 1632 |
-
<h4 style="color: #ffffff; margin: 0; text-shadow: 0 0 10px #e74c3c;">🇮🇳 Hindi</h4>
|
| 1633 |
-
<p style="margin: 5px 0; color: #fdedec; font-weight: 500;">Helsinki-NLP/opus-mt-en-hi</p>
|
| 1634 |
-
</div>
|
| 1635 |
-
<div style="padding: 15px; background: rgba(155, 89, 182, 0.2); border-radius: 10px; border: 2px solid #9b59b6;">
|
| 1636 |
-
<h4 style="color: #ffffff; margin: 0; text-shadow: 0 0 10px #9b59b6;">🇸🇦 Arabic</h4>
|
| 1637 |
-
<p style="margin: 5px 0; color: #f4ecf7; font-weight: 500;">marefa-nlp/marefa-mt-en-ar</p>
|
| 1638 |
-
</div>
|
| 1639 |
-
</div>
|
| 1640 |
-
</div>
|
| 1641 |
-
""")
|
| 1642 |
-
|
| 1643 |
-
with gr.Column(elem_classes=["feature-card"]):
|
| 1644 |
-
gr.Code(
|
| 1645 |
-
value="""
|
| 1646 |
-
# Hugging Face Translation Integration:
|
| 1647 |
-
|
| 1648 |
-
from huggingface_hub import InferenceClient
|
| 1649 |
-
|
| 1650 |
-
client = InferenceClient(
|
| 1651 |
-
provider="hf-inference",
|
| 1652 |
-
api_key=os.environ["HF_TOKEN"],
|
| 1653 |
-
)
|
| 1654 |
-
|
| 1655 |
-
# German translation
|
| 1656 |
-
german_result = client.translation(
|
| 1657 |
-
"This is an amazing moment! ✨",
|
| 1658 |
-
model="google-t5/t5-small",
|
| 1659 |
-
)
|
| 1660 |
-
|
| 1661 |
-
# Chinese translation
|
| 1662 |
-
chinese_result = client.translation(
|
| 1663 |
-
"Amazing content for Instagram",
|
| 1664 |
-
model="chence08/mt5-small-iwslt2017-zh-en",
|
| 1665 |
-
)
|
| 1666 |
-
|
| 1667 |
-
# Hindi translation
|
| 1668 |
-
hindi_result = client.translation(
|
| 1669 |
-
"Beautiful content creation",
|
| 1670 |
-
model="Helsinki-NLP/opus-mt-en-hi",
|
| 1671 |
-
)
|
| 1672 |
-
|
| 1673 |
-
# Arabic translation
|
| 1674 |
-
arabic_result = client.translation(
|
| 1675 |
-
"Social media content",
|
| 1676 |
-
model="marefa-nlp/marefa-mt-en-ar",
|
| 1677 |
-
)
|
| 1678 |
-
|
| 1679 |
-
# Features:
|
| 1680 |
-
# ✅ 4 language models
|
| 1681 |
-
# ✅ Fallback support
|
| 1682 |
-
# ✅ Instagram-optimized output
|
| 1683 |
-
# ✅ Cultural adaptation
|
| 1684 |
-
""",
|
| 1685 |
-
language="python",
|
| 1686 |
-
label="🔧 Hugging Face Translation Code"
|
| 1687 |
-
)
|
| 1688 |
-
|
| 1689 |
# Event Handlers
|
| 1690 |
generate_btn.click(
|
| 1691 |
fn=generate_advanced_caption_interface,
|
|
@@ -1693,14 +1349,12 @@ arabic_result = client.translation(
|
|
| 1693 |
outputs=[output, base_caption_input]
|
| 1694 |
)
|
| 1695 |
|
| 1696 |
-
# Generate multiple alternatives
|
| 1697 |
alternatives_btn.click(
|
| 1698 |
fn=generate_multiple_captions_interface,
|
| 1699 |
inputs=[images, caption_style, target_audience, custom_prompt],
|
| 1700 |
outputs=alternatives_output
|
| 1701 |
)
|
| 1702 |
|
| 1703 |
-
# Multi-language translation
|
| 1704 |
translate_btn.click(
|
| 1705 |
fn=translate_caption_interface,
|
| 1706 |
inputs=[base_caption_input, language_selector],
|
|
@@ -1709,7 +1363,6 @@ arabic_result = client.translation(
|
|
| 1709 |
|
| 1710 |
return app
|
| 1711 |
|
| 1712 |
-
|
| 1713 |
def main():
|
| 1714 |
"""Main function to launch the Instagram Caption Generator"""
|
| 1715 |
print("🚀 Starting Instagram Caption Generator...")
|
|
|
|
| 1211 |
|
| 1212 |
# Replace the CSS section in your create_gradio_app() function with this fixed version:
|
| 1213 |
|
| 1214 |
+
# Replace the problematic dropdowns with radio buttons - this completely avoids the positioning issue
|
| 1215 |
+
|
| 1216 |
def create_gradio_app():
|
| 1217 |
+
"""Create the Gradio app with radio buttons instead of dropdowns"""
|
| 1218 |
|
| 1219 |
# Status indicators
|
| 1220 |
hf_status = "✅ Connected" if generator and generator.hf_client_working else "⚠️ Fallback Mode"
|
| 1221 |
sambanova_status = "✅ Connected" if generator and generator.sambanova_client_working else "⚠️ Fallback Mode"
|
| 1222 |
|
| 1223 |
+
# NO CUSTOM CSS AT ALL
|
| 1224 |
+
with gr.Blocks(title="📱 Instagram Generator") as app:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1225 |
|
| 1226 |
+
# Simple header
|
| 1227 |
gr.HTML(f"""
|
| 1228 |
+
<h1>📱 INSTAGRAM CAPTION GENERATOR</h1>
|
| 1229 |
+
<p>🚀 AI-Powered Content Creation • SambaNova + Hugging Face</p>
|
| 1230 |
+
<p>🤖 SambaNova: {sambanova_status} | 🤗 Hugging Face: {hf_status}</p>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1231 |
""")
|
| 1232 |
|
| 1233 |
# Main Interface
|
| 1234 |
with gr.Tab("🎯 Caption Generator"):
|
| 1235 |
with gr.Row():
|
| 1236 |
# Left Column - Controls
|
| 1237 |
+
with gr.Column(scale=2):
|
| 1238 |
gr.Markdown("### 🖼️ Upload Images")
|
|
|
|
| 1239 |
|
| 1240 |
images = gr.File(
|
| 1241 |
label="📸 Upload Images (Max 3)",
|
| 1242 |
file_count="multiple",
|
| 1243 |
+
file_types=["image"]
|
|
|
|
| 1244 |
)
|
| 1245 |
|
| 1246 |
gr.Markdown("### ⚙️ Configuration")
|
| 1247 |
|
| 1248 |
+
# REPLACE DROPDOWNS WITH RADIO BUTTONS
|
| 1249 |
+
caption_style = gr.Radio(
|
| 1250 |
+
choices=[
|
| 1251 |
+
"🎯 Viral Engagement",
|
| 1252 |
+
"💼 Professional Brand",
|
| 1253 |
+
"😄 Casual Fun",
|
| 1254 |
+
"😂 Humor & Memes",
|
| 1255 |
+
"💪 Motivational",
|
| 1256 |
+
"📖 Storytelling"
|
| 1257 |
+
],
|
| 1258 |
+
value="🎯 Viral Engagement",
|
| 1259 |
+
label="🎨 Caption Style"
|
| 1260 |
+
)
|
| 1261 |
+
|
| 1262 |
+
target_audience = gr.Radio(
|
| 1263 |
+
choices=[
|
| 1264 |
+
"🌟 General Audience",
|
| 1265 |
+
"💼 Business Professionals",
|
| 1266 |
+
"✈️ Travel Enthusiasts",
|
| 1267 |
+
"🍕 Food Lovers",
|
| 1268 |
+
"💪 Fitness Community",
|
| 1269 |
+
"👗 Fashion Forward"
|
| 1270 |
+
],
|
| 1271 |
+
value="🌟 General Audience",
|
| 1272 |
+
label="👥 Target Audience"
|
| 1273 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1274 |
|
| 1275 |
custom_prompt = gr.Textbox(
|
| 1276 |
label="💬 Additional Instructions",
|
|
|
|
| 1280 |
|
| 1281 |
generate_btn = gr.Button(
|
| 1282 |
"🚀 Generate Caption",
|
| 1283 |
+
variant="primary"
|
|
|
|
| 1284 |
)
|
| 1285 |
|
| 1286 |
# Right Column - Results
|
| 1287 |
+
with gr.Column(scale=3):
|
| 1288 |
gr.Markdown("### 📊 Generated Content")
|
| 1289 |
|
| 1290 |
output = gr.Textbox(
|
| 1291 |
label="🎯 Generated Caption",
|
| 1292 |
lines=15,
|
|
|
|
| 1293 |
show_copy_button=True,
|
| 1294 |
placeholder="Upload images and generate your Instagram content..."
|
| 1295 |
)
|
| 1296 |
|
| 1297 |
+
alternatives_btn = gr.Button(
|
| 1298 |
+
"✨ Generate 3 Alternative Captions",
|
| 1299 |
+
variant="secondary"
|
| 1300 |
+
)
|
|
|
|
|
|
|
| 1301 |
|
| 1302 |
alternatives_output = gr.Textbox(
|
| 1303 |
label="✨ Alternative Captions",
|
| 1304 |
lines=15,
|
| 1305 |
show_copy_button=True,
|
| 1306 |
+
placeholder="Generate 3 different caption alternatives..."
|
| 1307 |
)
|
| 1308 |
|
| 1309 |
# Multi-Language Tab
|
| 1310 |
with gr.Tab("🌍 Multi-Language"):
|
| 1311 |
with gr.Row():
|
| 1312 |
+
with gr.Column():
|
| 1313 |
gr.Markdown("### 🗣️ Global Content Creation")
|
|
|
|
| 1314 |
|
| 1315 |
base_caption_input = gr.Textbox(
|
| 1316 |
label="📝 Base Caption",
|
|
|
|
| 1334 |
variant="primary"
|
| 1335 |
)
|
| 1336 |
|
| 1337 |
+
with gr.Column():
|
| 1338 |
multilingual_output = gr.Textbox(
|
| 1339 |
label="🗺️ Multi-Language Captions",
|
| 1340 |
lines=20,
|
|
|
|
| 1342 |
placeholder="Culturally adapted captions for global audiences..."
|
| 1343 |
)
|
| 1344 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1345 |
# Event Handlers
|
| 1346 |
generate_btn.click(
|
| 1347 |
fn=generate_advanced_caption_interface,
|
|
|
|
| 1349 |
outputs=[output, base_caption_input]
|
| 1350 |
)
|
| 1351 |
|
|
|
|
| 1352 |
alternatives_btn.click(
|
| 1353 |
fn=generate_multiple_captions_interface,
|
| 1354 |
inputs=[images, caption_style, target_audience, custom_prompt],
|
| 1355 |
outputs=alternatives_output
|
| 1356 |
)
|
| 1357 |
|
|
|
|
| 1358 |
translate_btn.click(
|
| 1359 |
fn=translate_caption_interface,
|
| 1360 |
inputs=[base_caption_input, language_selector],
|
|
|
|
| 1363 |
|
| 1364 |
return app
|
| 1365 |
|
|
|
|
| 1366 |
def main():
|
| 1367 |
"""Main function to launch the Instagram Caption Generator"""
|
| 1368 |
print("🚀 Starting Instagram Caption Generator...")
|