Spaces:
Sleeping
Sleeping
import gradio as gr | |
import torch | |
import requests | |
from torchvision import transforms | |
from diffusers import StableDiffusionPipeline, DPMSolverMultistepScheduler, EulerDiscreteScheduler | |
model = torch.hub.load("pytorch/vision:v0.6.0", "resnet18", pretrained=True).eval() | |
response = requests.get("https://git.io/JJkYN") | |
labels = response.text.split("\n") | |
def generate(inp): | |
torch.cuda.empty_cache() | |
print(f"Is CUDA available: {torch.cuda.is_available()}") | |
pipeline = StableDiffusionPipeline.from_pretrained("stabilityai/stable-diffusion-2-1", torch_dtype=torch.float16) | |
#pipeline.scheduler = DPMSolverMultistepScheduler.from_config(pipeline.scheduler.config) | |
#another comment | |
pipeline.scheduler = EulerDiscreteScheduler.from_config(pipeline.scheduler.config) | |
pipeline = pipeline.to("cuda") | |
image = pipeline(inp, height=512, width=512).images[0] | |
return image | |
def run(): | |
demo = gr.Interface( | |
fn=generate, | |
inputs=gr.inputs.Textbox(label="Prompt"), | |
outputs=gr.outputs.Image(type="pil"), | |
) | |
demo.launch(server_name="0.0.0.0", server_port=7860) | |
if __name__ == "__main__": | |
run() |