import gradio as gr import requests from PIL import Image import io import os from fal_client import submit def set_fal_key(api_key): os.environ["FAL_KEY"] = api_key return "FAL API key set successfully!" def generate_image(api_key, model, prompt, image_size, num_inference_steps, guidance_scale, num_images, safety_tolerance, enable_safety_checker, seed): set_fal_key(api_key) arguments = { "prompt": prompt, "image_size": image_size, "num_inference_steps": num_inference_steps, "num_images": num_images, } if model == "Flux Pro": arguments["guidance_scale"] = guidance_scale arguments["safety_tolerance"] = safety_tolerance fal_model = "fal-ai/flux-pro" elif model == "Flux Dev": arguments["guidance_scale"] = guidance_scale arguments["enable_safety_checker"] = enable_safety_checker fal_model = "fal-ai/flux/dev" else: # Flux Schnell arguments["enable_safety_checker"] = enable_safety_checker fal_model = "fal-ai/flux/schnell" if seed != -1: arguments["seed"] = seed try: handler = submit(fal_model, arguments=arguments) result = handler.get() images = [] for img_info in result["images"]: img_url = img_info["url"] img_response = requests.get(img_url) img = Image.open(io.BytesIO(img_response.content)) images.append(img) return images except Exception as e: return [Image.new('RGB', (512, 512), color='black')] def update_visible_components(model): if model == "Flux Pro": return [ gr.update(visible=True, value=28), gr.update(visible=True, value=3.5), gr.update(visible=True, value="2"), gr.update(visible=False) ] elif model == "Flux Dev": return [ gr.update(visible=True, value=28), gr.update(visible=True, value=3.5), gr.update(visible=False), gr.update(visible=True, value=True) ] else: # Flux Schnell return [ gr.update(visible=True, value=4), gr.update(visible=False), gr.update(visible=False), gr.update(visible=True, value=True) ] with gr.Blocks(theme='bethecloud/storj_theme') as demo: gr.HTML("""