LuigiLui commited on
Commit
76ea01b
·
verified ·
1 Parent(s): b060071

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -14
app.py CHANGED
@@ -8,22 +8,27 @@ def generate_image(text, seed):
8
  if seed is not None:
9
  random.seed(seed)
10
 
11
- if text in [example[0] for example in examples]:
12
- print(f"Using example: {text}")
 
 
 
 
 
13
 
14
- # Generate four images by calling the model four times
15
- images = [model(text) for _ in range(4)]
16
  return images
17
 
18
- # Examples for user guidance
19
  examples = [
20
- ["Humanoid Cat Warrior, Full View", None],
21
- ["Warhammer Sisterhood", None],
22
- ["Future Robots war", None],
23
- ["Fantasy dragon", None]
24
  ]
25
 
26
- # Custom CSS for gradient buttons and capsule shapes
27
  css = """
28
  /* General button styles */
29
  button {
@@ -63,17 +68,20 @@ input[type=range] {
63
  }
64
  """
65
 
66
- # Gradio interface with custom styles
 
 
 
 
67
  interface = gr.Interface(
68
  fn=generate_image,
69
  inputs=[
70
  gr.Textbox(label="Type your imagination:", placeholder="Type or select an example..."),
71
  gr.Slider(minimum=0, maximum=10000, step=1, label="Seed (optional)")
72
  ],
73
- # Specify a list of 4 Image outputs for displaying multiple images
74
  outputs=[gr.Image(label=f"Generated Image {i+1}") for i in range(4)],
75
- examples=examples,
76
- css=css, # Apply custom CSS styling
77
  description="Note: The model is running on CPU; processing might take a bit longer. Thank you for your patience!"
78
  )
79
 
 
8
  if seed is not None:
9
  random.seed(seed)
10
 
11
+ # Define slight variations of the original prompt for different poses/positions
12
+ variations = [
13
+ f"{text}, front view",
14
+ f"{text}, side view",
15
+ f"{text}, dynamic pose",
16
+ f"{text}, close-up view"
17
+ ]
18
 
19
+ # Generate an image for each variation
20
+ images = [model(variation) for variation in variations]
21
  return images
22
 
23
+ # Define examples with pre-generated image previews
24
  examples = [
25
+ ["Humanoid Cat Warrior, Full View", None, "path/to/humanoid_cat_preview.jpg"],
26
+ ["Warhammer Sisterhood", None, "path/to/warhammer_sisterhood_preview.jpg"],
27
+ ["Future Robots war", None, "path/to/future_robots_war_preview.jpg"],
28
+ ["Fantasy dragon", None, "path/to/fantasy_dragon_preview.jpg"]
29
  ]
30
 
31
+ # Custom CSS for styling
32
  css = """
33
  /* General button styles */
34
  button {
 
68
  }
69
  """
70
 
71
+ # Define a function to create the examples with preview images
72
+ def create_example_row(example):
73
+ return [gr.Example(value=example[0], examples=None, label=example[0], image=example[2])]
74
+
75
+ # Gradio interface
76
  interface = gr.Interface(
77
  fn=generate_image,
78
  inputs=[
79
  gr.Textbox(label="Type your imagination:", placeholder="Type or select an example..."),
80
  gr.Slider(minimum=0, maximum=10000, step=1, label="Seed (optional)")
81
  ],
 
82
  outputs=[gr.Image(label=f"Generated Image {i+1}") for i in range(4)],
83
+ examples=create_example_row(examples), # Use pre-generated images for previews
84
+ css=css,
85
  description="Note: The model is running on CPU; processing might take a bit longer. Thank you for your patience!"
86
  )
87