tianlong12 commited on
Commit
48b41e4
·
verified ·
1 Parent(s): cb31a9d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -7
app.py CHANGED
@@ -37,13 +37,34 @@ def req_flux(token, prompt_value, aspect_ratio="1:1", output_format="webp", num_
37
  print(f"Error making request: {e}")
38
  return None
39
 
40
- def generate_optimized_prompt(api_key, api_base, system_prompt, user_input):
41
  client = OpenAI(api_key=api_key, base_url=api_base)
42
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
43
  completion = client.chat.completions.create(
44
  model="gpt-4o-mini",
45
  messages=[
46
- {"role": "system", "content": system_prompt},
47
  {"role": "user", "content": user_input}
48
  ]
49
  )
@@ -51,11 +72,11 @@ def generate_optimized_prompt(api_key, api_base, system_prompt, user_input):
51
 
52
  def generate_fake_stream(image_url, optimized_prompt):
53
  chunks = [
54
- "I'm generating an optimized prompt based on your input...\n",
55
- f"Optimized prompt: {optimized_prompt}\n",
56
- "Now generating an image based on the optimized prompt...\n",
57
- "The image is being processed...\n",
58
- "Almost there...\n",
59
  f"Image generated successfully! Here it is:\n\n![Generated Image]({image_url})"
60
  ]
61
 
 
37
  print(f"Error making request: {e}")
38
  return None
39
 
40
+ def generate_optimized_prompt(api_key, api_base, user_input):
41
  client = OpenAI(api_key=api_key, base_url=api_base)
42
 
43
+ prompt = (
44
+ f"As a Stable Diffusion prompt expert, your task is to directly modify the following sentence: '{user_input}'"
45
+ "into a proper Stable Diffusion prompt in English, formatted according to the guidelines provided: "
46
+ "1. Create prompts using common vocabulary, arranged by importance and separated by commas. Avoid using '-' or '.', "
47
+ "but spaces and natural language are acceptable. Avoid repeating words. "
48
+ "2. To emphasize keywords, enclose them in parentheses to increase their weight. For example, '(flowers)' increases "
49
+ "the weight of 'flowers' by 1.1 times, '(((flowers)))' increases it by 1.331 times, and '(flowers:1.5)' increases "
50
+ "the weight of 'flowers' by 1.5 times. Only increase the weight for important tags. "
51
+ "3. The prompt should consist of three parts: prefix (quality tags + style words + effectors), subject "
52
+ "(main focus of the image), and scene (background, environment). The prefix affects image quality; tags like "
53
+ "'masterpiece,' 'best quality,' and '4k' enhance image detail, style words like 'illustration' and 'lensflare' "
54
+ "define the style of the image, and effectors like 'best lighting,' 'lensflare,' and 'depth of field' influence "
55
+ "lighting and depth. The subject is the main focus of the image, such as a character or scene. Providing a detailed "
56
+ "description of the subject ensures a rich and detailed image, and increasing the subject's weight enhances its clarity. "
57
+ "For characters, describe features like the face, hair, body, clothing, and pose. The scene describes the environment; "
58
+ "without a scene, the image's background appears plain, making the subject seem overly large. Some subjects inherently "
59
+ "include scenes (such as buildings or landscapes), and environmental words like 'flower meadow,' 'sunlight,' and 'river' "
60
+ "can enrich the scene. "
61
+ "Return only the revised prompt in English."
62
+ )
63
+
64
  completion = client.chat.completions.create(
65
  model="gpt-4o-mini",
66
  messages=[
67
+ {"role": "system", "content": prompt},
68
  {"role": "user", "content": user_input}
69
  ]
70
  )
 
72
 
73
  def generate_fake_stream(image_url, optimized_prompt):
74
  chunks = [
75
+ "I'm generating an optimized prompt based on your input...",
76
+ f"Optimized prompt: {optimized_prompt}",
77
+ "Now generating an image based on the optimized prompt...",
78
+ "The image is being processed...",
79
+ "Almost there...",
80
  f"Image generated successfully! Here it is:\n\n![Generated Image]({image_url})"
81
  ]
82