openfree commited on
Commit
5a0337c
·
verified ·
1 Parent(s): 63e0ec1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +32 -19
app.py CHANGED
@@ -3,6 +3,7 @@ import os
3
  import uuid
4
  from datetime import datetime
5
  import gradio as gr
 
6
  import numpy as np
7
  import spaces
8
  import torch
@@ -16,7 +17,7 @@ if not os.path.exists(SAVE_DIR):
16
 
17
  device = "cuda" if torch.cuda.is_available() else "cpu"
18
  repo_id = "black-forest-labs/FLUX.1-dev"
19
- adapter_id = "openfree/korea-president-yoon"
20
 
21
  pipeline = DiffusionPipeline.from_pretrained(repo_id, torch_dtype=torch.bfloat16)
22
  pipeline.load_lora_weights(adapter_id)
@@ -47,8 +48,11 @@ def load_generated_images():
47
  return []
48
 
49
  # Load all images from the directory
50
- image_files = [os.path.join(SAVE_DIR, f) for f in os.listdir(SAVE_DIR)
51
- if f.endswith(('.png', '.jpg', '.jpeg', '.webp'))]
 
 
 
52
  # Sort by creation time (newest first)
53
  image_files.sort(key=lambda x: os.path.getctime(x), reverse=True)
54
  return image_files
@@ -90,30 +94,38 @@ def inference(
90
  return image, seed, load_generated_images()
91
 
92
  examples = [
93
- "A man playing fetch with a golden retriever in a sunny park. He wears casual weekend clothes and throws a red frisbee with joy. The dog leaps gracefully through the air, tail wagging with excitement. Warm afternoon sunlight filters through the trees, creating a peaceful scene of companionship. [president yoon]",
94
-
95
- "A soldier standing at attention in full military gear, holding a standard-issue rifle. His uniform is crisp and properly adorned with medals. Behind him, other soldiers march in formation during a military parade. The scene conveys discipline and duty. [president yoon]",
96
-
97
- "A medieval knight in gleaming armor, holding an ornate sword and shield. He stands proudly in front of a majestic castle, his cape flowing in the wind. The shield bears intricate heraldic designs, and sunlight glints off his polished armor. [president yoon]",
98
-
99
- "A charismatic political leader addressing a crowd from a podium. He wears a well-fitted suit and gestures confidently while speaking. The audience fills a large plaza, holding supportive banners and signs. News cameras capture the moment as he delivers his speech. [president yoon]",
100
-
101
- "A man enjoying a peaceful morning at home, reading a newspaper at his breakfast table. He wears comfortable home clothes and sips coffee from a favorite mug. Sunlight streams through the kitchen window, and a house plant adds a touch of nature to the cozy domestic scene. [president yoon]",
102
-
103
- "A businessman walking confidently through a modern office building. He carries a leather briefcase and wears a tailored navy suit. Floor-to-ceiling windows reveal a cityscape behind him, and his expression shows determination and purpose. [president yoon]"
104
  ]
105
 
106
  css = """
107
  footer {
108
  visibility: hidden;
109
  }
 
 
 
110
  """
111
 
112
- with gr.Blocks(theme=gr.themes.Soft, css=css, analytics_enabled=False) as demo:
113
- gr.HTML('<div class="title"> President DJ(김대중) in KOREA </div>')
 
 
 
 
 
 
 
 
 
 
 
 
114
 
115
-
116
-
117
  with gr.Tabs() as tabs:
118
  with gr.Tab("Generation"):
119
  with gr.Column(elem_id="col-container"):
@@ -207,6 +219,7 @@ with gr.Blocks(theme=gr.themes.Soft, css=css, analytics_enabled=False) as demo:
207
  outputs=generated_gallery,
208
  )
209
 
 
210
  gr.on(
211
  triggers=[run_button.click, prompt.submit],
212
  fn=inference,
@@ -224,4 +237,4 @@ with gr.Blocks(theme=gr.themes.Soft, css=css, analytics_enabled=False) as demo:
224
  )
225
 
226
  demo.queue()
227
- demo.launch()
 
3
  import uuid
4
  from datetime import datetime
5
  import gradio as gr
