Saravutw commited on
Commit
3fa0129
·
verified ·
1 Parent(s): d88ef2f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +52 -132
app.py CHANGED
@@ -1,142 +1,62 @@
1
  import gradio as gr
2
- import numpy as np
3
- import random
4
- from PIL import Image
5
- from diffusers import StableDiffusionXLPipeline
6
- import torch
7
- import gc
8
 
9
- # System configuration
10
- device = "cpu"
11
- model_repo_id = "stabilityai/sdxl-turbo"
12
 
13
- # 1. Load SDXL Turbo Model
14
- pipe = StableDiffusionXLPipeline.from_pretrained(
15
- model_repo_id,
16
- torch_dtype=torch.float32,
17
- use_safetensors=True
18
- )
19
- pipe.enable_attention_slicing()
20
-
21
- MAX_SEED = np.iinfo(np.int32).max
22
-
23
- # Style templates
24
- STYLE_TEMPLATES = {
25
- "None": "{prompt}",
26
- "Cinematic": "{prompt}, cinematic lighting, highly detailed, 8k, masterpiece",
27
- "Anime": "{prompt}, anime style, vibrant colors, clean lines, high quality",
28
- "Digital Art": "{prompt}, digital illustration, sharp focus, trend on artstation",
29
- "Oil Painting": "{prompt}, oil painting texture, brush strokes, classical art",
30
- "Photorealistic": "{prompt}, ultra realistic, photorealistic, raw photo, 8k uhd"
 
 
 
 
 
 
 
 
 
31
  }
32
-
33
- def update_resolution(aspect_ratio):
34
- if aspect_ratio == "1:1 (512x512)":
35
- return 512, 512
36
- elif aspect_ratio == "4:3 (512x384)":
37
- return 512, 384
38
- elif aspect_ratio == "3:4 (384x512)":
39
- return 384, 512
40
- elif aspect_ratio == "16:9 (512x288)":
41
- return 512, 288
42
- return 512, 512
43
-
44
- def infer(
45
- prompt,
46
- negative_prompt,
47
- seed,
48
- randomize_seed,
49
- width,
50
- height,
51
- guidance_scale,
52
- num_inference_steps,
53
- style_selection,
54
- auto_enhance
55
- ):
56
- if randomize_seed:
57
- seed = random.randint(0, MAX_SEED)
58
-
59
- generator = torch.Generator(device=device).manual_seed(seed)
60
-
61
- # Apply style and auto-enhancement
62
- final_prompt = STYLE_TEMPLATES.get(style_selection, "{prompt}").format(prompt=prompt)
63
- if auto_enhance:
64
- final_prompt += ", professional lighting, high resolution, intricate details"
65
-
66
- try:
67
- image = pipe(
68
- prompt=final_prompt,
69
- negative_prompt=negative_prompt,
70
- guidance_scale=guidance_scale,
71
- num_inference_steps=num_inference_steps,
72
- width=width,
73
- height=height,
74
- generator=generator,
75
- ).images[0]
76
- except Exception as e:
77
- print(f"Inference Error: {e}")
78
- return None, seed
79
- finally:
80
- gc.collect()
81
-
82
- return image, seed
83
-
84
- # UI Styling
85
- custom_css = """
86
- body, .gradio-container { background-color: #0b0b0b !important; color: #ff0000 !important; }
87
- button.primary { background: linear-gradient(90deg, #8b0000, #ff0000) !important; color: white !important; border: none !important; }
88
- footer { visibility: hidden; }
89
- .tabs, .accordion, .input-container { border: 1px solid #440000 !important; }
90
  """
91
 
92
- with gr.Blocks(css=custom_css, theme=gr.themes.Soft(primary_hue="red", neutral_hue="slate")) as demo:
93
- gr.Markdown("# <span style='color: #ff0000;'>Z-TURBO RED ENGINE</span>")
94
-
95
- with gr.Row():
96
- with gr.Column(scale=3):
97
- prompt = gr.Textbox(label="Main Prompt", placeholder="What do you want to create?", lines=3)
98
- style_selection = gr.Dropdown(choices=list(STYLE_TEMPLATES.keys()), value="None", label="Art Style")
99
- auto_enhance = gr.Checkbox(label="Auto Prompt Enhancement", value=False)
100
- run_button = gr.Button("GENERATE IMAGE", variant="primary")
101
-
102
- with gr.Column(scale=2):
103
- result = gr.Image(label="Result", type="pil")
104
- seed_display = gr.Number(label="Last Seed Used", interactive=False)
105
 
