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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +55 -34
app.py CHANGED
@@ -4,13 +4,18 @@ import random
4
  # Load the model
5
  model = gr.load("models/Purz/face-projection")
6
 
7
- # Function to generate image
8
  def generate_image(text, seed):
9
  if seed is not None:
10
  random.seed(seed)
11
- return model(text)
12
 
13
- # Define example inputs
 
 
 
 
 
 
 
14
  examples = [
15
  ["Humanoid Cat Warrior, Full View", None],
16
  ["Warhammer Sisterhood", None],
@@ -18,42 +23,58 @@ examples = [
18
  ["Fantasy dragon", None]
19
  ]
20
 
21
- # Customized Gradio Interface
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
22
  interface = gr.Interface(
23
  fn=generate_image,
24
  inputs=[
25
- gr.Textbox(label="Imagine and Type Here:", placeholder="Type your idea or click an example...", elem_id="input-text"),
26
- gr.Slider(minimum=0, maximum=10000, step=1, label="Seed (optional)", elem_id="seed-slider")
27
  ],
28
- outputs=gr.Image(label="Generated Image", elem_id="output-image"),
 
29
  examples=examples,
30
- theme="default",
31
- description="The model is currently running on CPU. Performance might vary. Thanks for your patience.",
32
- css="""
33
- #input-text, #seed-slider .input-label, .output-label, .description {
34
- font-family: 'Arial', sans-serif;
35
- text-align: center;
36
- color: #333;
37
- }
38
- .container {
39
- background: linear-gradient(135deg, #a8edea 0%, #fed6e3 100%);
40
- border-radius: 12px;
41
- padding: 10px;
42
- }
43
- .btn {
44
- background: linear-gradient(90deg, #ff8a00, #e52e71);
45
- border: none;
46
- border-radius: 25px;
47
- color: white;
48
- padding: 12px 24px;
49
- font-size: 16px;
50
- font-weight: bold;
51
- cursor: pointer;
52
- }
53
- .examples-table {
54
- text-align: center;
55
- }
56
- """
57
  )
58
 
59
  # Launch the interface
 
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
+ # 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],
 
23
  ["Fantasy dragon", None]
24
  ]
25
 
26
+ # Custom CSS for gradient buttons and capsule shapes
27
+ css = """
28
+ /* General button styles */
29
+ button {
30
+ border-radius: 25px; /* Capsule shape */
31
+ padding: 10px 20px;
32
+ font-size: 16px;
33
+ font-weight: bold;
34
+ color: white;
35
+ background: linear-gradient(135deg, #6D5BBA, #8A2387); /* Gradient color */
36
+ border: none;
37
+ cursor: pointer;
38
+ transition: background 0.3s ease;
39
+ }
40
+
41
+ button:hover {
42
+ background: linear-gradient(135deg, #8A2387, #6D5BBA); /* Gradient reverse on hover */
43
+ }
44
+
45
+ /* Slider handle style */
46
+ input[type=range] {
47
+ accent-color: #8A2387; /* Gradient color accent */
48
+ }
49
+
50
+ /* Textbox styling */
51
+ .gr-textbox {
52
+ border-radius: 8px;
53
+ border: 1px solid #DDD;
54
+ padding: 10px;
55
+ }
56
+
57
+ /* Output image styling */
58
+ .output_image {
59
+ border: 2px solid #6D5BBA;
60
+ border-radius: 10px;
61
+ padding: 10px;
62
+ background-color: #f9f9f9;
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
 
80
  # Launch the interface