TS447 commited on
Commit
dc4fc93
·
verified ·
1 Parent(s): c147147

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +129 -0
app.py CHANGED
@@ -0,0 +1,129 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from PIL import Image, ImageEnhance
3
+ import os
4
+
5
+ # --- 1. Processing Logic ---
6
+ def process_image(image, split_count, should_enhance, format_type):
7
+ if image is None:
8
+ return None
9
+
10
+ # Enhancement
11
+ if should_enhance:
12
+ enhancer = ImageEnhance.Sharpness(image)
13
+ image = enhancer.enhance(1.5)
14
+ contrast = ImageEnhance.Contrast(image)
15
+ image = contrast.enhance(1.1)
16
+
17
+ img_width, img_height = image.size
18
+ split_width = img_width // int(split_count)
19
+ output_files = []
20
+
21
+ if not os.path.exists("outputs"):
22
+ os.makedirs("outputs")
23
+
24
+ # Splitting
25
+ for i in range(int(split_count)):
26
+ left = i * split_width
27
+ right = (i + 1) * split_width
28
+ part = image.crop((left, 0, right, img_height))
29
+
30
+ # Transparency Fix
31
+ if part.mode in ('RGBA', 'LA') or (part.mode == 'P' and 'transparency' in part.info):
32
+ part = part.convert('RGB')
33
+
34
+ # Save
35
+ ext = "png" if format_type == "PNG (HQ)" else "jpg"
36
+ save_path = f"outputs/ts_part_{i+1}.{ext}"
37
+ part.save(save_path, quality=95)
38
+ output_files.append(save_path)
39
+
40
+ return output_files
41
+
42
+ # --- 2. Ultra-Premium 3D CSS ---
43
+ custom_css = """
44
+ @import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;700;900&display=swap');
45
+
46
+ body, .gradio-container {
47
+ font-family: 'Inter', sans-serif !important;
48
+ background: radial-gradient(circle at top center, #1a1a2e, #0a0a0a) !important;
49
+ color: #ffffff !important;
50
+ }
51
+
52
+ #main_card {
53
+ background: rgba(255, 255, 255, 0.03);
54
+ backdrop-filter: blur(20px);
55
+ -webkit-backdrop-filter: blur(20px);
56
+ border: 1px solid rgba(255, 255, 255, 0.08);
57
+ border-radius: 24px;
58
+ padding: 40px;
59
+ box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
60
+ max-width: 950px;
61
+ margin: 30px auto;
62
+ }
63
+
64
+ #logo_text h1 {
65
+ background: linear-gradient(to right, #00dbde, #fc00ff);
66
+ -webkit-background-clip: text;
67
+ -webkit-text-fill-color: transparent;
68
+ font-size: 4rem !important;
69
+ font-weight: 900;
70
+ text-align: center;
71
+ margin-bottom: 0px;
72
+ line-height: 1.1;
73
+ letter-spacing: -3px;
74
+ }
75
+
76
+ #subtitle_text h3 {
77
+ text-align: center;
78
+ color: #a0a0a0;
79
+ font-size: 1.2rem;
80
+ font-weight: 400;
81
+ margin-top: 10px;
82
+ margin-bottom: 30px;
83
+ }
84
+
85
+ .block, .svelte-12cmxck, .form {
86
+ background: rgba(255,255,255,0.05) !important;
87
+ border: 1px solid rgba(255,255,255,0.1) !important;
88
+ border-radius: 16px !important;
89
+ }
90
+ label.svelte-1b8gl8r { color: #ccc !important; font-weight: bold; }
91
+
92
+ .primary-btn {
93
+ background: linear-gradient(90deg, #00dbde, #fc00ff) !important;
94
+ border: none !important;
95
+ font-size: 1.2rem !important;
96
+ padding: 15px !important;
97
+ border-radius: 16px !important;
98
+ box-shadow: 0 10px 25px -10px rgba(252, 0, 255, 0.6);
99
+ transition: transform 0.2s ease;
100
+ }
101
+ .primary-btn:hover {
102
+ transform: scale(1.03);
103
+ box-shadow: 0 15px 35px -10px rgba(252, 0, 255, 0.8);
104
+ }
105
+ """
106
+
107
+ # --- 3. Interface ---
108
+ with gr.Blocks(css=custom_css, theme=gr.themes.Base(mode='dark')) as app:
109
+
110
+ with gr.Column(elem_id="main_card"):
111
+ gr.Markdown("# TS", elem_id="logo_text")
112
+ gr.Markdown("### Premium AI Carousel Splitter", elem_id="subtitle_text")
113
+
114
+ with gr.Row(variant="panel"):
115
+ with gr.Column(scale=1):
116
+ inp_img = gr.Image(type="pil", label="Drop Image", sources=["upload", "clipboard"])
117
+ with gr.Group():
118
+ slider = gr.Slider(2, 5, value=3, step=1, label="Split Count")
119
+ with gr.Row():
120
+ enhance_opt = gr.Checkbox(label="Magic Enhance", value=True)
121
+ fmt_opt = gr.Radio(["JPG", "PNG (HQ)"], label="Format", value="JPG")
122
+ btn = gr.Button("⚡ GENERATE", variant="primary", elem_classes=["primary-btn"])
123
+
124
+ with gr.Column(scale=1.2):
125
+ out_gal = gr.Gallery(label="Results", columns=3, height="auto")
126
+
127
+ btn.click(process_image, inputs=[inp_img, slider, enhance_opt, fmt_opt], outputs=out_gal)
128
+
129
+ app.launch()