6
+ import gradio.themes as themes # <-- Import the theme module
7
  import numpy as np
8
  import spaces
9
  import torch
 
17
 
18
  device = "cuda" if torch.cuda.is_available() else "cpu"
19
  repo_id = "black-forest-labs/FLUX.1-dev"
20
+ adapter_id = "openfree/president-k-dj"
21
 
22
  pipeline = DiffusionPipeline.from_pretrained(repo_id, torch_dtype=torch.bfloat16)
23
  pipeline.load_lora_weights(adapter_id)
 
48
  return []
49
 
50
  # Load all images from the directory
51
+ image_files = [
52
+ os.path.join(SAVE_DIR, f)
53
+ for f in os.listdir(SAVE_DIR)
54
+ if f.endswith(('.png', '.jpg', '.jpeg', '.webp'))
55
+ ]
56
  # Sort by creation time (newest first)
57
  image_files.sort(key=lambda x: os.path.getctime(x), reverse=True)
58
  return image_files
 
94
  return image, seed, load_generated_images()
95
 
96
  examples = [
97
+ "A man playing fetch with a golden retriever in a sunny park. He wears casual weekend clothes and throws a red frisbee with joy. The dog leaps gracefully through the air, tail wagging with excitement. Warm afternoon sunlight filters through the trees, creating a peaceful scene of companionship. [president_K_DJ ]",
98
+ "A soldier standing at attention in full military gear, holding a standard-issue rifle. His uniform is crisp and properly adorned with medals. Behind him, other soldiers march in formation during a military parade. The scene conveys discipline and duty. [president_K_DJ ]",
99
+ "A medieval knight in gleaming armor, holding an ornate sword and shield. He stands proudly in front of a majestic castle, his cape flowing in the wind. The shield bears intricate heraldic designs, and sunlight glints off his polished armor. [president_K_DJ ]",
100
+ "A charismatic political leader addressing a crowd from a podium. He wears a well-fitted suit and gestures confidently while speaking. The audience fills a large plaza, holding supportive banners and signs. News cameras capture the moment as he delivers his speech. [president_K_DJ ]",
101
+ "A man enjoying a peaceful morning at home, reading a newspaper at his breakfast table. He wears comfortable home clothes and sips coffee from a favorite mug. Sunlight streams through the kitchen window, and a house plant adds a touch of nature to the cozy domestic scene. [president_K_DJ]",
102
+ "A businessman walking confidently through a modern office building. He carries a leather briefcase and wears a tailored navy suit. Floor-to-ceiling windows reveal a cityscape behind him, and his expression shows determination and purpose. [president_K_DJ ]"
 
 
 
 
 
103
  ]
104
 
105
  css = """
106
  footer {
107
  visibility: hidden;
108
  }
109
+ #col-container {
110
+ margin-top: 10px;
111
+ }
112
  """
113
 
114
+ # Create a customized Soft theme for better visuals
115
+ custom_theme = themes.Soft(
116
+ primary_hue="blue", # Color for primary actions
117
+ secondary_hue="gray", # Color for secondary actions
118
+ neutral_hue="cyan", # Neutral color scheme
119
+ text_size="md", # Medium text size
120
+ spacing_size="md", # Medium spacing for elements
121
+ radius_size="lg", # Larger corner radius
122
+ font=["Open Sans", "sans-serif"] # Modern, clean font
123
+ )
124
+
125
+ with gr.Blocks(theme=custom_theme, css=css, analytics_enabled=False) as demo:
126
+ gr.HTML('<div class="title" style="text-align:center; font-size:2em; margin-bottom:20px;">\
127
+ <strong> President DJ(김대중) in KOREA </strong></div>')
128
 
 
 
129
  with gr.Tabs() as tabs:
130
  with gr.Tab("Generation"):
131
  with gr.Column(elem_id="col-container"):
 
219
  outputs=generated_gallery,
220
  )
221
 
222
+ # tie the run_button and prompt.submit to the same function
223
  gr.on(
224
  triggers=[run_button.click, prompt.submit],
225
  fn=inference,
 
237
  )
238
 
239
  demo.queue()
240
+ demo.launch()