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"""
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.
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...
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...