akhaliq HF Staff commited on
Commit
e0bd939
Β·
verified Β·
1 Parent(s): aaf01c9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +29 -30
app.py CHANGED
@@ -4,23 +4,20 @@ import torch
4
  from PIL import Image
5
  from transformers import AutoProcessor
6
  from longcat_image.models import LongCatImageTransformer2DModel
7
- from longcat_image.pipelines import LongCatImageEditPipeline, LongCatImagePipeline
8
  import numpy as np
9
 
10
- # 1. Define the Custom Theme Class
11
- # Inherit from Base for simplicity and modify core parameters.
12
- class AppleSoft(gr.themes.Base):
13
  def __init__(
14
  self,
15
- # Use a deep Indigo/Blue for primary actions (like the iOS/macOS blue)
16
- primary_hue=gr.themes.colors.indigo,
17
  secondary_hue=gr.themes.colors.gray,
18
  neutral_hue=gr.themes.colors.neutral,
19
- # Increase radius for "card" look (iOS uses large rounded corners)
20
- radius_size=gr.themes.sizes.radius_lg,
21
- # Set font to use a system font stack (like the old custom CSS)
22
- font=[gr.themes.GoogleFont("Source Sans Pro"), "system-ui", "sans-serif"],
23
- font_mono=gr.themes.GoogleFont("IBM Plex Mono"),
24
  spacing_size=gr.themes.sizes.spacing_lg,
25
  text_size=gr.themes.sizes.text_md,
26
  **kwargs
@@ -31,29 +28,33 @@ class AppleSoft(gr.themes.Base):
31
  neutral_hue=neutral_hue,
32
  radius_size=radius_size,
33
  font=font,
34
- font_mono=font_mono,
35
  spacing_size=spacing_size,
36
  text_size=text_size,
37
  **kwargs
38
  )
39
- # 2. Use .set() to override specific CSS variables for the Apple aesthetic
40
  self.set(
41
- # Remove main block shadow for a flatter, modern look
42
- block_shadow="none",
43
- block_label_padding="*spacing_sm *spacing_lg",
44
- # Apply light shadow and clean background to input/panel elements (the "card" effect)
45
  block_background_fill="white",
46
- block_border_width="1px",
 
 
47
  block_border_color="*neutral_200",
48
- # Ensure primary button looks clean and elevated
 
49
  button_primary_background_fill="*primary_500",
50
  button_primary_background_fill_hover="*primary_400",
51
  button_primary_border_color="*primary_500",
52
- button_primary_shadow="0 2px 8px *primary_300", # Subtle shadow for depth
 
 
 
53
  )
54
 
55
  # Instantiate the custom theme
56
- apple_theme = AppleSoft()
 
57
 
58
  # --- Model Loading (Kept for completeness) ---
59
  device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
@@ -61,7 +62,6 @@ device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
61
  # Text-to-Image Model
62
  t2i_model_id = 'meituan-longcat/LongCat-Image'
63
  print(f"πŸ”„ Loading Text-to-Image model from {t2i_model_id}...")
