Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
|
@@ -7,18 +7,27 @@ 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
|
| 11 |
class AppleStyleTheme(gr.themes.Base):
|
| 12 |
def __init__(
|
| 13 |
self,
|
| 14 |
-
# Core Colors:
|
| 15 |
primary_hue=gr.themes.colors.blue,
|
| 16 |
secondary_hue=gr.themes.colors.gray,
|
| 17 |
-
neutral_hue=gr.themes.colors.
|
| 18 |
-
#
|
| 19 |
radius_size=gr.themes.sizes.radius_lg,
|
| 20 |
-
#
|
| 21 |
-
font=[
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
font_mono=gr.themes.GoogleFont("IBM Plex Mono"),
|
| 23 |
spacing_size=gr.themes.sizes.spacing_lg,
|
| 24 |
text_size=gr.themes.sizes.text_md,
|
|
@@ -35,33 +44,69 @@ class AppleStyleTheme(gr.themes.Base):
|
|
| 35 |
text_size=text_size,
|
| 36 |
**kwargs
|
| 37 |
)
|
| 38 |
-
|
|
|
|
| 39 |
self.set(
|
| 40 |
-
#
|
| 41 |
-
body_background_fill="
|
| 42 |
-
block_background_fill="
|
|
|
|
| 43 |
|
| 44 |
-
#
|
| 45 |
-
block_border_color="
|
| 46 |
block_border_width="1px",
|
| 47 |
-
block_shadow="
|
|
|
|
| 48 |
|
| 49 |
-
#
|
| 50 |
-
|
| 51 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 52 |
button_primary_text_color="white",
|
| 53 |
-
button_primary_border_color="
|
|
|
|
| 54 |
|
| 55 |
-
#
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
|
|
|
|
|
|
| 60 |
)
|
| 61 |
|
| 62 |
# Instantiate the theme
|
| 63 |
apple_theme = AppleStyleTheme()
|
| 64 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 65 |
# --- Model Loading ---
|
| 66 |
device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
|
| 67 |
|
|
@@ -193,13 +238,16 @@ t2i_example_prompts = [
|
|
| 193 |
]
|
| 194 |
|
| 195 |
# Build Gradio interface
|
|
|
|
| 196 |
with gr.Blocks(fill_width=True) as demo:
|
|
|
|
|
|
|
| 197 |
gr.HTML("""
|
| 198 |
<div style="text-align: center; padding: 40px 20px 30px 20px;">
|
| 199 |
-
<h1 style="font-size: 48px; font-weight: 700; margin: 0; color: #1d1d1f;">
|
| 200 |
LongCat Studio
|
| 201 |
</h1>
|
| 202 |
-
<p style="font-size: 20px; color: #86868b; margin-top: 12px; font-weight: 400;">
|
| 203 |
AI-powered image generation and editing
|
| 204 |
</p>
|
| 205 |
</div>
|
|
@@ -210,6 +258,7 @@ with gr.Blocks(fill_width=True) as demo:
|
|
| 210 |
with gr.TabItem("Edit Image", id=0):
|
| 211 |
with gr.Row():
|
| 212 |
# Left Column: Inputs
|
|
|
|
| 213 |
with gr.Column(scale=1, variant="panel"):
|
| 214 |
gr.Markdown("### 🖼️ Input Image & Controls")
|
| 215 |
input_image = gr.Image(
|
|
@@ -271,13 +320,14 @@ with gr.Blocks(fill_width=True) as demo:
|
|
| 271 |
max_lines=6
|
| 272 |
)
|
| 273 |
|
|
|
|
| 274 |
t2i_width = gr.Slider(
|
| 275 |
minimum=512,
|
| 276 |
maximum=2048,
|
| 277 |
value=1344,
|
| 278 |
step=64,
|
| 279 |
label="Width",
|
| 280 |
-
visible=False,
|
| 281 |
)
|
| 282 |
|
| 283 |
t2i_height = gr.Slider(
|
|
@@ -286,7 +336,7 @@ with gr.Blocks(fill_width=True) as demo:
|
|
| 286 |
value=768,
|
| 287 |
step=64,
|
| 288 |
label="Height",
|
| 289 |
-
visible=False,
|
| 290 |
)
|
| 291 |
|
| 292 |
t2i_seed = gr.Slider(
|
|
@@ -345,8 +395,10 @@ with gr.Blocks(fill_width=True) as demo:
|
|
| 345 |
""")
|
| 346 |
|
| 347 |
# Launch the app
|
|
|
|
| 348 |
if __name__ == "__main__":
|
| 349 |
demo.launch(
|
| 350 |
mcp_server=True,
|
| 351 |
theme=apple_theme,
|
|
|
|
| 352 |
)
|
|
|
|
| 7 |
from longcat_image.pipelines import LongCatImageEditPipeline, LongCatImagePipeline
|
| 8 |
import numpy as np
|
| 9 |
|
| 10 |
+
# 1. DEFINE THE CUSTOM APPLE THEME
|
| 11 |
class AppleStyleTheme(gr.themes.Base):
|
| 12 |
def __init__(
|
| 13 |
self,
|
| 14 |
+
# Apple Core Colors: System Blue, Cool Grays
|
| 15 |
primary_hue=gr.themes.colors.blue,
|
| 16 |
secondary_hue=gr.themes.colors.gray,
|
| 17 |
+
neutral_hue=gr.themes.colors.gray,
|
| 18 |
+
# Sizing: Rounded corners (iOS style) and generous spacing
|
| 19 |
radius_size=gr.themes.sizes.radius_lg,
|
| 20 |
+
# Fonts: The stack that prioritizes San Francisco (Apple's font)
|
| 21 |
+
font=[
|
| 22 |
+
"system-ui",
|
| 23 |
+
"-apple-system",
|
| 24 |
+
"BlinkMacSystemFont",
|
| 25 |
+
"Segoe UI",
|
| 26 |
+
"Roboto",
|
| 27 |
+
"Helvetica Neue",
|
| 28 |
+
"Arial",
|
| 29 |
+
"sans-serif"
|
| 30 |
+
],
|
| 31 |
font_mono=gr.themes.GoogleFont("IBM Plex Mono"),
|
| 32 |
spacing_size=gr.themes.sizes.spacing_lg,
|
| 33 |
text_size=gr.themes.sizes.text_md,
|
|
|
|
| 44 |
text_size=text_size,
|
| 45 |
**kwargs
|
| 46 |
)
|
| 47 |
+
|
| 48 |
+
# Override specific CSS variables for the "Apple Look"
|
| 49 |
self.set(
|
| 50 |
+
# Backgrounds: Very light gray background, pure white cards
|
| 51 |
+
body_background_fill="#F5F5F7", # Apple's signature light gray
|
| 52 |
+
block_background_fill="#FFFFFF",
|
| 53 |
+
block_label_background_fill="#FFFFFF",
|
| 54 |
|
| 55 |
+
# Borders: Very subtle, thin borders
|
| 56 |
+
block_border_color="#E5E5EA",
|
| 57 |
block_border_width="1px",
|
| 58 |
+
block_shadow="0 4px 6px -1px rgba(0, 0, 0, 0.05), 0 2px 4px -1px rgba(0, 0, 0, 0.03)", # Soft shadow
|
| 59 |
+
block_padding="*spacing_lg",
|
| 60 |
|
| 61 |
+
# Inputs: Light gray background for inputs (like iOS grouped tables)
|
| 62 |
+
input_background_fill="#F2F2F7",
|
| 63 |
+
input_border_color="transparent",
|
| 64 |
+
input_shadow="none",
|
| 65 |
+
input_shadow_focus="0 0 0 2px #007AFF", # Apple Blue focus ring
|
| 66 |
+
|
| 67 |
+
# Buttons: Flat Apple Blue button
|
| 68 |
+
button_primary_background_fill="#007AFF",
|
| 69 |
+
button_primary_background_fill_hover="#0071E3",
|
| 70 |
button_primary_text_color="white",
|
| 71 |
+
button_primary_border_color="transparent",
|
| 72 |
+
button_primary_shadow="none",
|
| 73 |
|
| 74 |
+
# Text
|
| 75 |
+
block_label_text_color="*neutral_500",
|
| 76 |
+
block_title_text_color="*neutral_900",
|
| 77 |
+
|
| 78 |
+
# Tabs
|
| 79 |
+
tabs_border_color="#E5E5EA",
|
| 80 |
+
text_color="#1d1d1f",
|
| 81 |
)
|
| 82 |
|
| 83 |
# Instantiate the theme
|
| 84 |
apple_theme = AppleStyleTheme()
|
| 85 |
|
| 86 |
+
# 2. CUSTOM CSS FOR DARK MODE FIXES
|
| 87 |
+
# This CSS targets the HTML elements specifically when Gradio is in "dark" mode.
|
| 88 |
+
custom_css = """
|
| 89 |
+
/* Force title color in dark mode */
|
| 90 |
+
.dark #app-title {
|
| 91 |
+
color: #F5F5F7 !important;
|
| 92 |
+
}
|
| 93 |
+
.dark #app-subtitle {
|
| 94 |
+
color: #A1A1A6 !important;
|
| 95 |
+
}
|
| 96 |
+
|
| 97 |
+
/* Dark mode adjustments for the custom theme colors */
|
| 98 |
+
.dark .gradio-container {
|
| 99 |
+
background-color: #000000 !important;
|
| 100 |
+
}
|
| 101 |
+
.dark .block.panel {
|
| 102 |
+
background-color: #1C1C1E !important; /* Apple Dark Mode Gray */
|
| 103 |
+
border-color: #2C2C2E !important;
|
| 104 |
+
}
|
| 105 |
+
.dark input, .dark textarea, .dark .gr-input {
|
| 106 |
+
background-color: #2C2C2E !important;
|
| 107 |
+
}
|
| 108 |
+
"""
|
| 109 |
+
|
| 110 |
# --- Model Loading ---
|
| 111 |
device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
|
| 112 |
|
|
|
|
| 238 |
]
|
| 239 |
|
| 240 |
# Build Gradio interface
|
| 241 |
+
# Theme and CSS are NOT passed here for Gradio 6 compliance
|
| 242 |
with gr.Blocks(fill_width=True) as demo:
|
| 243 |
+
|
| 244 |
+
# Header with IDs for CSS targeting
|
| 245 |
gr.HTML("""
|
| 246 |
<div style="text-align: center; padding: 40px 20px 30px 20px;">
|
| 247 |
+
<h1 id="app-title" style="font-size: 48px; font-weight: 700; margin: 0; color: #1d1d1f; letter-spacing: -0.02em;">
|
| 248 |
LongCat Studio
|
| 249 |
</h1>
|
| 250 |
+
<p id="app-subtitle" style="font-size: 20px; color: #86868b; margin-top: 12px; font-weight: 400;">
|
| 251 |
AI-powered image generation and editing
|
| 252 |
</p>
|
| 253 |
</div>
|
|
|
|
| 258 |
with gr.TabItem("Edit Image", id=0):
|
| 259 |
with gr.Row():
|
| 260 |
# Left Column: Inputs
|
| 261 |
+
# scale=1 without min_width allows stacking on mobile
|
| 262 |
with gr.Column(scale=1, variant="panel"):
|
| 263 |
gr.Markdown("### 🖼️ Input Image & Controls")
|
| 264 |
input_image = gr.Image(
|
|
|
|
| 320 |
max_lines=6
|
| 321 |
)
|
| 322 |
|
| 323 |
+
# HIDDEN SLIDERS (values passed silently)
|
| 324 |
t2i_width = gr.Slider(
|
| 325 |
minimum=512,
|
| 326 |
maximum=2048,
|
| 327 |
value=1344,
|
| 328 |
step=64,
|
| 329 |
label="Width",
|
| 330 |
+
visible=False,
|
| 331 |
)
|
| 332 |
|
| 333 |
t2i_height = gr.Slider(
|
|
|
|
| 336 |
value=768,
|
| 337 |
step=64,
|
| 338 |
label="Height",
|
| 339 |
+
visible=False,
|
| 340 |
)
|
| 341 |
|
| 342 |
t2i_seed = gr.Slider(
|
|
|
|
| 395 |
""")
|
| 396 |
|
| 397 |
# Launch the app
|
| 398 |
+
# Theme and CSS are passed here for Gradio 6 compliance
|
| 399 |
if __name__ == "__main__":
|
| 400 |
demo.launch(
|
| 401 |
mcp_server=True,
|
| 402 |
theme=apple_theme,
|
| 403 |
+
css=custom_css
|
| 404 |
)
|