from PIL import Image import gradio as gr from diffusers import LDMSuperResolutionPipeline import torch import keras model_id = "CompVis/ldm-super-resolution-4x-openimages" # load model and scheduler pipeline = LDMSuperResolutionPipeline.from_pretrained(model_id) #pipeline = pipeline.to(device) # let's download an image #url = "https://user-images.githubusercontent.com/38061659/199705896-b48e17b8-b231-47cd-a270-4ffa5a93fa3e.png" #response = requests.get(url) def infer(original_image): #low_res_img = Image.open(BytesIO(response.content)).convert("RGB") image = keras.utils.img_to_array(original_image) image = image.astype("float32") / 255.0 image = np.expand_dims(image, axis=0) # run pipeline in inference (sample random noise and denoise) upscaled_image = pipeline(image, num_inference_steps=100, eta=1).images[0] return upscaled_image # save image #upscaled_image.save("ldm_generated_image.png") iface = gr.Interface( fn=infer, title="Enhancement Resolution", description = "OpenCV implementation of Enhancement Resolution 🌆🎆", inputs=[gr.inputs.Image(label="image", type="pil")], outputs="image", examples=examples, cache_examples=True, article = "Authors: Vivek Narayan, Chiranjan,Srujan,Rohan Pawar,Pavan Karthik").launch(enable_queue=True)