Instructions to use antonellaavad/https-huggingface-co-iyashi-haku-naruto with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Diffusers
How to use antonellaavad/https-huggingface-co-iyashi-haku-naruto with Diffusers:
pip install -U diffusers transformers accelerate
import torch from diffusers import DiffusionPipeline # switch to "mps" for apple devices pipe = DiffusionPipeline.from_pretrained("andite/pastel-mix", dtype=torch.bfloat16, device_map="cuda") pipe.load_lora_weights("antonellaavad/https-huggingface-co-iyashi-haku-naruto") prompt = "haku(naruto), haku, female, woman, girl, 1 girl, flat breasts, black eyes, brown eyes, mask, anbu mask, white and red mask, white mask, red mask, holding mask, headband, solid steel headband, symbol headband, white hair bun, hair bun, black hair, long hair, needles, holding needles, solid steel needles, steel needles, kimono, teal kimono, battlesuit, brown battlesuit, long sleeves, tassel" image = pipe(prompt).images[0] - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- Draw Things
- DiffusionBee
Create app.py
#2
by ShriVidyaAyushi - opened
app.py
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# app.py — Verified Hugging Face Space Code (CPU/GPU Safe)
|
| 2 |
+
|
| 3 |
+
import gradio as gr
|
| 4 |
+
from diffusers import StableDiffusionPipeline
|
| 5 |
+
import torch
|
| 6 |
+
from PIL import Image
|
| 7 |
+
import traceback
|
| 8 |
+
|
| 9 |
+
# ------------------ CONFIG ------------------
|
| 10 |
+
MODEL_ID = "runwayml/stable-diffusion-v1-5"
|
| 11 |
+
|
| 12 |
+
# ------------------ SAFE MODEL LOAD ------------------
|
| 13 |
+
try:
|
| 14 |
+
device = "cuda" if torch.cuda.is_available() else "cpu"
|
| 15 |
+
dtype = torch.float16 if torch.cuda.is_available() else torch.float32
|
| 16 |
+
|
| 17 |
+
pipe = StableDiffusionPipeline.from_pretrained(
|
| 18 |
+
MODEL_ID,
|
| 19 |
+
torch_dtype=dtype,
|
| 20 |
+
safety_checker=None
|
| 21 |
+
).to(device)
|
| 22 |
+
|
| 23 |
+
except Exception as e:
|
| 24 |
+
print("❌ Model Loading Error:")
|
| 25 |
+
traceback.print_exc()
|
| 26 |
+
pipe = None
|
| 27 |
+
|
| 28 |
+
# ------------------ GENERATION FUNCTION ------------------
|
| 29 |
+
def generate_image(prompt):
|
| 30 |
+
if pipe is None:
|
| 31 |
+
return "⚠️ Model not loaded properly. Please check logs."
|
| 32 |
+
try:
|
| 33 |
+
result = pipe(prompt)
|
| 34 |
+
image = result.images[0]
|
| 35 |
+
return image
|
| 36 |
+
except Exception as e:
|
| 37 |
+
print("❌ Generation Error:", e)
|
| 38 |
+
return "⚠️ Error generating image."
|
| 39 |
+
|
| 40 |
+
# ------------------ GRADIO UI ------------------
|
| 41 |
+
title = "🪷 Shrividya Text-to-Image AI"
|
| 42 |
+
description = "Generate stunning images from your text prompts using Stable Diffusion."
|
| 43 |
+
|
| 44 |
+
iface = gr.Interface(
|
| 45 |
+
fn=generate_image,
|
| 46 |
+
inputs=gr.Textbox(label="Enter your prompt", placeholder="e.g. Divine temple on riverbank at sunset"),
|
| 47 |
+
outputs=gr.Image(label="Generated Image"),
|
| 48 |
+
title=title,
|
| 49 |
+
description=description,
|
| 50 |
+
allow_flagging="never"
|
| 51 |
+
)
|
| 52 |
+
|
| 53 |
+
if __name__ == "__main__":
|
| 54 |
+
iface.launch()
|