Spaces:
Runtime error
Runtime error
File size: 14,224 Bytes
9d560e2 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 |
import gradio as gr
import random
from random import choice
import requests
import base64
import io
from PIL import Image
import plotly.graph_objects as go
import numpy as np
from PIL import Image, ImageDraw
import random
import re
url = "http://73.255.78.150:7909/sdapi/v1/txt2img"
session_seed = None
last_session_seed = None
# Predefined arrays for design parameters and their corresponding values
ALL_TITLES = [
'Minimalism', 'Bauhaus', 'Organic Design', 'Brutalism', 'Mid-century Modern',
'Retro-Vintage', 'Futurism', 'Tesselated', 'Streamlined', 'Timeless',
'Industrial Chic', 'Art Deco', 'Elegant', 'Biomorphic Design', 'High Contrast',
'Deconstructivism', 'Zen Design', 'Pop Art', 'Cyberpunk', 'Sustainable Design',
'Angular', 'Textured', 'Symmetric', 'Utilitarian', 'Dynamic Energy Flow'
]
ALL_VALUES = [
1.5, 1.2, 0.8, 1.0, 0.5, -1.0, 0.3, -0.5, 1.1, -0.7,
0.9, 1.3, 0.2, -1.3, -0.9, -1.1, 0.7, 0.6, -0.8, 0.4,
-0.2, 0.1, -1.2, 0.0, -0.4
]
# Base payload for API call
base_payload = {
"steps": 20,
"seed": 1,
"width": 768,
"height": 512,
}
# New function to generate radar chart using Plotly
def generate_figure(r_values, theta_values, chart_title):
fig = go.Figure(data=go.Scatterpolar(
r=r_values, theta=theta_values, mode='lines+markers',
marker=dict(size=10), fill='toself')
)
fig.update_layout(
polar=dict(radialaxis=dict(visible=True, range=[0, 1.5])),
showlegend=False, title=chart_title
)
return fig
# New function for generating the radar chart
def display_radar_chart(input_parameters, randomize_values, randomize_titles, randomize_param_count, chart_title, param_count, param1, param2, param3, param4, param5, param6, param7, param8, param9, param10):
if randomize_param_count:
param_count = random.randint(3, 10)
# π€ Create a temporary array from comma-separated input_parameters
if input_parameters:
parameters = re.split(r'\s*,\s*', input_parameters.strip())
if len(parameters) > param_count:
parameters = parameters[:param_count]
elif randomize_titles:
parameters = random.sample(ALL_TITLES, param_count)
else:
parameters = []
# π€ Fill in missing parameters based on param_count
if len(parameters) < param_count:
remaining_count = param_count - len(parameters)
if randomize_titles:
additional_params = random.sample(set(ALL_TITLES) - set(parameters), remaining_count)
else:
additional_params = ALL_TITLES[len(parameters):len(parameters) + remaining_count]
parameters.extend(additional_params)
elif len(parameters) > param_count:
parameters = parameters[:param_count]
# Existing code for randomizing values remains the same
if randomize_values:
r_values = random.sample(ALL_VALUES, len(parameters))
else:
r_values = [param1, param2, param3, param4, param5, param6, param7, param8, param9, param10][:len(parameters)]
chart_figure = generate_figure(r_values, parameters, chart_title)
slider_labels = ", ".join([f"{parameters[i]}: {r_values[i]:.2f}" for i in range(len(r_values))])
return chart_figure, slider_labels
def generate_image(prompt, steps, reset_seed, increment_seed):
global session_seed
global last_session_seed
if reset_seed:
if session_seed != -1:
last_session_seed = session_seed
session_seed = -1
elif not reset_seed and last_session_seed is not None:
session_seed = last_session_seed
elif session_seed is None:
session_seed = random.randint(0, 10000)
if increment_seed and session_seed != -1:
session_seed += 1
last_session_seed = session_seed
payload = {
"prompt": prompt,
"steps": steps,
"seed": session_seed,
"height": 768,
"width": 1024,
}
response = requests.post(url, json=payload)
response_data = response.json()
try:
image = Image.open(io.BytesIO(base64.b64decode(response_data['images'][0])))
return image
except KeyError:
error_message = response_data.get('error', 'Unknown error')
error_image = Image.new('RGB', (512, 512), color=(73, 109, 137))
d = ImageDraw.Draw(error_image)
d.text((10, 10), f"Error: {error_message}", fill=(255, 255, 0))
return error_image
image_list = [f"Images/Image {i}.png" for i in range(1, 19)]
def update_moodboard(btn_value):
return {moodboard_image: choice(image_list)}
with gr.Blocks() as app:
gr.Markdown("# Magazine Layouts")
with gr.Tab("Dynamic Dashboard"):
with gr.Row():
gr.Textbox(lines=1, value="Dashboard: Dynamic View")
gr.Dropdown(options=["Overview", "Details", "Summary"], label="Dashboard Mode")
with gr.Row():
gr.Textbox(lines=1, value="Status: Active")
gr.Slider(minimum=0, maximum=100, label="Dashboard Progress")
# Image Generation Section
with gr.Column():
gr.Markdown("### Image Generation")
prompt_input = gr.Textbox(lines=2, placeholder="Imagine something...", label="Prompt")
steps_input = gr.Slider(minimum=15, maximum=50, step=15, default=5, label="Steps")
reset_seed_input = gr.Checkbox(label="Randomize Composition")
increment_seed_input = gr.Checkbox(label="New Composition")
img_output = gr.Image(label="Generated Image")
# Radar Chart Section
with gr.Column():
gr.Markdown("### Radar Chart")
input_parameters = gr.Textbox(placeholder="Enter parameters, separated by commas", label="Parameters")
randomize_values = gr.Checkbox(label="Randomize Values")
chart_title = gr.Textbox(value="Radar Chart", label="Chart Title")
param_count = gr.Slider(minimum=3, maximum=10, step=1, label="Parameter Count")
radar_output = gr.Plot(label="Radar Chart")
with gr.Row():
gr.Image(choice(image_list))
gr.Textbox(lines=4, value="Dashboard Insights: Real-time updates and metrics")
gr.Button("Refresh Dashboard", label="Refresh Dashboard")
with gr.Tab("API Call Interface"):
with gr.Blocks() as main_blocks:
with gr.Row():
with gr.Column():
img_output = gr.Image(label="Generated Image")
with gr.Row():
with gr.Column(scale=1):
prompt_input = gr.Textbox(lines=2, placeholder="Imagine something...", label="Prompt")
steps_input = gr.Slider(minimum=15, maximum=50, step=15, default=5, label="Steps")
with gr.Column(scale=1):
reset_seed_input = gr.Checkbox(label="Randomize Composition")
increment_seed_input = gr.Checkbox(label="New Composition")
iface = gr.Interface(
fn=generate_image,
inputs=[prompt_input, steps_input, reset_seed_input, increment_seed_input],
outputs=[img_output],
live=False,
layout=main_blocks
)
# Design Proposal Board with Multi-layered Layouts
with gr.Tab("Design Proposal Board"):
with gr.Row():
gr.Textbox(lines=1, value="Project: Redesign UI")
gr.Dropdown(options=["Planning", "Execution", "Review"], label="Project Stage")
with gr.Row():
gr.Textbox(lines=1, value="Timeline: 3 months")
gr.Slider(minimum=0, maximum=100, label="Progress")
gr.Image(choice(image_list))
gr.Button("View Milestones", label="View Milestones")
gr.Textbox(lines=4, value="Goals: Improve user engagement by 20%")
with gr.Tab("The Minimalist Layout"):
with gr.Column():
gr.Markdown("## Minimalist")
gr.Image("Images/Image 1.png")
gr.Textbox(lines=4, value="It was a stormy night, and the vintage car roared down the highway.")
with gr.Tab("The Grid Layout"):
with gr.Row():
with gr.Column(scale=1):
gr.Image("Images/Image 2.png")
gr.Textbox(lines=4, value="The old leather seats had stories to tell.")
with gr.Column(scale=1):
gr.Image("Images/Image 3.png")
gr.Textbox(lines=4, value="With every curve and turn, the car seemed to whisper.")
with gr.Tab("The Asymmetrical Layout"):
with gr.Row():
with gr.Column(scale=2):
gr.Markdown("## Artistic Layout")
gr.Image("Images/Image 4.png")
with gr.Column(scale=1):
gr.Image("Images/Image 5.png")
gr.Textbox(lines=3, value="As the dawn broke, the car finally stopped.")
with gr.Tab("The F-Layout"):
with gr.Row():
with gr.Column(scale=3):
gr.Image("Images/Image 6.png")
with gr.Column(scale=1):
gr.Textbox(lines=4, value="It was a stormy night, and the vintage car roared down the highway.")
with gr.Tab("The Radial Layout"):
with gr.Row():
with gr.Column(scale=1):
gr.Image("Images/Image 9.png")
with gr.Column(scale=1):
gr.Image("Images/Image 10.png")
with gr.Row():
with gr.Column(scale=1):
gr.Image("Images/Image 11.png")
with gr.Column(scale=1):
gr.Textbox(lines=4, value="As the dawn broke, the car finally stopped.")
with gr.Column(scale=1):
gr.Image("Images/Image 12.png")
with gr.Tab("Trading Card Layout 1"):
with gr.Column():
gr.Image(choice(image_list))
gr.Textbox(lines=1, value="Car Model: Mustang")
gr.Textbox(lines=1, value="Year: 1965")
gr.Textbox(lines=2, value="Stats: Speed 200mph, Mileage 15mpg")
gr.Textbox(lines=3, value="The Mustang is a classic American muscle car.")
# Museum Art Gallery: Spotlight Layout
with gr.Tab("Spotlight Layout"):
gr.Image(choice(image_list))
with gr.Row():
gr.Textbox(lines=1, value="Art: Moonlit Sonata")
gr.Textbox(lines=1, value="Artist: L. Vinci")
gr.Textbox(lines=1, value="Year: 1911")
gr.Textbox(lines=3, value="A single spotlight shines on this masterpiece, illuminating its intricate details and vivid colors.")
# Museum Art Gallery: Interactive Kiosk Layout
with gr.Tab("Interactive Kiosk Layout"):
with gr.Row():
with gr.Column(scale=1):
gr.Image(choice(image_list))
with gr.Column(scale=1):
gr.Textbox(lines=1, value="Art: Pixelated Reality")
gr.Textbox(lines=1, value="Artist: G. O'Keeffe")
gr.Textbox(lines=1, value="Year: 2001")
gr.Textbox(lines=4, value="Step up to the interactive kiosk to dive deeper into the story and significance of the artwork.")
# Moodboard for a Designer
with gr.Tab("Moodboard for a Designer"):
with gr.Row():
gr.Image(choice(image_list))
gr.Textbox(lines=1, value="Color: #FF5733")
gr.Textbox(lines=1, value="Font: Arial")
with gr.Row():
gr.Textbox(lines=1, value="Quote: Design is intelligence made visible.")
gr.Image(choice(image_list))
gr.Textbox(lines=1, value="Project: Logo Design")
# Comic Book with Dynamic Content Loading
with gr.Tab("Comic Book"):
with gr.Row():
gr.Textbox(lines=1, value="Title: The Adventures of Grado")
gr.Image(choice(image_list))
with gr.Row():
gr.Textbox(lines=1, value="BOOM!")
gr.Image(choice(image_list))
gr.Textbox(lines=2, value="Character: Oh no!")
gr.Button("Next Page", label="Next Page")
gr.Textbox(lines=1, value="Caption: To be continued...")
with gr.Tab("Radar Chart"):
with gr.Row():
input_parameters = gr.Textbox(placeholder="Enter parameters, separated by commas", label="Parameters")
randomize_values = gr.Checkbox(label="Randomize Values")
randomize_titles = gr.Checkbox(label="Randomize Titles")
randomize_param_count = gr.Checkbox(label="Randomize Parameter Count")
chart_title = gr.Textbox(value="Radar Chart", label="Chart Title")
param_count = gr.Slider(minimum=3, maximum=10, step=1, label="Parameter Count")
param1 = gr.Slider(minimum=-1.5, maximum=1.5, step=0.1, label="Parameter 1")
param2 = gr.Slider(minimum=-1.5, maximum=1.5, step=0.1, label="Parameter 2")
param3 = gr.Slider(minimum=-1.5, maximum=1.5, step=0.1, label="Parameter 3")
param4 = gr.Slider(minimum=-1.5, maximum=1.5, step=0.1, label="Parameter 4")
param5 = gr.Slider(minimum=-1.5, maximum=1.5, step=0.1, label="Parameter 5")
param6 = gr.Slider(minimum=-1.5, maximum=1.5, step=0.1, label="Parameter 6")
param7 = gr.Slider(minimum=-1.5, maximum=1.5, step=0.1, label="Parameter 7")
param8 = gr.Slider(minimum=-1.5, maximum=1.5, step=0.1, label="Parameter 8")
param9 = gr.Slider(minimum=-1.5, maximum=1.5, step=0.1, label="Parameter 9")
param10 = gr.Slider(minimum=-1.5, maximum=1.5, step=0.1, label="Parameter 10")
radar_output = gr.Plot(label="Radar Chart")
slider_labels_output = gr.Textbox(label="Prompt: Slider Labels")
radar_interface = gr.Interface(
fn=display_radar_chart,
inputs=[input_parameters, randomize_values, randomize_titles, randomize_param_count, chart_title, param_count, param1, param2, param3, param4, param5, param6, param7, param8, param9, param10], # Include param6 to param10
outputs=[radar_output, slider_labels_output]
)
app.launch()
|