GChilukala commited on
Commit
9dc0d8e
·
verified ·
1 Parent(s): 1847ef5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +131 -106
app.py CHANGED
@@ -7,7 +7,7 @@ Multi-Modal AI Analysis (Vision + Text) + Multi-Language Support
7
 
8
  🚀 Key Features:
9
  - SambaNova Llama-4-Maverick Integration
10
- - Multi-Language Support (German, Chinese, French, Arabic via Hugging Face)
11
  - Advanced Gradio Interface
12
  - Advanced Error Handling & Security
13
 
@@ -348,40 +348,40 @@ class AdvancedInstagramGenerator:
348
 
349
  return f"🇨🇳 CHINESE VERSION (Fallback):\n{translated}"
350
 
351
- def get_fallback_french_translation(self, text: str) -> str:
352
- """Fallback French translation when HF API fails"""
353
  # Simple keyword-based translation for common Instagram terms
354
- french_translations = {
355
- "amazing": "incroyable",
356
- "beautiful": "beau",
357
- "love": "amour",
358
- "perfect": "parfait",
359
- "awesome": "génial",
360
- "incredible": "incroyable",
361
- "follow": "suivre",
362
- "like": "j'aime",
363
- "share": "partager",
364
- "comment": "commenter",
365
- "today": "aujourd'hui",
366
- "moment": "moment",
367
- "life": "vie",
368
- "inspiration": "inspiration",
369
- "community": "communauté",
370
- "content": "contenu",
371
- "check out": "regardez",
372
- "what do you think": "qu'en pensez-vous"
373
  }
374
 
375
  # Basic word replacement (not perfect but functional fallback)
376
  translated = text.lower()
377
- for english, french in french_translations.items():
378
- translated = translated.replace(english, french)
379
 
380
- # Add French hashtags
381
  if "#" in translated:
382
- translated += " #France #Français #RéseauxSociaux #CréationDeContenu"
383
 
384
- return f"🇫🇷 FRENCH VERSION (Fallback):\n{translated}"
385
 
386
  def get_fallback_arabic_translation(self, text: str) -> str:
387
  """Fallback Arabic translation when HF API fails"""
@@ -1210,13 +1210,13 @@ async def translate_caption_interface(base_caption, selected_languages):
1210
 
1211
 
1212
  def create_gradio_app():
1213
- """Create the Gradio app with good UI styling"""
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 UI
1220
  css = """
1221
  @import url('https://fonts.googleapis.com/css2?family=Space+Grotesk:wght@300;400;500;600;700&display=swap');
1222
 
@@ -1224,107 +1224,136 @@ def create_gradio_app():
1224
  background: linear-gradient(135deg, #667eea 0%, #764ba2 25%, #f093fb 50%, #f5576c 75%, #4facfe 100%);
1225
  font-family: 'Space Grotesk', 'Inter', system-ui, sans-serif;
1226
  min-height: 100vh;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1227
  }
1228
 
1229
  .main-header {
1230
  text-align: center;
1231
  color: white;
1232
- margin-bottom: 30px;
1233
- padding: 30px;
1234
  background: rgba(255,255,255,0.1);
1235
- border-radius: 20px;
1236
- backdrop-filter: blur(20px);
1237
- border: 1px solid rgba(255,255,255,0.2);
1238
- box-shadow: 0 20px 40px rgba(0,0,0,0.1);
 
 
 
 
 
 
 
 
1239
  }
1240
 
1241
  .feature-card {
1242
- background: rgba(255,255,255,0.1);
1243
- border-radius: 15px;
1244
- padding: 20px;
1245
- backdrop-filter: blur(15px);
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 {
1252
  background: linear-gradient(45deg, #ff6b6b, #ee5a24, #ff9ff3, #54a0ff) !important;
 
 
1253
  border: none !important;
1254
- border-radius: 15px !important;
1255
- padding: 15px 25px !important;
1256
- font-weight: 600 !important;
1257
- color: white !important;
1258
- box-shadow: 0 10px 20px rgba(255, 107, 107, 0.3) !important;
 
1259
  transition: all 0.3s ease !important;
 
 
1260
  }
1261
 
1262
- .gradio-button-primary:hover {
1263
- transform: translateY(-2px) !important;
1264
- box-shadow: 0 15px 30px rgba(255, 107, 107, 0.5) !important;
 
1265
  }
1266
 
1267
- .gradio-button-secondary {
1268
- background: linear-gradient(45deg, #feca57, #ff9ff3, #54a0ff, #5f27cd) !important;
1269
- border: none !important;
1270
- border-radius: 12px !important;
1271
- padding: 12px 20px !important;
1272
- font-weight: 600 !important;
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
- .feature-card.config-card {
1289
- overflow: visible;
1290
- z-index: 10;
 
1291
  }
1292
  """