64
- # ... (rest of model loading remains the same) ...
65
  t2i_text_processor = AutoProcessor.from_pretrained(
66
  t2i_model_id,
67
  subfolder='tokenizer'
@@ -86,7 +86,6 @@ print(f"βœ… Text-to-Image model loaded successfully")
86
  # Image Edit Model
87
  edit_model_id = 'meituan-longcat/LongCat-Image-Edit'
88
  print(f"πŸ”„ Loading Image Edit model from {edit_model_id}...")
89
- # ... (rest of model loading remains the same) ...
90
  edit_text_processor = AutoProcessor.from_pretrained(
91
  edit_model_id,
92
  subfolder='tokenizer'
@@ -188,7 +187,7 @@ t2i_example_prompts = [
188
  ]
189
 
190
  # Build Gradio interface
191
- # Passed theme=apple_theme here and fill_width=True for responsiveness
192
  with gr.Blocks(theme=apple_theme, fill_width=True) as demo:
193
  # Retaining the HTML header for branding/title
194
  gr.HTML("""
@@ -207,7 +206,7 @@ with gr.Blocks(theme=apple_theme, fill_width=True) as demo:
207
  with gr.TabItem("Edit Image", id=0):
208
  with gr.Row():
209
  # Left Column (Inputs)
210
- with gr.Column(scale=1, min_width=0, variant="panel"): # variant="panel" applies the card styling from theme
211
  gr.Markdown("### πŸ–ΌοΈ Input Image & Controls")
212
  input_image = gr.Image(
213
  label="Upload Image",
@@ -220,6 +219,7 @@ with gr.Blocks(theme=apple_theme, fill_width=True) as demo:
220
  label="What would you like to change?",
221
  placeholder="e.g., Add a mustache, Change to sunset, Make it vintage...",
222
  lines=2,
 
223
  max_lines=3
224
  )
225
 
@@ -229,7 +229,7 @@ with gr.Blocks(theme=apple_theme, fill_width=True) as demo:
229
  value=42,
230
  step=1,
231
  label="Seed",
232
- visible=False
233
  )
234
 
235
  edit_btn = gr.Button("Edit Image", variant="primary", size="lg")
@@ -290,7 +290,7 @@ with gr.Blocks(theme=apple_theme, fill_width=True) as demo:
290
  value=42,
291
  step=1,
292
  label="Seed",
293
- visible=False
294
  )
295
 
296
  generate_btn = gr.Button("Generate Image", variant="primary", size="lg")
@@ -339,10 +339,9 @@ with gr.Blocks(theme=apple_theme, fill_width=True) as demo:
339
  </div>
340
  """)
341
 
342
- # Launch the app with the custom, programmatic theme
343
  if __name__ == "__main__":
344
  demo.launch(
345
  mcp_server=True,
346
- theme=apple_theme,
347
- # Custom CSS is removed to ensure theme integrity
348
  )
 
4
  from PIL import Image
5
  from transformers import AutoProcessor
6
  from longcat_image.models import LongCatImageTransformer2DModel
7
+ from longcat_image.pipelines import LongCatImagePipeline, LongCatImageEditPipeline
8
  import numpy as np
9
 
10
+ # 1. DEFINE THE CUSTOM THEME CLASS (Programmatic Theming, No Custom CSS)
11
+ # Inherit from Base and use .set() to achieve the Apple aesthetic.
12
+ class AppleStyleTheme(gr.themes.Base):
13
  def __init__(
14
  self,
15
+ # Core Parameters for Apple Aesthetic
16
+ primary_hue=gr.themes.colors.blue,
17
  secondary_hue=gr.themes.colors.gray,
18
  neutral_hue=gr.themes.colors.neutral,
19
+ radius_size=gr.themes.sizes.radius_lg, # Large radius for modern rounded look
20
+ font=["system-ui", "sans-serif"], # Use system fonts for native feel
 
 
 
21
  spacing_size=gr.themes.sizes.spacing_lg,
22
  text_size=gr.themes.sizes.text_md,
23
  **kwargs
 
28
  neutral_hue=neutral_hue,
29
  radius_size=radius_size,
30
  font=font,
 
31
  spacing_size=spacing_size,
32
  text_size=text_size,
33
  **kwargs
34
  )
35
+ # Use .set() to fine-tune variables beyond the core 8
36
  self.set(
37
+ # General clean white/light gray background
38
+ body_background_fill="*neutral_50",
 
 
39
  block_background_fill="white",
40
+ # Remove default shadows for a flatter, cleaner look
41
+ block_shadow="none",
42
+ # Add a subtle border/ring for 'card' definition
43
  block_border_color="*neutral_200",
44
+ block_border_width="1px",
45
+ # Customize button look (Primary blue is defined by primary_hue=blue)
46
  button_primary_background_fill="*primary_500",
47
  button_primary_background_fill_hover="*primary_400",
48
  button_primary_border_color="*primary_500",
49
+ # Tabs (Segmented control look is largely handled by rounded corners and soft theme)
50
+ tabs_border_color="*neutral_200",
51
+ tab_border_color="*neutral_100",
52
+ tab_border_width="0",
53
  )
54
 
55
  # Instantiate the custom theme
56
+ apple_theme = AppleStyleTheme()
57
+ # --- End Theme Definition ---
58
 
59
  # --- Model Loading (Kept for completeness) ---
60
  device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
 
62
  # Text-to-Image Model
63
  t2i_model_id = 'meituan-longcat/LongCat-Image'
64
  print(f"πŸ”„ Loading Text-to-Image model from {t2i_model_id}...")
 
65
  t2i_text_processor = AutoProcessor.from_pretrained(
66
  t2i_model_id,
67
  subfolder='tokenizer'
 
86
  # Image Edit Model
87
  edit_model_id = 'meituan-longcat/LongCat-Image-Edit'
88
  print(f"πŸ”„ Loading Image Edit model from {edit_model_id}...")
 
89
  edit_text_processor = AutoProcessor.from_pretrained(
90
  edit_model_id,
91
  subfolder='tokenizer'
 
187
  ]
188
 
189
  # Build Gradio interface
190
+ # Passed theme=apple_theme and fill_width=True
191
  with gr.Blocks(theme=apple_theme, fill_width=True) as demo:
192
  # Retaining the HTML header for branding/title
193
  gr.HTML("""
 
206
  with gr.TabItem("Edit Image", id=0):
207
  with gr.Row():
208
  # Left Column (Inputs)
209
+ with gr.Column(scale=1, min_width=0, variant="panel"):
210
  gr.Markdown("### πŸ–ΌοΈ Input Image & Controls")
211
  input_image = gr.Image(
212
  label="Upload Image",
 
219
  label="What would you like to change?",
220
  placeholder="e.g., Add a mustache, Change to sunset, Make it vintage...",
221
  lines=2,
222
+ info="Describe the edit you want to make to the uploaded image.",
223
  max_lines=3
224
  )
225
 
 
229
  value=42,
230
  step=1,
231
  label="Seed",
232
+ visible=True # Make visible for control
233
  )
234
 
235
  edit_btn = gr.Button("Edit Image", variant="primary", size="lg")
 
290
  value=42,
291
  step=1,
292
  label="Seed",
293
+ visible=True # Make visible for control
294
  )
295
 
296
  generate_btn = gr.Button("Generate Image", variant="primary", size="lg")
 
339
  </div>
340
  """)
341
 
342
+ # Launch the app with the custom programmatic theme
343
  if __name__ == "__main__":
344
  demo.launch(
345
  mcp_server=True,
346
+ theme=apple_theme,
 
347
  )