LuigiLui commited on
Commit
3901554
·
verified ·
1 Parent(s): 51f8fc2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +41 -41
app.py CHANGED
@@ -1,19 +1,13 @@
1
  import gradio as gr
2
  import random
3
 
4
- # Load the model
5
  model = gr.load("models/Purz/face-projection")
6
 
7
  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
  return model(text)
15
 
16
- # Examples for user guidance
17
  examples = [
18
  ["Humanoid Cat Warrior, Full View", None],
19
  ["Warhammer Sisterhood", None],
@@ -21,58 +15,64 @@ examples = [
21
  ["Fantasy dragon", None]
22
  ]
23
 
24
- # Custom CSS for gradient buttons and capsule shapes
25
- css = """
26
- /* General button styles */
27
- button {
28
- border-radius: 25px; /* Capsule shape */
29
- padding: 10px 20px;
30
- font-size: 16px;
31
- font-weight: bold;
32
- color: white;
33
- background: linear-gradient(135deg, #6D5BBA, #8A2387); /* Gradient color */
34
- border: none;
35
- cursor: pointer;
36
- transition: background 0.3s ease;
37
  }
38
 
39
- button:hover {
40
- background: linear-gradient(135deg, #8A2387, #6D5BBA); /* Gradient reverse on hover */
 
 
 
 
 
 
41
  }
42
 
43
- /* Slider handle style */
44
- input[type=range] {
45
- accent-color: #8A2387; /* Gradient color accent */
 
 
 
 
46
  }
47
 
48
- /* Textbox styling */
49
- .gr-textbox {
50
- border-radius: 8px;
51
- border: 1px solid #DDD;
52
- padding: 10px;
 
53
  }
54
 
55
- /* Output image styling */
56
- .output_image {
57
- border: 2px solid #6D5BBA;
58
- border-radius: 10px;
59
- padding: 10px;
60
- background-color: #f9f9f9;
61
  }
62
  """
63
 
64
- # Gradio interface with custom styles
 
 
 
 
65
  interface = gr.Interface(
66
  fn=generate_image,
67
  inputs=[
68
- gr.Textbox(label="Type your imagination:", placeholder="Type or select an example..."),
69
  gr.Slider(minimum=0, maximum=10000, step=1, label="Seed (optional)")
70
  ],
71
- outputs=gr.Image(label="Generated Image"),
72
  examples=examples,
73
- css=css, # Apply custom CSS styling
74
- description="Note: The model is running on CPU; processing might take a bit longer. Thank you for your patience!"
 
75
  )
76
 
77
- # Launch the interface
78
  interface.launch()
 
1
  import gradio as gr
2
  import random
3
 
 
4
  model = gr.load("models/Purz/face-projection")
5
 
6
  def generate_image(text, seed):
7
  if seed is not None:
8
  random.seed(seed)
 
 
 
 
9
  return model(text)
10
 
 
11
  examples = [
12
  ["Humanoid Cat Warrior, Full View", None],
13
  ["Warhammer Sisterhood", None],
 
15
  ["Fantasy dragon", None]
16
  ]
17
 
18
+ # Custom CSS for minimalist style, horizontal example layout, and styled prompt box
19
+ custom_css = """
20
+ /* Remove border and background color for the output image preview */
21
+ .output-image {
22
+ border: none !important;
23
+ background: none !important;
 
 
 
 
 
 
 
24
  }
25
 
26
+ /* Prompt textbox styling */
27
+ input[type="text"] {
28
+ border: 2px solid #ddd;
29
+ border-radius: 8px;
30
+ padding: 12px;
31
+ font-size: 16px;
32
+ width: 100%;
33
+ background-color: #f9f9f9;
34
  }
35
 
36
+ /* Examples arranged in a single line, without buttons */
37
+ .gr-examples {
38
+ display: flex;
39
+ flex-direction: row;
40
+ justify-content: space-evenly;
41
+ gap: 10px;
42
+ margin-top: 10px;
43
  }
44
 
45
+ .gr-examples span {
46
+ font-size: 14px;
47
+ color: #333;
48
+ cursor: pointer;
49
+ padding: 5px;
50
+ transition: all 0.2s ease;
51
  }
52
 
53
+ /* Hover effect on examples */
54
+ .gr-examples span:hover {
55
+ color: #007bff;
56
+ text-decoration: underline;
 
 
57
  }
58
  """
59
 
60
+ # Function to handle example clicks (to simulate button-less selection)
61
+ def update_prompt_text(example_text):
62
+ return example_text, None
63
+
64
+ # Gradio Interface with updated UI elements and custom CSS
65
  interface = gr.Interface(
66
  fn=generate_image,
67
  inputs=[
68
+ gr.Textbox(label="Imagine anything:", placeholder="Describe the scene...", interactive=True),
69
  gr.Slider(minimum=0, maximum=10000, step=1, label="Seed (optional)")
70
  ],
71
+ outputs=gr.Image(label="Generated Image", type="pil"),
72
  examples=examples,
73
+ css=custom_css, # Apply custom CSS
74
+ description="Enter a creative prompt or choose an example to generate your AI-powered image. Model performance may vary due to CPU usage.",
75
+ live=True
76
  )
77
 
 
78
  interface.launch()