1293
 
1294
- with gr.Blocks(css=css, title="📱 Instagram Generator", theme=gr.themes.Glass()) as app:
1295
 
1296
  # Main Header
1297
- gr.HTML(f"""
1298
  <div class="main-header">
1299
- <h1 style="font-size: 2.5rem; margin-bottom: 15px; font-weight: 800; background: linear-gradient(45deg, #ff6b6b, #feca57, #ff9ff3, #54a0ff); -webkit-background-clip: text; -webkit-text-fill-color: transparent;">
1300
  📱 INSTAGRAM CAPTION GENERATOR
1301
  </h1>
1302
- <h2 style="font-size: 1.2rem; margin-bottom: 20px; opacity: 0.9;">
1303
- 🚀 AI-Powered Content Creation • SambaNova + Hugging Face
1304
  </h2>
1305
- <div style="display: flex; justify-content: center; gap: 20px; margin-top: 15px;">
1306
- <span style="background: rgba(255,255,255,0.2); padding: 8px 16px; border-radius: 15px;">🤖 SambaNova: {sambanova_status}</span>
1307
- <span style="background: rgba(255,255,255,0.2); padding: 8px 16px; border-radius: 15px;">🤗 Hugging Face: {hf_status}</span>
 
1308
  </div>
1309
  </div>
1310
  """)
1311
 
 
 
 
 
 
 
 
1312
  # Main Interface
1313
- with gr.Tab("🎯 Caption Generator"):
1314
  with gr.Row():
1315
  # Left Column - Controls
1316
- with gr.Column(scale=2, elem_classes=["feature-card", "config-card"]):
1317
- gr.Markdown("### 🖼️ Upload Images")
1318
  gr.Markdown("*SambaNova AI vision analysis with quality scoring*")
1319
 
1320
  images = gr.File(
1321
  label="📸 Upload Images (Max 3)",
1322
  file_count="multiple",
1323
- file_types=["image"],
1324
- height=200
1325
  )
1326
 
1327
- gr.Markdown("### ⚙️ Configuration")
1328
 
1329
  with gr.Row():
1330
  caption_style = gr.Dropdown(
@@ -1351,56 +1380,54 @@ def create_gradio_app():
1351
  "💪 Fitness Community",
1352
  "👗 Fashion Forward",
1353
  "💻 Tech Innovators",
1354
- "🎨 Creative Artists"
 
 
1355
  ],
1356
  value="🌟 General Audience",
1357
  label="👥 Target Audience"
1358
  )
1359
 
1360
  custom_prompt = gr.Textbox(
1361
- label="💬 Additional Instructions",
1362
- placeholder="e.g., 'Focus on sustainability', 'Include product details'...",
1363
- lines=2
1364
  )
1365
 
1366
  generate_btn = gr.Button(
1367
  "🚀 Generate Caption",
1368
- variant="primary",
1369
- size="lg"
1370
  )
1371
 
1372
  # Right Column - Results
1373
  with gr.Column(scale=3, elem_classes=["feature-card"]):
