Spaces:
Runtime error
Runtime error
viveknarayan
commited on
Commit
β’
fcc9852
1
Parent(s):
86a51f6
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
!pip install git+https://github.com/huggingface/diffusers.git
|
2 |
+
from PIL import Image
|
3 |
+
import gradio as gr
|
4 |
+
from diffusers import LDMSuperResolutionPipeline
|
5 |
+
import torch
|
6 |
+
import keras
|
7 |
+
|
8 |
+
model_id = "CompVis/ldm-super-resolution-4x-openimages"
|
9 |
+
|
10 |
+
# load model and scheduler
|
11 |
+
pipeline = LDMSuperResolutionPipeline.from_pretrained(model_id)
|
12 |
+
#pipeline = pipeline.to(device)
|
13 |
+
|
14 |
+
# let's download an image
|
15 |
+
#url = "https://user-images.githubusercontent.com/38061659/199705896-b48e17b8-b231-47cd-a270-4ffa5a93fa3e.png"
|
16 |
+
#response = requests.get(url)
|
17 |
+
def infer(original_image):
|
18 |
+
#low_res_img = Image.open(BytesIO(response.content)).convert("RGB")
|
19 |
+
image = keras.utils.img_to_array(original_image)
|
20 |
+
image = image.astype("float32") / 255.0
|
21 |
+
image = np.expand_dims(image, axis=0)
|
22 |
+
# run pipeline in inference (sample random noise and denoise)
|
23 |
+
upscaled_image = pipeline(image, num_inference_steps=100, eta=1).images[0]
|
24 |
+
return upscaled_image
|
25 |
+
# save image
|
26 |
+
#upscaled_image.save("ldm_generated_image.png")
|
27 |
+
iface = gr.Interface(
|
28 |
+
fn=infer,
|
29 |
+
title="Enhancement Resolution",
|
30 |
+
description = "OpenCV implementation of Enhancement Resolution ππ",
|
31 |
+
inputs=[gr.inputs.Image(label="image", type="pil")],
|
32 |
+
outputs="image",
|
33 |
+
examples=examples,
|
34 |
+
cache_examples=True,
|
35 |
+
article = "Authors: <a href=\"https://github.com/Uviveknarayan\">Vivek Narayan</a>, <a href=\"https://github.com/chiranjan-7\">Chiranjan</a>,<a href=\"https://github.com/GangaSrujan\">Srujan</a>,<a href=\"https://github.com/RohanPawar3399\">Rohan Pawar</a>,<a href=\"https://github.com/pavankarthik77\">Pavan Karthik</a>").launch(enable_queue=True)
|