106
- with gr.Row():
107
- with gr.Accordion("Advanced Parameters", open=True):
108
- with gr.Row():
109
- aspect_ratio = gr.Radio(
110
- choices=["1:1 (512x512)", "4:3 (512x384)", "3:4 (384x512)", "16:9 (512x288)"],
111
- value="1:1 (512x512)",
112
- label="Quick Aspect Ratio"
113
- )
114
- with gr.Row():
115
- width = gr.Slider(label="Width", minimum=256, maximum=512, step=64, value=512)
116
- height = gr.Slider(label="Height", minimum=256, maximum=512, step=64, value=512)
117
-
118
- with gr.Row():
119
- guidance_scale = gr.Slider(label="Guidance Scale", minimum=0.0, maximum=5.0, step=0.1, value=1.0)
120
- num_inference_steps = gr.Slider(label="Steps", minimum=1, maximum=20, step=1, value=8)
121
-
122
- with gr.Row():
123
- seed = gr.Slider(label="Seed", minimum=0, maximum=MAX_SEED, step=1, value=0)
124
- randomize_seed = gr.Checkbox(label="Randomize Seed", value=True)
125
 
126
- # Negative Prompt at the very bottom
127
- negative_prompt = gr.Textbox(label="Negative Prompt (Short)", value="blurry, ugly, distorted", lines=1)
 
128
 
129
- # Event handlers
130
- aspect_ratio.change(fn=update_resolution, inputs=[aspect_ratio], outputs=[width, height])
131
-
132
- run_button.click(
133
- fn=infer,
134
- inputs=[
135
- prompt, negative_prompt, seed, randomize_seed,
136
- width, height, guidance_scale, num_inference_steps,
137
- style_selection, auto_enhance
138
- ],
139
- outputs=[result, seed_display],
140
- )
141
 
142
- demo.launch()
 
 
1
  import gradio as gr
2
+ import os
 
 
 
 
 
3
 
4
+ URL_EDITOR = "https://selfit-camera-omni-image-editor.hf.space/?__theme=dark"
5
+ URL_VIDEO = "https://frameai4687-omni-video-factory.hf.space/?__theme=dark"
 
6
 
7
+ css = """
8
+ .gradio-container {
9
+ max-width: 100% !important;
10
+ padding: 0 !important;
11
+ background-color: #0b0f19 !important;
12
+ }
13
+ #status-bar {
14
+ background: linear-gradient(90deg, #1e293b 0%, #0f172a 100%);
15
+ color: #38bdf8;
16
+ padding: 10px;
17
+ font-weight: bold;
18
+ border-bottom: 2px solid #38bdf8;
19
+ text-align: center;
20
+ font-size: 1em;
21
+ /* รองรับพื้นที่ปลอดภัยสำหรับมือถือที่มีติ่งหน้าจอ */
22
+ padding-top: env(safe-area-inset-top, 10px);
23
+ }
24
+ iframe {
25
+ width: 100%;
26
+ height: 85vh;
27
+ border: none;
28
+ }
29
+ /* ปรับแต่งสำหรับหน้าจอขนาดเล็ก (Mobile) */
30
+ @media (max-width: 768px) {
31
+ #status-bar { font-size: 0.8em; }
32
+ iframe { height: 80vh; }
33
+ .tabs button { font-size: 0.7em !important; padding: 5px !important; }
34
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
35
  """
36
 
37
+ js_func = """
38
+ function() {
39
+ const tabs = document.querySelectorAll('.tabs button');
40
+ const statusBar = document.querySelector('#status-bar span');
41
+ if(tabs && statusBar) {
42
+ tabs.forEach(tab => {
43
+ tab.addEventListener('click', () => {
44
+ statusBar.innerText = tab.innerText.toUpperCase();
45
+ });
46
+ });
47
+ }
48
+ }
49
+ """
50
 
51
+ with gr.Blocks(css=css, title="Omni Studio Pro", js=js_func) as demo:
52
+ gr.HTML('<div id="status-bar">SYSTEM ACTIVE: <span>🎨 OMNI IMAGE EDITOR</span></div>')
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
53
 
54
+ with gr.Tabs() as tabs:
55
+ with gr.Tab("🎨 Omni Image Editor"):
56
+ gr.HTML(f'<iframe src="{URL_EDITOR}" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" allowfullscreen></iframe>')
57
 
58
+ with gr.Tab("🎬 Omni Video Factory"):
59
+ gr.HTML(f'<iframe src="{URL_VIDEO}" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" allowfullscreen></iframe>')
 
 
 
 
 
 
 
 
 
 
60
 
61
+ if __name__ == "__main__":
62
+ demo.launch(server_name="0.0.0.0", server_port=int(os.getenv("PORT", "7860")))