1374
- gr.Markdown("### 📊 Generated Content")
1375
 
1376
  output = gr.Textbox(
1377
  label="🎯 Generated Caption",
1378
  lines=15,
1379
- max_lines=20,
1380
  show_copy_button=True,
1381
- placeholder="Upload images and generate your Instagram content..."
1382
  )
1383
 
1384
- with gr.Row():
1385
- alternatives_btn = gr.Button(
1386
- "✨ Generate 3 Alternative Captions",
1387
- variant="secondary",
1388
- scale=1
1389
- )
1390
 
1391
  alternatives_output = gr.Textbox(
1392
  label="✨ Alternative Captions",
1393
  lines=15,
1394
  show_copy_button=True,
1395
- placeholder="Generate 3 different caption alternatives using Meta-Llama-3.2-3B-Instruct..."
1396
  )
1397
 
1398
  # Multi-Language Tab
1399
- with gr.Tab("🌍 Multi-Language"):
1400
  with gr.Row():
1401
- with gr.Column(elem_classes=["feature-card"]):
1402
  gr.Markdown("### 🗣️ Global Content Creation")
1403
- gr.Markdown("*Powered by Hugging Face Translation Models*")
1404
 
1405
  base_caption_input = gr.Textbox(
1406
  label="📝 Base Caption",
@@ -1424,7 +1451,7 @@ def create_gradio_app():
1424
  variant="primary"
1425
  )
1426
 
