Upload folder using huggingface_hub
Browse files- HW.jpeg +0 -0
- README.md +1 -7
- flagged/Upload Low-Resolution Image/4f885062a26d878bf6ae/clipboard.png +0 -0
- flagged/log.csv +2 -0
- low_res_cat.png +0 -0
- main.py +37 -0
- test.py +25 -0
- upscale.png +0 -0
- upscale2.png +0 -0
HW.jpeg
ADDED
README.md
CHANGED
@@ -1,12 +1,6 @@
|
|
1 |
---
|
2 |
title: Upscaler
|
3 |
-
|
4 |
-
colorFrom: gray
|
5 |
-
colorTo: gray
|
6 |
sdk: gradio
|
7 |
sdk_version: 4.41.0
|
8 |
-
app_file: app.py
|
9 |
-
pinned: false
|
10 |
---
|
11 |
-
|
12 |
-
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
1 |
---
|
2 |
title: Upscaler
|
3 |
+
app_file: main.py
|
|
|
|
|
4 |
sdk: gradio
|
5 |
sdk_version: 4.41.0
|
|
|
|
|
6 |
---
|
|
|
|
flagged/Upload Low-Resolution Image/4f885062a26d878bf6ae/clipboard.png
ADDED
flagged/log.csv
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
Upload Low-Resolution Image,Upscaling Prompt,Upscaled Image,flag,username,timestamp
|
2 |
+
flagged\Upload Low-Resolution Image\4f885062a26d878bf6ae\clipboard.png,Car,,,,2024-08-19 14:23:30.400851
|
low_res_cat.png
ADDED
main.py
ADDED
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from PIL import Image
|
3 |
+
from diffusers import StableDiffusionUpscalePipeline
|
4 |
+
import torch
|
5 |
+
import numpy as np
|
6 |
+
|
7 |
+
# Load model and scheduler
|
8 |
+
model_id = "stabilityai/stable-diffusion-x4-upscaler"
|
9 |
+
pipeline = StableDiffusionUpscalePipeline.from_pretrained(model_id, torch_dtype=torch.float16)
|
10 |
+
pipeline = pipeline.to("cuda")
|
11 |
+
|
12 |
+
def upscale_image(image, prompt):
|
13 |
+
# Convert uploaded image to PIL
|
14 |
+
low_res_img = Image.fromarray(image).convert("RGB")
|
15 |
+
|
16 |
+
# Upscale the image
|
17 |
+
upscaled_image = pipeline(prompt=prompt, image=low_res_img).images[0]
|
18 |
+
|
19 |
+
# Convert upscaled PIL image back to numpy array for Gradio
|
20 |
+
upscaled_image_np = np.array(upscaled_image)
|
21 |
+
|
22 |
+
return upscaled_image_np
|
23 |
+
|
24 |
+
# Create the Gradio interface
|
25 |
+
interface = gr.Interface(
|
26 |
+
fn=upscale_image,
|
27 |
+
inputs=[
|
28 |
+
gr.Image(type="numpy", label="Upload Low-Resolution Image"),
|
29 |
+
gr.Textbox(label="Upscaling Prompt", placeholder="Enter a prompt, e.g., 'a red box with glasses'")
|
30 |
+
],
|
31 |
+
outputs=gr.Image(type="numpy", label="Upscaled Image"),
|
32 |
+
title="Image Upscaler",
|
33 |
+
description="Upload a low-resolution image and provide a prompt to upscale it using Stable Diffusion."
|
34 |
+
)
|
35 |
+
|
36 |
+
# Launch the Gradio app
|
37 |
+
interface.launch(share=True)
|
test.py
ADDED
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import requests
|
2 |
+
from PIL import Image
|
3 |
+
from io import BytesIO
|
4 |
+
from diffusers import StableDiffusionUpscalePipeline
|
5 |
+
import torch
|
6 |
+
|
7 |
+
# load model and scheduler
|
8 |
+
model_id = "stabilityai/stable-diffusion-x4-upscaler"
|
9 |
+
pipeline = StableDiffusionUpscalePipeline.from_pretrained(model_id, torch_dtype=torch.float16)
|
10 |
+
pipeline = pipeline.to("cuda")
|
11 |
+
|
12 |
+
# let's download an image
|
13 |
+
url = "https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main/sd2-upscale/low_res_cat.png"
|
14 |
+
response = requests.get(url)
|
15 |
+
low_res_img = Image.open(BytesIO(response.content)).convert("RGB")
|
16 |
+
|
17 |
+
|
18 |
+
low_res_img.save("low_res_cat.png")
|
19 |
+
|
20 |
+
prompt = "a white cat"
|
21 |
+
|
22 |
+
upscaled_image = pipeline(prompt=prompt, image=low_res_img).images[0]
|
23 |
+
upscaled_image.save("upsampled_cat.png")
|
24 |
+
|
25 |
+
|
upscale.png
ADDED
upscale2.png
ADDED