RajputVansh commited on
Commit
dbbc92d
·
verified ·
1 Parent(s): 92683f9

Update mcp_server.py

Browse files
Files changed (1) hide show
  1. mcp_server.py +16 -19
mcp_server.py CHANGED
@@ -13,12 +13,12 @@ from mcp.server.fastmcp import FastMCP
13
 
14
  mcp = FastMCP("modal_flux_testing", timeout=500)
15
 
16
- # Global variables to store secrets
17
- MODAL_API_URL = os.getenv('MODAL_API_URL',"https://rajkumarcmppl--flux-api-server-fastapi-server.modal.run")
18
- MISTRAL_API_KEY = os.getenv("MISTRAL_API_KEY","DRdpSRosSmwjj62cbdb3b04xjaPrMKpa")
19
  MISTRAL_API_URL = "https://api.mistral.ai/v1/chat/completions"
20
 
21
- # Social Media Size Presets
22
  SIZE_PRESETS = {
23
  "instagram_post": (1080, 1080),
24
  "instagram_story": (1080, 1920),
@@ -28,8 +28,7 @@ SIZE_PRESETS = {
28
  "youtube_thumbnail": (1280, 720),
29
  }
30
 
31
- # Prompt Templates for Marketing
32
- # Updated Prompt Templates for Cinematic Marketing (based on your examples)
33
  PROMPT_TEMPLATES = {
34
  "product_hero": """A professional, cinematic product photography composition featuring {product} as the center subject against a {background} backdrop. The scene is illuminated with dramatic studio lighting creating golden highlights and deep shadows. The {product} appears to float with ethereal light emanating from beneath, surrounded by subtle glowing particles and atmospheric mist. The composition uses cinematic depth of field with the product razor-sharp in focus while the background fades into artistic bokeh. Luxurious materials and textures are emphasized with photorealistic detail, showcasing premium quality and craftsmanship.""",
35
 
@@ -48,7 +47,7 @@ PROMPT_TEMPLATES = {
48
  "luxury_product": """An ultra-premium product showcase featuring {product} in a luxurious, museum-quality presentation. The item sits on pristine surfaces with perfect reflections, surrounded by architectural elements like marble, gold accents, and crystal. Dramatic lighting creates spectacular highlights and deep shadows, emphasizing every detail and texture. The background features elegant negative space with subtle gradient lighting and floating particles that suggest exclusivity. The entire composition exudes opulence and sophistication, with photorealistic detail that showcases premium craftsmanship and materials."""
49
  }
50
 
51
- # Enhanced Style Modifiers (matching your cinematic examples)
52
  STYLE_MODIFIERS = {
53
  "professional": """professional studio lighting, cinematic composition, dramatic shadows and highlights, premium materials and textures, photorealistic detail, magazine-quality photography, sophisticated color grading, architectural precision, corporate elegance, high-end commercial aesthetics""",
54
 
@@ -105,7 +104,7 @@ VARIATION_STRATEGIES = {
105
  ]
106
  }
107
 
108
- # Content creator specific variations
109
  CONTENT_CREATOR_VARIATIONS = {
110
  "social_media": [
111
  "Instagram-optimized with bold text overlay space",
@@ -131,7 +130,7 @@ CONTENT_CREATOR_VARIATIONS = {
131
  }
132
 
133
 
134
- # In-memory storage for history (in production, use a database)
135
  generation_history = []
136
 
137
 
@@ -238,7 +237,6 @@ Make it sound like a professional movie poster description with rich visual deta
238
  "fallback_prompt": f"Cinematic {style} style image of {user_input}, dramatic lighting, high detail, professional composition, vivid colors"
239
  })
240
 
241
- # Additional function to improve prompt quality based on your examples
242
  @mcp.tool()
243
  async def enhance_prompt_with_details(base_prompt: str, enhancement_type: str = "cinematic") -> str:
244
  """
@@ -357,7 +355,7 @@ async def generate_and_save_image(prompt: str, num_inference_steps: int = 50, wi
357
  "prompt": prompt,
358
  "timestamp": datetime.now().isoformat(),
359
  "dimensions": f"{width}x{height}",
360
- "image_base64": image_b64[:100] + "..." # Store preview only
361
  })
362
 
363
  return image_b64
@@ -388,15 +386,15 @@ async def batch_generate_smart_variations(prompt: str, count: int = 3, variation
388
  variations = []
389
 
390
  if variation_type == "mixed":
391
- # Mix different strategies for comprehensive testing
392
  all_variations = []
393
  for strategy in VARIATION_STRATEGIES.values():
394
- all_variations.extend(strategy[:2]) # Take 2 from each strategy
395
 
396
- # Add content creator specific ones
397
  all_variations.extend(CONTENT_CREATOR_VARIATIONS["engagement_hooks"][:2])
398
 
399
- # Randomly select variations
400
  import random
401
  selected_variations = random.sample(all_variations, min(count, len(all_variations)))
402
 
@@ -405,7 +403,7 @@ async def batch_generate_smart_variations(prompt: str, count: int = 3, variation
405
  elif variation_type in CONTENT_CREATOR_VARIATIONS:
406
  selected_variations = CONTENT_CREATOR_VARIATIONS[variation_type][:count]
407
  else:
408
- # Fallback to mixed
409
  selected_variations = [
410
  "with vibrant, attention-grabbing colors",
411
  "with professional, clean aesthetic",
@@ -543,7 +541,7 @@ async def generate_social_media_set(prompt: str, platforms: List[str], num_infer
543
  platform_prompt = f"{prompt}, optimized for {platform.replace('_', ' ')}"
544
 
545
  try:
546
- # Now pass the actual dimensions to the generation function
547
  image_b64 = await generate_and_save_image(
548
  platform_prompt,
549
  num_inference_steps,
@@ -596,8 +594,7 @@ async def create_image_package(image_data_list: List[Dict], package_name: str =
596
  Create a downloadable package of generated images with metadata.
597
  Useful for bulk content creation and organization.
598
  """
599
- # This would create a zip file with images and a metadata JSON
600
- # For now, return structured data
601
 
602
  package_info = {
603
  "package_name": package_name,
 
13
 
14
  mcp = FastMCP("modal_flux_testing", timeout=500)
15
 
16
+
17
+ MODAL_API_URL = os.environ.get("MODAL_API_URL")
18
+ MISTRAL_API_KEY = os.environ.get("MISTRAL_API_KEY")
19
  MISTRAL_API_URL = "https://api.mistral.ai/v1/chat/completions"
20
 
21
+
22
  SIZE_PRESETS = {
23
  "instagram_post": (1080, 1080),
24
  "instagram_story": (1080, 1920),
 
28
  "youtube_thumbnail": (1280, 720),
29
  }
30
 
31
+
 
32
  PROMPT_TEMPLATES = {
33
  "product_hero": """A professional, cinematic product photography composition featuring {product} as the center subject against a {background} backdrop. The scene is illuminated with dramatic studio lighting creating golden highlights and deep shadows. The {product} appears to float with ethereal light emanating from beneath, surrounded by subtle glowing particles and atmospheric mist. The composition uses cinematic depth of field with the product razor-sharp in focus while the background fades into artistic bokeh. Luxurious materials and textures are emphasized with photorealistic detail, showcasing premium quality and craftsmanship.""",
34
 
 
47
  "luxury_product": """An ultra-premium product showcase featuring {product} in a luxurious, museum-quality presentation. The item sits on pristine surfaces with perfect reflections, surrounded by architectural elements like marble, gold accents, and crystal. Dramatic lighting creates spectacular highlights and deep shadows, emphasizing every detail and texture. The background features elegant negative space with subtle gradient lighting and floating particles that suggest exclusivity. The entire composition exudes opulence and sophistication, with photorealistic detail that showcases premium craftsmanship and materials."""
48
  }
49
 
50
+
51
  STYLE_MODIFIERS = {
52
  "professional": """professional studio lighting, cinematic composition, dramatic shadows and highlights, premium materials and textures, photorealistic detail, magazine-quality photography, sophisticated color grading, architectural precision, corporate elegance, high-end commercial aesthetics""",
53
 
 
104
  ]
105
  }
106
 
107
+
108
  CONTENT_CREATOR_VARIATIONS = {
109
  "social_media": [
110
  "Instagram-optimized with bold text overlay space",
 
130
  }
131
 
132
 
133
+
134
  generation_history = []
135
 
136
 
 
237
  "fallback_prompt": f"Cinematic {style} style image of {user_input}, dramatic lighting, high detail, professional composition, vivid colors"
238
  })
239
 
 
240
  @mcp.tool()
241
  async def enhance_prompt_with_details(base_prompt: str, enhancement_type: str = "cinematic") -> str:
242
  """
 
355
  "prompt": prompt,
356
  "timestamp": datetime.now().isoformat(),
357
  "dimensions": f"{width}x{height}",
358
+ "image_base64": image_b64[:100] + "..."
359
  })
360
 
361
  return image_b64
 
386
  variations = []
387
 
388
  if variation_type == "mixed":
389
+
390
  all_variations = []
391
  for strategy in VARIATION_STRATEGIES.values():
392
+ all_variations.extend(strategy[:2])
393
 
394
+
395
  all_variations.extend(CONTENT_CREATOR_VARIATIONS["engagement_hooks"][:2])
396
 
397
+
398
  import random
399
  selected_variations = random.sample(all_variations, min(count, len(all_variations)))
400
 
 
403
  elif variation_type in CONTENT_CREATOR_VARIATIONS:
404
  selected_variations = CONTENT_CREATOR_VARIATIONS[variation_type][:count]
405
  else:
406
+
407
  selected_variations = [
408
  "with vibrant, attention-grabbing colors",
409
  "with professional, clean aesthetic",
 
541
  platform_prompt = f"{prompt}, optimized for {platform.replace('_', ' ')}"
542
 
543
  try:
544
+
545
  image_b64 = await generate_and_save_image(
546
  platform_prompt,
547
  num_inference_steps,
 
594
  Create a downloadable package of generated images with metadata.
595
  Useful for bulk content creation and organization.
596
  """
597
+
 
598
 
599
  package_info = {
600
  "package_name": package_name,