salehalmansour's picture
Update app.py
0adca5e verified
raw
history blame
1.08 kB
import torch
import gradio as gr
from diffusers import StableDiffusionPipeline
class CFG:
device = 'cpu'
seed = 42
Generator = torch.Generator(device).manual_seed(seed)
image_gen_steps = 35
image_gen_model_id = 'stabilityai/stable-diffusion-2'
image_gen_size = (400, 400)
image_gen_guidance_scale = 9
image_gen_model = StableDiffusionPipeline.from_pretrained(
CFG.image_gen_model_id, torch_dtype=torch.float32,
revision="fp16", use_auth_token='hf_pxvzpoafqjfkELFKMLTESNpvmyvkTVuD01' , guidance_scale=9
)
apply = image_gen_model.to(CFG.device)
def generate_image(prompt):
image = apply(
prompt, num_inference_steps=CFG.image_gen_steps,
generator=CFG.generator ,
guidance_scale=CFG.image_gen_guidance_scale
).image[0]
image = image.resize(CFG.image_gen_size)
return image
)
title = "ุชุตูˆู‘ูŽุฑ"
description = "ุฃุฏุฎู„ ู†ุต ู†ุญูˆู„ู‡ุง ู„ูƒ ุตูˆุฑู‡"
iface = gr.interface(fn=generate_image, inputs = "text", outputs = "image" , title= title , description=description)
iface.launch(
)