import gradio as gr import gradio.components as gc import torch import numpy as np from diffusers import DiffusionPipeline from huggingface_hub import login, HfApi, HfFolder from PIL import Image import os from datetime import datetime import shutil # Get your Hugging Face API token folder = HfFolder() token = folder.get_token() # Instantiate the Hugging Face API api = HfApi() login(token=os.environ.get('HF_KEY')) device = "cuda" if torch.cuda.is_available() else "cpu" torch.cuda.max_memory_allocated(device=device) pipe1 = DiffusionPipeline.from_pretrained("FFusion/FFusionXL-BASE", torch_dtype=torch.float16, use_safetensors=True) pipe2 = DiffusionPipeline.from_pretrained("stabilityai/stable-diffusion-xl-refiner-1.0", torch_dtype=torch.float16, variant="fp16", use_safetensors=True) pipe1 = pipe1.to(device) pipe1.enable_xformers_memory_efficient_attention() pipe2 = pipe2.to(device) pipe2.enable_xformers_memory_efficient_attention() def save_image_to_hf_space(image_np, image_name): # Name of your Hugging Face repo repo_name = "FFusion/FF2" # Convert the numpy array to an image image = Image.fromarray(image_np.astype('uint8')) # Append a timestamp to the filename timestamp = datetime.now().strftime("%Y%m%d-%H%M%S") image_name_with_timestamp = f"{image_name}-{timestamp}.png" # Save the image locally local_image_path = f"./{image_name_with_timestamp}" image.save(local_image_path) # Upload the image to your Hugging Face repo api.upload_file( token=token, path_or_fileobj=local_image_path, repo_id=repo_name, path_in_repo=image_name_with_timestamp # The path where the image will be stored in the repository ) # Save the image to the persistent storage persistent_storage_path = f"/data/{image_name_with_timestamp}" shutil.copy(local_image_path, persistent_storage_path) article = f"""
ffusionAI-FFusionXL-SDXL-preview

Citation

Please note that the demo is intended solely for academic and research purposes. This demo features the FFusionXL-BASE model developed by FFusion.AI, a division of Source Code Bulgaria Ltd.

Acknowledgement of Original Work and Modifications

This Software is based on the Stable Diffusion XL Base 1.0 model developed by Stability AI Ltd. FFusion AI and Source Code Bulgaria Ltd. have made modifications and enhancements to the original Software for the creation of the FFusionXL-BASE model...

Warning and Compliance

All images and content generated through this demo are logged in a Hugging Face repository, and we actively monitor for violations of these terms. Any use of the demo for generating inappropriate or unlawful content is strictly prohibited...

License

SDXL 0.9 Research License

FFXL 0.9 Research License

""" # Create the Gradio interface gr.Interface(fn=genie, inputs=[gr.Textbox(label='Describe your FFusion idea. 77 Token Limit.', lines=2), gr.Textbox(label='Things the AI should not create (negative prompt)', lines=2), gr.Slider(1, 15, 10), gr.Slider(25, maximum=100, value=50, step=1), gr.Slider(minimum=1, step=1, maximum=999999999999999999, randomize=True)], outputs=[gc.Image(type='numpy', label="FFusionXL Base Image"), gc.Image(type='numpy', label="Refined Image")], title="FFusionXL Base - Generate and Refine", description='
FFusionXL-BASE-SDXL
', article=article, css=""" .gr-textbox { width: 100%; } .gr-image { max-width: 50%; display: inline-block; } """ ).launch(debug=True, max_threads=10)