Update app.py
Some checks failed
society-ai-hub-container-cache Actions Demo / build (push) Has been cancelled

This commit is contained in:
Hezi Aharon 2024-12-11 15:27:40 +00:00
parent 4f4e1df28b
commit bf326688c5

22
app.py

@ -11,9 +11,17 @@ API_URL = 'https://hub.societyai.com/models/flux-1-schnell/infer'
API_TOKEN = os.environ.get("SAI_API_TOKEN", "")
MAX_SEED = np.iinfo(np.int32).max
MAX_IMAGE_SIZE = 2048
CYBERPUNK_STYLE = (
"Create a highly detailed and visually stunning image in a Cyberpunk theme, "
"regardless of the subject or concept described. Use neon lights, futuristic technology, "
"gritty urban environments, and cybernetic enhancements as core elements of the design. "
"Blend a mix of dystopian aesthetics, vibrant holographic displays, and advanced robotics "
"to capture the essence of Cyberpunk, while adapting to the users specific prompt or description seamlessly. "
"Maintain a bold and immersive atmosphere that conveys a high-tech, neon-lit future."
)
with gr.Blocks(css="footer {visibility: hidden}") as demo:
gr.Markdown("## FLUX.1-schnell Image Generation")
gr.Markdown("## FLUX.1-schnell Cyberpunk Image Generation")
with gr.Row():
prompt = gr.Textbox(label="Prompt", lines=2, placeholder="Enter your prompt here")
@ -47,19 +55,23 @@ with gr.Blocks(css="footer {visibility: hidden}") as demo:
return None, "Error: Both width and height must be divisible by 8."
if randomize_seed:
seed = random.randint(0, MAX_SEED)
# Combine the Cyberpunk style with the user prompt
full_prompt = f"{CYBERPUNK_STYLE} {prompt.strip()}"
# Prepare the data payload
inputs = [
{
"name": "PROMPT",
"shape": [1],
"datatype": "BYTES",
"data": [prompt]
"data": [full_prompt]
},
{
"name": "INIT_IMAGE",
"shape": [1],
"datatype": "BYTES",
"data": [""] # not supported
"data": [""] # not supported
},
{
"name": "WIDTH",
@ -95,7 +107,7 @@ with gr.Blocks(css="footer {visibility: hidden}") as demo:
"name": "IMAGE_STRENGTH",
"shape": [1],
"datatype": "FP32",
"data": [0.0] # not supported
"data": [0.0] # not supported
}
]
@ -125,7 +137,7 @@ with gr.Blocks(css="footer {visibility: hidden}") as demo:
# Convert to numpy array
image = Image.open(BytesIO(image_data))
image_np = np.array(image)
return image_np, "Image generated successfully.", seed
return image_np, "Cyberpunk Image generated successfully.", seed
else:
# Handle error
return None, f"Error: {response.status_code} - {response.text}", seed