Update app.py
Browse files
app.py
CHANGED
|
@@ -1209,14 +1209,16 @@ async def translate_caption_interface(base_caption, selected_languages):
|
|
| 1209 |
return result
|
| 1210 |
|
| 1211 |
|
|
|
|
|
|
|
| 1212 |
def create_gradio_app():
|
| 1213 |
-
"""Create the Gradio app with
|
| 1214 |
|
| 1215 |
# Status indicators
|
| 1216 |
hf_status = "✅ Connected" if generator and generator.hf_client_working else "⚠️ Fallback Mode"
|
| 1217 |
sambanova_status = "✅ Connected" if generator and generator.sambanova_client_working else "⚠️ Fallback Mode"
|
| 1218 |
|
| 1219 |
-
# Enhanced CSS for better
|
| 1220 |
css = """
|
| 1221 |
@import url('https://fonts.googleapis.com/css2?family=Space+Grotesk:wght@300;400;500;600;700&display=swap');
|
| 1222 |
|
|
@@ -1246,6 +1248,62 @@ def create_gradio_app():
|
|
| 1246 |
border: 1px solid rgba(255,255,255,0.2);
|
| 1247 |
box-shadow: 0 15px 30px rgba(0,0,0,0.1);
|
| 1248 |
margin: 10px 0;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1249 |
}
|
| 1250 |
|
| 1251 |
.gradio-button-primary {
|
|
@@ -1273,17 +1331,6 @@ def create_gradio_app():
|
|
| 1273 |
color: white !important;
|
| 1274 |
box-shadow: 0 8px 16px rgba(254, 202, 87, 0.3) !important;
|
| 1275 |
}
|
| 1276 |
-
|
| 1277 |
-
.status-badge {
|
| 1278 |
-
background: linear-gradient(90deg, #2ecc71, #27ae60);
|
| 1279 |
-
color: white;
|
| 1280 |
-
padding: 10px 20px;
|
| 1281 |
-
border-radius: 10px;
|
| 1282 |
-
text-align: center;
|
| 1283 |
-
font-weight: 600;
|
| 1284 |
-
box-shadow: 0 8px 16px rgba(46, 204, 113, 0.3);
|
| 1285 |
-
margin: 10px 0;
|
| 1286 |
-
}
|
| 1287 |
"""
|
| 1288 |
|
| 1289 |
with gr.Blocks(css=css, title="📱 Instagram Generator", theme=gr.themes.Glass()) as app:
|
|
@@ -1321,6 +1368,7 @@ def create_gradio_app():
|
|
| 1321 |
|
| 1322 |
gr.Markdown("### ⚙️ Configuration")
|
| 1323 |
|
|
|
|
| 1324 |
with gr.Row():
|
| 1325 |
caption_style = gr.Dropdown(
|
| 1326 |
choices=[
|
|
@@ -1331,10 +1379,22 @@ def create_gradio_app():
|
|
| 1331 |
"💪 Motivational",
|
| 1332 |
"📖 Storytelling",
|
| 1333 |
"🌟 Luxury Lifestyle",
|
| 1334 |
-
"🔥 Trending Culture"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1335 |
],
|
| 1336 |
value="🎯 Viral Engagement",
|
| 1337 |
-
label="🎨 Caption Style"
|
|
|
|
|
|
|
| 1338 |
)
|
| 1339 |
|
| 1340 |
target_audience = gr.Dropdown(
|
|
@@ -1346,16 +1406,49 @@ def create_gradio_app():
|
|
| 1346 |
"💪 Fitness Community",
|
| 1347 |
"👗 Fashion Forward",
|
| 1348 |
"💻 Tech Innovators",
|
| 1349 |
-
"🎨 Creative Artists"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1350 |
],
|
| 1351 |
value="🌟 General Audience",
|
| 1352 |
-
label="👥 Target Audience"
|
|
|
|
|
|
|
| 1353 |
)
|
| 1354 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1355 |
custom_prompt = gr.Textbox(
|
| 1356 |
label="💬 Additional Instructions",
|
| 1357 |
-
placeholder="e.g., 'Focus on sustainability', 'Include product details'...",
|
| 1358 |
-
lines=
|
| 1359 |
)
|
| 1360 |
|
| 1361 |
generate_btn = gr.Button(
|
|
@@ -1371,7 +1464,7 @@ def create_gradio_app():
|
|
| 1371 |
output = gr.Textbox(
|
| 1372 |
label="🎯 Generated Caption",
|
| 1373 |
lines=15,
|
| 1374 |
-
max_lines=
|
| 1375 |
show_copy_button=True,
|
| 1376 |
placeholder="Upload images and generate your Instagram content..."
|
| 1377 |
)
|
|
@@ -1382,6 +1475,11 @@ def create_gradio_app():
|
|
| 1382 |
variant="secondary",
|
| 1383 |
scale=1
|
| 1384 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1385 |
|
| 1386 |
alternatives_output = gr.Textbox(
|
| 1387 |
label="✨ Alternative Captions",
|
|
@@ -1390,7 +1488,7 @@ def create_gradio_app():
|
|
| 1390 |
placeholder="Generate 3 different caption alternatives using Meta-Llama-3.2-3B-Instruct..."
|
| 1391 |
)
|
| 1392 |
|
| 1393 |
-
# Multi-Language Tab
|
| 1394 |
with gr.Tab("🌍 Multi-Language"):
|
| 1395 |
with gr.Row():
|
| 1396 |
with gr.Column(elem_classes=["feature-card"]):
|
|
@@ -1408,7 +1506,15 @@ def create_gradio_app():
|
|
| 1408 |
"🇩🇪 German",
|
| 1409 |
"🇨🇳 Chinese",
|
| 1410 |
"🇮🇳 Hindi",
|
| 1411 |
-
"🇸🇦 Arabic"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1412 |
],
|
| 1413 |
label="🌐 Select Languages",
|
| 1414 |
value=["🇩🇪 German", "🇮🇳 Hindi"]
|
|
@@ -1427,184 +1533,87 @@ def create_gradio_app():
|
|
| 1427 |
placeholder="Culturally adapted captions for global audiences..."
|
| 1428 |
)
|
| 1429 |
|
| 1430 |
-
#
|
| 1431 |
-
with gr.Tab("
|
| 1432 |
-
gr.HTML(f"""
|
| 1433 |
-
<div class="status-badge">
|
| 1434 |
-
🚀 SambaNova Status: {sambanova_status} • 🦙 Llama-4-Maverick + Llama-3.2-3B
|
| 1435 |
-
</div>
|
| 1436 |
-
""")
|
| 1437 |
-
|
| 1438 |
with gr.Row():
|
| 1439 |
with gr.Column(elem_classes=["feature-card"]):
|
| 1440 |
-
gr.
|
| 1441 |
-
|
| 1442 |
-
|
| 1443 |
-
|
| 1444 |
-
|
| 1445 |
-
|
| 1446 |
-
|
| 1447 |
-
|
| 1448 |
-
|
| 1449 |
-
|
| 1450 |
-
|
| 1451 |
-
</div>
|
| 1452 |
-
<div style="padding: 15px; background: rgba(231, 76, 60, 0.2); border-radius: 10px; border: 2px solid #e74c3c;">
|
| 1453 |
-
<h4 style="color: #ffffff; margin: 0; text-shadow: 0 0 10px #e74c3c;">Multi-Modal</h4>
|
| 1454 |
-
<p style="margin: 5px 0; color: #fdedec; font-weight: 500;">Vision + Text Analysis</p>
|
| 1455 |
-
</div>
|
| 1456 |
-
<div style="padding: 15px; background: rgba(155, 89, 182, 0.2); border-radius: 10px; border: 2px solid #9b59b6;">
|
| 1457 |
-
<h4 style="color: #ffffff; margin: 0; text-shadow: 0 0 10px #9b59b6;">Advanced</h4>
|
| 1458 |
-
<p style="margin: 5px 0; color: #f4ecf7; font-weight: 500;">Style & Audience Targeting</p>
|
| 1459 |
-
</div>
|
| 1460 |
-
</div>
|
| 1461 |
-
</div>
|
| 1462 |
-
""")
|
| 1463 |
-
|
| 1464 |
-
with gr.Column(elem_classes=["feature-card"]):
|
| 1465 |
-
gr.Code(
|
| 1466 |
-
value="""
|
| 1467 |
-
# SambaNova API Integration:
|
| 1468 |
-
|
| 1469 |
-
from openai import OpenAI
|
| 1470 |
-
|
| 1471 |
-
client = OpenAI(
|
| 1472 |
-
api_key=os.environ["SAMBANOVA_API_KEY"],
|
| 1473 |
-
base_url="https://api.sambanova.ai/v1",
|
| 1474 |
-
)
|
| 1475 |
-
|
| 1476 |
-
# Main caption generation
|
| 1477 |
-
response = client.chat.completions.create(
|
| 1478 |
-
model="Llama-4-Maverick-17B-128E-Instruct",
|
| 1479 |
-
messages=[{
|
| 1480 |
-
"role": "user",
|
| 1481 |
-
"content": [
|
| 1482 |
-
{"type": "text", "text": "Create Instagram caption"},
|
| 1483 |
-
{"type": "image_url", "image_url": {"url": "data:image/jpeg;base64,..."}}
|
| 1484 |
-
]
|
| 1485 |
-
}],
|
| 1486 |
-
temperature=0.1,
|
| 1487 |
-
top_p=0.1
|
| 1488 |
-
)
|
| 1489 |
-
|
| 1490 |
-
# Caption variations
|
| 1491 |
-
variations = client.chat.completions.create(
|
| 1492 |
-
model="Meta-Llama-3.2-3B-Instruct",
|
| 1493 |
-
messages=[{
|
| 1494 |
-
"role": "user",
|
| 1495 |
-
"content": "Create different version of this caption..."
|
| 1496 |
-
}],
|
| 1497 |
-
temperature=0.9,
|
| 1498 |
-
top_p=0.95
|
| 1499 |
-
)
|
| 1500 |
-
""",
|
| 1501 |
-
language="python",
|
| 1502 |
-
label="🔧 SambaNova Integration Code"
|
| 1503 |
)
|
| 1504 |
-
|
| 1505 |
-
# Hugging Face Features Tab
|
| 1506 |
-
with gr.Tab("🤗 Hugging Face Features"):
|
| 1507 |
-
gr.HTML(f"""
|
| 1508 |
-
<div class="status-badge">
|
| 1509 |
-
🤗 Hugging Face Status: {hf_status} • 🌍 Multi-Language Translation
|
| 1510 |
-
</div>
|
| 1511 |
-
""")
|
| 1512 |
-
|
| 1513 |
-
with gr.Row():
|
| 1514 |
-
with gr.Column(elem_classes=["feature-card"]):
|
| 1515 |
-
gr.HTML("""
|
| 1516 |
-
<div style="text-align: center; padding: 20px;">
|
| 1517 |
-
<h3>🌍 Translation Models</h3>
|
| 1518 |
-
<div style="display: grid; grid-template-columns: repeat(2, 1fr); gap: 15px; margin-top: 20px;">
|
| 1519 |
-
<div style="padding: 15px; background: rgba(46, 204, 113, 0.2); border-radius: 10px; border: 2px solid #2ecc71;">
|
| 1520 |
-
<h4 style="color: #ffffff; margin: 0; text-shadow: 0 0 10px #2ecc71;">🇩🇪 German</h4>
|
| 1521 |
-
<p style="margin: 5px 0; color: #e8f8f5; font-weight: 500;">google-t5/t5-small</p>
|
| 1522 |
-
</div>
|
| 1523 |
-
<div style="padding: 15px; background: rgba(52, 152, 219, 0.2); border-radius: 10px; border: 2px solid #3498db;">
|
| 1524 |
-
<h4 style="color: #ffffff; margin: 0; text-shadow: 0 0 10px #3498db;">🇨🇳 Chinese</h4>
|
| 1525 |
-
<p style="margin: 5px 0; color: #ebf3fd; font-weight: 500;">chence08/mt5-small-iwslt2017-zh-en</p>
|
| 1526 |
-
</div>
|
| 1527 |
-
<div style="padding: 15px; background: rgba(231, 76, 60, 0.2); border-radius: 10px; border: 2px solid #e74c3c;">
|
| 1528 |
-
<h4 style="color: #ffffff; margin: 0; text-shadow: 0 0 10px #e74c3c;">🇮🇳 Hindi</h4>
|
| 1529 |
-
<p style="margin: 5px 0; color: #fdedec; font-weight: 500;">Helsinki-NLP/opus-mt-en-hi</p>
|
| 1530 |
-
</div>
|
| 1531 |
-
<div style="padding: 15px; background: rgba(155, 89, 182, 0.2); border-radius: 10px; border: 2px solid #9b59b6;">
|
| 1532 |
-
<h4 style="color: #ffffff; margin: 0; text-shadow: 0 0 10px #9b59b6;">🇸🇦 Arabic</h4>
|
| 1533 |
-
<p style="margin: 5px 0; color: #f4ecf7; font-weight: 500;">marefa-nlp/marefa-mt-en-ar</p>
|
| 1534 |
-
</div>
|
| 1535 |
-
</div>
|
| 1536 |
-
</div>
|
| 1537 |
-
""")
|
| 1538 |
|
| 1539 |
with gr.Column(elem_classes=["feature-card"]):
|
| 1540 |
-
gr.
|
| 1541 |
-
|
| 1542 |
-
|
| 1543 |
-
|
| 1544 |
-
|
| 1545 |
-
|
| 1546 |
-
|
| 1547 |
-
provider="hf-inference",
|
| 1548 |
-
api_key=os.environ["HF_TOKEN"],
|
| 1549 |
-
)
|
| 1550 |
-
|
| 1551 |
-
# German translation
|
| 1552 |
-
german_result = client.translation(
|
| 1553 |
-
"This is an amazing moment! ✨",
|
| 1554 |
-
model="google-t5/t5-small",
|
| 1555 |
-
)
|
| 1556 |
-
|
| 1557 |
-
# Chinese translation
|
| 1558 |
-
chinese_result = client.translation(
|
| 1559 |
-
"Amazing content for Instagram",
|
| 1560 |
-
model="chence08/mt5-small-iwslt2017-zh-en",
|
| 1561 |
-
)
|
| 1562 |
-
|
| 1563 |
-
# Hindi translation
|
| 1564 |
-
hindi_result = client.translation(
|
| 1565 |
-
"Beautiful content creation",
|
| 1566 |
-
model="Helsinki-NLP/opus-mt-en-hi",
|
| 1567 |
-
)
|
| 1568 |
|
| 1569 |
-
# Arabic translation
|
| 1570 |
-
arabic_result = client.translation(
|
| 1571 |
-
"Social media content",
|
| 1572 |
-
model="marefa-nlp/marefa-mt-en-ar",
|
| 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 |
-
translate_btn.click(
|
| 1601 |
-
fn=translate_caption_interface,
|
| 1602 |
-
inputs=[base_caption_input, language_selector],
|
| 1603 |
-
outputs=multilingual_output
|
| 1604 |
-
)
|
| 1605 |
|
| 1606 |
-
|
| 1607 |
-
|
|
|
|
|
|
|
| 1608 |
|
| 1609 |
def main():
|
| 1610 |
"""Main function to launch the Instagram Caption Generator"""
|
|
|
|
| 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 |
|
|
|
|
| 1248 |
border: 1px solid rgba(255,255,255,0.2);
|
| 1249 |
box-shadow: 0 15px 30px rgba(0,0,0,0.1);
|
| 1250 |
margin: 10px 0;
|
| 1251 |
+
position: relative;
|
| 1252 |
+
z-index: 1;
|
| 1253 |
+
}
|
| 1254 |
+
|
| 1255 |
+
/* FIX: Better dropdown styling */
|
| 1256 |
+
.gradio-dropdown {
|
| 1257 |
+
position: relative !important;
|
| 1258 |
+
z-index: 1000 !important;
|
| 1259 |
+
}
|
| 1260 |
+
|
| 1261 |
+
.gradio-dropdown .wrap {
|
| 1262 |
+
position: relative !important;
|
| 1263 |
+
z-index: 1000 !important;
|
| 1264 |
+
}
|
| 1265 |
+
|
| 1266 |
+
.gradio-dropdown .wrap.opened {
|
| 1267 |
+
z-index: 1001 !important;
|
| 1268 |
+
}
|
| 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;
|
| 1276 |
+
backdrop-filter: blur(20px) !important;
|
| 1277 |
+
border: 1px solid rgba(255, 255, 255, 0.3) !important;
|
| 1278 |
+
border-radius: 10px !important;
|
| 1279 |
+
box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2) !important;
|
| 1280 |
+
max-height: 200px !important;
|
| 1281 |
+
overflow-y: auto !important;
|
| 1282 |
+
z-index: 1002 !important;
|
| 1283 |
+
margin-top: 5px !important;
|
| 1284 |
+
}
|
| 1285 |
+
|
| 1286 |
+
.gradio-dropdown li {
|
| 1287 |
+
padding: 10px 15px !important;
|
| 1288 |
+
color: #333 !important;
|
| 1289 |
+
cursor: pointer !important;
|
| 1290 |
+
transition: all 0.2s ease !important;
|
| 1291 |
+
}
|
| 1292 |
+
|
| 1293 |
+
.gradio-dropdown li:hover {
|
| 1294 |
+
background: rgba(102, 126, 234, 0.1) !important;
|
| 1295 |
+
color: #667eea !important;
|
| 1296 |
+
}
|
| 1297 |
+
|
| 1298 |
+
.gradio-dropdown li.selected {
|
| 1299 |
+
background: rgba(102, 126, 234, 0.2) !important;
|
| 1300 |
+
color: #667eea !important;
|
| 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 |
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:
|
|
|
|
| 1368 |
|
| 1369 |
gr.Markdown("### ⚙️ Configuration")
|
| 1370 |
|
| 1371 |
+
# ENHANCED DROPDOWN OPTIONS
|
| 1372 |
with gr.Row():
|
| 1373 |
caption_style = gr.Dropdown(
|
| 1374 |
choices=[
|
|
|
|
| 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 |
"💪 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 |
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 |
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 |
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 |
"🇩🇪 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 |
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"""
|