1427
- with gr.Column(elem_classes=["feature-card"]):
1428
  multilingual_output = gr.Textbox(
1429
  label="🗺️ Multi-Language Captions",
1430
  lines=20,
@@ -1435,7 +1462,7 @@ def create_gradio_app():
1435
  # SambaNova Features Tab
1436
  with gr.Tab("🤖 SambaNova Features"):
1437
  gr.HTML(f"""
1438
- <div class="status-badge">
1439
  🚀 SambaNova Status: {sambanova_status} • 🦙 Llama-4-Maverick + Llama-3.2-3B
1440
  </div>
1441
  """)
@@ -1510,7 +1537,7 @@ variations = client.chat.completions.create(
1510
  # Hugging Face Features Tab
1511
  with gr.Tab("🤗 Hugging Face Features"):
1512
  gr.HTML(f"""
1513
- <div class="status-badge">
1514
  🤗 Hugging Face Status: {hf_status} • 🌍 Multi-Language Translation
1515
  </div>
1516
  """)
@@ -1594,14 +1621,12 @@ arabic_result = client.translation(
1594
  outputs=[output, base_caption_input]
1595
  )
1596
 
1597
- # Generate multiple alternatives
1598
  alternatives_btn.click(
1599
  fn=generate_multiple_captions_interface,
1600
  inputs=[images, caption_style, target_audience, custom_prompt],
1601
  outputs=alternatives_output
1602
  )
1603
 
1604
- # Multi-language translation
1605
  translate_btn.click(
1606
  fn=translate_caption_interface,
1607
  inputs=[base_caption_input, language_selector],
 
7
 
8
  🚀 Key Features:
9
  - SambaNova Llama-4-Maverick Integration
10
+ - Multi-Language Support (German, Chinese, Hindi, Arabic via Hugging Face)
11
  - Advanced Gradio Interface
12
  - Advanced Error Handling & Security
13
 
 
348
 
349
  return f"🇨🇳 CHINESE VERSION (Fallback):\n{translated}"
350
 
351
+ def get_fallback_hindi_translation(self, text: str) -> str:
352
+ """Fallback Hindi translation when HF API fails"""
353
  # Simple keyword-based translation for common Instagram terms
354
+ hindi_translations = {
355
+ "amazing": "अद्भुत",
356
+ "beautiful": "सुंदर",
357
+ "love": "प्रेम",
358
+ "perfect": "परफेक्ट",
359
+ "awesome": "शानदार",
360
+ "incredible": "अविश्वसनीय",
361
+ "follow": "फॉलो",
362
+ "like": "लाइक",
363
+ "share": "शेयर",
364
+ "comment": "कमेंट",
365
+ "today": "आज",
366
+ "moment": "पल",
367
+ "life": "जिंदगी",
368
+ "inspiration": "प्रेरणा",
369
+ "community": "समुदाय",
370
+ "content": "सामग्री",
371
+ "check out": "देखें",
372
+ "what do you think": "आपको क्या लगता है"
373
  }
374
 
375
  # Basic word replacement (not perfect but functional fallback)
376
  translated = text.lower()
377
+ for english, hindi in hindi_translations.items():
378
+ translated = translated.replace(english, hindi)
379
 
380
+ # Add Hindi hashtags
381
  if "#" in translated:
382
+ translated += " #भारत #हिंदी #सोशलमीडिया #कंटेंट"
383
 
384
+ return f"🇮🇳 HINDI VERSION (Fallback):\n{translated}"
385
 
386
  def get_fallback_arabic_translation(self, text: str) -> str:
387
  """Fallback Arabic translation when HF API fails"""
 
1210
 
1211
 
1212
  def create_gradio_app():
1213
+ """Create the Gradio app with SambaNova and Hugging Face integration"""
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
+ # Championship-level CSS from app.py
1220
  css = """
1221
  @import url('https://fonts.googleapis.com/css2?family=Space+Grotesk:wght@300;400;500;600;700&display=swap');
1222
 
 
1224
  background: linear-gradient(135deg, #667eea 0%, #764ba2 25%, #f093fb 50%, #f5576c 75%, #4facfe 100%);
1225
  font-family: 'Space Grotesk', 'Inter', system-ui, sans-serif;
1226
  min-height: 100vh;
1227
+ position: relative;
1228
+ overflow-x: hidden;
1229
+ }
1230
+
1231
+ .gradio-container::before {
1232
+ content: '';
1233
+ position: absolute;
1234
+ top: 0;
1235
+ left: 0;
1236
+ right: 0;
1237
+ bottom: 0;
1238
+ background: radial-gradient(circle at 20% 80%, rgba(120, 119, 198, 0.3) 0%, transparent 50%),
1239
+ radial-gradient(circle at 80% 20%, rgba(255, 119, 198, 0.3) 0%, transparent 50%);
1240
+ pointer-events: none;
1241
+ z-index: 1;
1242
  }
1243
 
1244
  .main-header {
1245
  text-align: center;
1246
  color: white;
1247
+ margin-bottom: 40px;
1248
+ padding: 40px;
1249
  background: rgba(255,255,255,0.1);
1250
+ border-radius: 30px;
1251
+ backdrop-filter: blur(30px);
1252
+ border: 2px solid rgba(255,255,255,0.2);
1253
+ box-shadow: 0 25px 50px rgba(0,0,0,0.1);
1254
+ position: relative;
1255
+ z-index: 2;
1256
+ animation: float 6s ease-in-out infinite;
1257
+ }
1258
+
1259
+ @keyframes float {
1260
+ 0%, 100% { transform: translateY(0px); }
1261
+ 50% { transform: translateY(-10px); }
1262
  }
1263
 
1264
  .feature-card {
1265
+ background: rgba(255,255,255,0.15);
1266
+ border-radius: 25px;
1267
+ padding: 30px;
1268
+ backdrop-filter: blur(20px);
1269
+ border: 1px solid rgba(255,255,255,0.3);
1270
+ box-shadow: 0 20px 40px rgba(0,0,0,0.1);
1271
+ transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
1272
+ position: relative;
1273
+ z-index: 2;
1274
  }
1275
 
1276
  .gradio-button-primary {
1277
  background: linear-gradient(45deg, #ff6b6b, #ee5a24, #ff9ff3, #54a0ff) !important;
1278
+ background-size: 300% 300% !important;
1279
+ animation: gradient-shift 4s ease infinite !important;
1280
  border: none !important;
1281
+ border-radius: 20px !important;
1282
+ padding: 18px 35px !important;
1283
+ font-weight: 700 !important;
1284
+ text-transform: uppercase !important;
1285
+ letter-spacing: 2px !important;
1286
+ box-shadow: 0 15px 35px rgba(255, 107, 107, 0.4) !important;
1287
  transition: all 0.3s ease !important;
1288
+ position: relative !important;
1289
+ overflow: hidden !important;
1290
  }
1291
 
1292
+ @keyframes gradient-shift {
1293
+ 0% { background-position: 0% 50%; }
1294
+ 50% { background-position: 100% 50%; }
1295
+ 100% { background-position: 0% 50%; }
1296
  }
1297
 
1298
+ .sambanova-status {
 
 
 
 
 
 
 
 
 
 
1299
  background: linear-gradient(90deg, #2ecc71, #27ae60);
1300
  color: white;
1301
+ padding: 15px 25px;
1302
+ border-radius: 15px;
1303
  text-align: center;
1304
  font-weight: 600;
1305
+ box-shadow: 0 10px 20px rgba(46, 204, 113, 0.3);
1306
+ animation: pulse 2s infinite;
1307
  }
1308
 
1309
+ @keyframes pulse {
1310
+ 0% { box-shadow: 0 10px 20px rgba(46, 204, 113, 0.3); }
1311
+ 50% { box-shadow: 0 15px 30px rgba(46, 204, 113, 0.5); }
1312
+ 100% { box-shadow: 0 10px 20px rgba(46, 204, 113, 0.3); }
1313
  }
1314
  """
1315
 
1316
+ with gr.Blocks(css=css, title="📱 Instagram Generator - MCP Hackathon 2025", theme=gr.themes.Glass()) as app:
1317
 
1318
  # Main Header
1319
+ gr.HTML("""
1320
  <div class="main-header">
1321
+ <h1 style="font-size: 3rem; margin-bottom: 15px; font-weight: 800; background: linear-gradient(45deg, #ff6b6b, #feca57, #ff9ff3, #54a0ff); -webkit-background-clip: text; -webkit-text-fill-color: transparent;">
1322
  📱 INSTAGRAM CAPTION GENERATOR
1323
  </h1>
1324
+ <h2 style="font-size: 1.4rem; margin-bottom: 20px; opacity: 0.9; font-weight: 500;">
1325
+ 🚀 MCP Hackathon 2025 Submission • SambaNova + Hugging Face Edition
1326
  </h2>
1327
+ <div style="display: flex; justify-content: center; gap: 20px; margin-top: 25px;">
1328
+ <span style="background: rgba(255,255,255,0.2); padding: 8px 16px; border-radius: 20px; font-size: 0.9rem;">🤖 SambaNova AI</span>
1329
+ <span style="background: rgba(255,255,255,0.2); padding: 8px 16px; border-radius: 20px; font-size: 0.9rem;">🌍 Multi-Language</span>
1330
+ <span style="background: rgba(255,255,255,0.2); padding: 8px 16px; border-radius: 20px; font-size: 0.9rem;">🔗 MCP Server</span>
1331
  </div>
1332
  </div>
1333
  """)
1334
 
1335
+ # Status Indicators
1336
+ gr.HTML(f"""
1337
+ <div class="sambanova-status">
1338
+ 🚀 SambaNova: {sambanova_status} • 🤗 Hugging Face: {hf_status} • Ready for Deployment!
1339
+ </div>
1340
+ """)
1341
+
1342
  # Main Interface
1343
+ with gr.Tab("🎯 Advanced Caption Generator"):
1344
  with gr.Row():
1345
  # Left Column - Controls
1346
+ with gr.Column(scale=2, elem_classes=["feature-card"]):
1347
+ gr.Markdown("### 🖼️ Multi-Image Upload & Analysis")
1348
  gr.Markdown("*SambaNova AI vision analysis with quality scoring*")
1349
 
1350
  images = gr.File(
1351
  label="📸 Upload Images (Max 3)",
1352
  file_count="multiple",
1353
+ file_types=["image"]
 
1354
  )
1355
 
1356
+ gr.Markdown("### ⚙️ AI Configuration")
1357
 
1358
  with gr.Row():
1359
  caption_style = gr.Dropdown(
 
1380
  "💪 Fitness Community",
1381
  "👗 Fashion Forward",
1382
  "💻 Tech Innovators",
1383
+ "🎨 Creative Artists",
1384
+ "🌱 Sustainability Advocates",
1385
+ "🎵 Music Fans"
1386
  ],
1387
  value="🌟 General Audience",
1388
  label="👥 Target Audience"
1389
  )
1390
 
1391
  custom_prompt = gr.Textbox(
1392
+ label="💬 Advanced Instructions",
1393
+ placeholder="e.g., 'Focus on sustainability messaging', 'Include product launch details', 'Emphasize community building'...",
1394
+ lines=3
1395
  )
1396
 
1397
  generate_btn = gr.Button(
1398
  "🚀 Generate Caption",
1399
+ variant="primary"
 
1400
  )
1401
 
1402
  # Right Column - Results
1403
  with gr.Column(scale=3, elem_classes=["feature-card"]):
1404
+ gr.Markdown("### 📊 AI-Generated Content")
1405
 
1406
  output = gr.Textbox(
1407
  label="🎯 Generated Caption",
1408
  lines=15,
 
1409
  show_copy_button=True,
1410
+ placeholder="Upload images and generate your Instagram content with AI..."
1411
  )
1412
 
1413
+ alternatives_btn = gr.Button(
1414
+ "✨ Generate 3 Alternative Captions",
1415
+ variant="secondary"
1416
+ )
 
 
1417
 
1418
  alternatives_output = gr.Textbox(
1419
  label="✨ Alternative Captions",
1420
  lines=15,
1421
  show_copy_button=True,
1422
+ placeholder="Generate 3 different caption alternatives..."
1423
  )
1424
 
1425
  # Multi-Language Tab
1426
+ with gr.Tab("🌍 Multi-Language Generator"):
1427
  with gr.Row():
1428
+ with gr.Column():
1429
  gr.Markdown("### 🗣️ Global Content Creation")
1430
+ gr.Markdown("*Featuring Hugging Face Helsinki-NLP Translation Models*")
1431
 
1432
  base_caption_input = gr.Textbox(
1433
  label="📝 Base Caption",
 
1451
  variant="primary"
1452
  )
1453
 
1454
+ with gr.Column():
1455
  multilingual_output = gr.Textbox(
1456
  label="🗺️ Multi-Language Captions",
1457
  lines=20,
 
1462
  # SambaNova Features Tab
1463
  with gr.Tab("🤖 SambaNova Features"):
1464
  gr.HTML(f"""
1465
+ <div class="sambanova-status">
1466
  🚀 SambaNova Status: {sambanova_status} • 🦙 Llama-4-Maverick + Llama-3.2-3B
1467
  </div>
1468
  """)
 
1537
  # Hugging Face Features Tab
1538
  with gr.Tab("🤗 Hugging Face Features"):
1539
  gr.HTML(f"""
1540
+ <div class="sambanova-status">
1541
  🤗 Hugging Face Status: {hf_status} • 🌍 Multi-Language Translation
1542
  </div>
1543
  """)
 
1621
  outputs=[output, base_caption_input]
1622
  )
1623
 
 
1624
  alternatives_btn.click(
1625
  fn=generate_multiple_captions_interface,
1626
  inputs=[images, caption_style, target_audience, custom_prompt],
1627
  outputs=alternatives_output
1628
  )
1629
 
 
1630
  translate_btn.click(
1631
  fn=translate_caption_interface,
1632
  inputs=[base_caption_input, language_selector],