File size: 1,094 Bytes
feabc9a d985a28 feabc9a 5120226 feabc9a 5120226 feabc9a 8f305a1 |
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 |
from diffusers import StableDiffusionPipeline
import torch
import os
from huggingface_hub import login
# Retrieve the token from the environment variable
token = os.getenv("HF_TOKEN") # Hugging Face token from the secret
if token:
login(token=token) # Log in with the retrieved token
else:
raise ValueError("Hugging Face token not found. Please set it as a repository secret in the Space settings.")
# Load the Stable Diffusion 3.5 model
model_id = "stabilityai/stable-diffusion-3.5"
pipe = StableDiffusionPipeline.from_pretrained(model_id, torch_dtype=torch.float16)
pipe.to("cuda")
# Define the path to the LoRA model (since it's in the main directory)
lora_model_path = "lora_model.pth" # Path to the uploaded LoRA model
# Load the LoRA model weights into the pipeline
pipe.load_lora_model(lora_model_path) # Integrate the LoRA weights
# Function to generate an image from a text prompt
def generate_image(prompt):
image = pipe(prompt).images[0]
return image
import gradio as gr
iface = gr.Interface(fn=generate_image, inputs="text", outputs="image")
iface.launch() |