Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,17 +1,15 @@
|
|
1 |
-
import os
|
2 |
import gradio as gr
|
3 |
from diffusers import StableDiffusionUpscalePipeline
|
4 |
from diffusers.utils import load_image
|
5 |
import torch
|
6 |
from PIL import Image
|
7 |
import base64
|
8 |
-
import requests
|
9 |
from io import BytesIO
|
10 |
|
11 |
# Load model and scheduler
|
12 |
model_id = "stabilityai/stable-diffusion-x4-upscaler"
|
13 |
-
pipeline = StableDiffusionUpscalePipeline.from_pretrained(model_id
|
14 |
-
pipeline = pipeline.to("
|
15 |
|
16 |
def upscale_image(image, prompt):
|
17 |
image = image.resize((128, 128)) # Resize to the expected input size
|
@@ -27,10 +25,10 @@ def base64_to_image(base64_str):
|
|
27 |
image_data = base64.b64decode(base64_str)
|
28 |
return Image.open(BytesIO(image_data))
|
29 |
|
30 |
-
def
|
31 |
-
prompt = "a white cat"
|
32 |
upscaled_image = upscale_image(image, prompt)
|
33 |
-
|
|
|
34 |
|
35 |
def main():
|
36 |
with gr.Blocks() as demo:
|
@@ -45,11 +43,6 @@ def main():
|
|
45 |
base64_output = gr.Textbox(label="Base64 Encoded Image")
|
46 |
upscaled_image_output = gr.Image(type="pil", label="Upscaled Image")
|
47 |
|
48 |
-
def handle_upload(image, prompt):
|
49 |
-
upscaled_image = upscale_image(image, prompt)
|
50 |
-
base64_str = image_to_base64(upscaled_image)
|
51 |
-
return base64_str, upscaled_image
|
52 |
-
|
53 |
upload_btn.click(fn=handle_upload, inputs=[image_input, prompt_input], outputs=[base64_output, upscaled_image_output])
|
54 |
|
55 |
demo.launch()
|
|
|
|
|
1 |
import gradio as gr
|
2 |
from diffusers import StableDiffusionUpscalePipeline
|
3 |
from diffusers.utils import load_image
|
4 |
import torch
|
5 |
from PIL import Image
|
6 |
import base64
|
|
|
7 |
from io import BytesIO
|
8 |
|
9 |
# Load model and scheduler
|
10 |
model_id = "stabilityai/stable-diffusion-x4-upscaler"
|
11 |
+
pipeline = StableDiffusionUpscalePipeline.from_pretrained(model_id)
|
12 |
+
pipeline = pipeline.to("cpu") # Use CPU instead of GPU
|
13 |
|
14 |
def upscale_image(image, prompt):
|
15 |
image = image.resize((128, 128)) # Resize to the expected input size
|
|
|
25 |
image_data = base64.b64decode(base64_str)
|
26 |
return Image.open(BytesIO(image_data))
|
27 |
|
28 |
+
def handle_upload(image, prompt):
|
|
|
29 |
upscaled_image = upscale_image(image, prompt)
|
30 |
+
base64_str = image_to_base64(upscaled_image)
|
31 |
+
return base64_str, upscaled_image
|
32 |
|
33 |
def main():
|
34 |
with gr.Blocks() as demo:
|
|
|
43 |
base64_output = gr.Textbox(label="Base64 Encoded Image")
|
44 |
upscaled_image_output = gr.Image(type="pil", label="Upscaled Image")
|
45 |
|
|
|
|
|
|
|
|
|
|
|
46 |
upload_btn.click(fn=handle_upload, inputs=[image_input, prompt_input], outputs=[base64_output, upscaled_image_output])
|
47 |
|
48 |
demo.launch()
|