|
import gradio as gr |
|
from diffusers import StableDiffusionPipeline |
|
import torch |
|
|
|
|
|
model_id = "runwayml/stable-diffusion-v1-5" |
|
|
|
|
|
pipe = StableDiffusionPipeline.from_pretrained(model_id) |
|
pipe = pipe.to("cpu") |
|
pipe.enable_attention_slicing() |
|
|
|
|
|
def text2image(prompt): |
|
try: |
|
|
|
image = pipe(prompt, guidance_scale=9.5, num_inference_steps=35).images[0] |
|
return image |
|
except Exception as e: |
|
return f"Error: {str(e)}" |
|
|
|
|
|
iface = gr.Interface( |
|
fn=text2image, |
|
inputs=gr.Textbox(label="Prompt", placeholder="مثلا: a realistic portrait of a young woman"), |
|
outputs="image", |
|
title="Realistic Text-to-Image (CPU Friendly)", |
|
description="یک تصویر واقعی از متن شما تولید میکند. رزولوشن متوسط و مناسب CPU." |
|
) |
|
|
|
iface.launch() |