yangtb24 commited on
Commit
7191bab
1 Parent(s): 32dd444

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +39 -9
app.py CHANGED
@@ -583,19 +583,49 @@ def handsome_chat_completions():
583
 
584
  if model_name in image_models:
585
  # Handle image generation
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
586
  # Map OpenAI-style parameters to SiliconFlow's parameters
587
  siliconflow_data = {
588
  "model": model_name,
589
- "prompt": data.get("messages", [{}])[0].get("content") if isinstance(data.get("messages"), list) else "",
590
- "image_size": data.get("size", "1024x1024"),
591
- "batch_size": data.get("n", 1),
592
- "num_inference_steps": data.get("steps", 20),
593
- "guidance_scale": data.get("guidance_scale", 7.5),
594
- "negative_prompt": data.get("negative_prompt"),
595
- "seed": data.get("seed"),
596
- "prompt_enhancement": False,
597
  }
598
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
599
  # Parameter validation and adjustments
600
  if siliconflow_data["batch_size"] < 1:
601
  siliconflow_data["batch_size"] = 1
 
583
 
584
  if model_name in image_models:
585
  # Handle image generation
586
+ user_content = ""
587
+ messages = data.get("messages", [])
588
+ for message in messages:
589
+ if message["role"] == "user":
590
+ if isinstance(message["content"], str):
591
+ user_content += message["content"] + " "
592
+ elif isinstance(message["content"], list):
593
+ for item in message["content"]:
594
+ if (
595
+ isinstance(item, dict) and
596
+ item.get("type") == "text"
597
+ ):
598
+ user_content += (
599
+ item.get("text", "") +
600
+ " "
601
+ )
602
+ user_content = user_content.strip()
603
+
604
  # Map OpenAI-style parameters to SiliconFlow's parameters
605
  siliconflow_data = {
606
  "model": model_name,
607
+ "prompt": user_content,
608
+ "image_size": "1024x1024", # Default value
609
+ "batch_size": 1, # Default value
610
+ "num_inference_steps": 20, # Default value
611
+ "guidance_scale": 7.5, # Default value
612
+ "prompt_enhancement": False, # Default value
 
 
613
  }
614
+
615
+ # Override with user's params (if provided)
616
+ if data.get("size"):
617
+ siliconflow_data["image_size"] = data.get("size")
618
+ if data.get("n"):
619
+ siliconflow_data["batch_size"] = data.get("n")
620
+ if data.get("steps"):
621
+ siliconflow_data["num_inference_steps"] = data.get("steps")
622
+ if data.get("guidance_scale"):
623
+ siliconflow_data["guidance_scale"] = data.get("guidance_scale")
624
+ if data.get("negative_prompt"):
625
+ siliconflow_data["negative_prompt"] = data.get("negative_prompt")
626
+ if data.get("seed"):
627
+ siliconflow_data["seed"] = data.get("seed")
628
+
629
  # Parameter validation and adjustments
630
  if siliconflow_data["batch_size"] < 1:
631
  siliconflow_data["batch_size"] = 1