Spaces:
Sleeping
Sleeping
Remove unused code
Browse files
app.py
CHANGED
|
@@ -26,10 +26,7 @@ model_id = "sd-legacy/stable-diffusion-v1-5"
|
|
| 26 |
scheduler = EulerDiscreteScheduler.from_pretrained(model_id, subfolder="scheduler")
|
| 27 |
|
| 28 |
# Load the image-to-text pipeline with BLIP model
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
# Text-to-image endpoint
|
| 32 |
-
#get_tti_completion = pipeline("text-to-image", model="stabilityai/stable-diffusion-xl-base-1.0")
|
| 33 |
|
| 34 |
# Load the Stable Diffusion pipeline
|
| 35 |
pipe = StableDiffusionPipeline.from_pretrained(
|
|
@@ -40,39 +37,24 @@ pipe = StableDiffusionPipeline.from_pretrained(
|
|
| 40 |
)
|
| 41 |
pipe = pipe.to(device)
|
| 42 |
|
| 43 |
-
|
| 44 |
-
# Bringing the functions from lessons 3 and 4!
|
| 45 |
-
def image_to_base64_str(pil_image):
|
| 46 |
-
byte_arr = io.BytesIO()
|
| 47 |
-
pil_image.save(byte_arr, format='PNG')
|
| 48 |
-
byte_arr = byte_arr.getvalue()
|
| 49 |
-
return str(base64.b64encode(byte_arr).decode('utf-8'))
|
| 50 |
-
|
| 51 |
-
def base64_to_pil(img_base64):
|
| 52 |
-
base64_decoded = base64.b64decode(img_base64)
|
| 53 |
-
byte_stream = io.BytesIO(base64_decoded)
|
| 54 |
-
pil_image = Image.open(byte_stream)
|
| 55 |
-
return pil_image
|
| 56 |
-
|
| 57 |
# Caption generate function
|
| 58 |
-
@spaces.GPU # Designed to be effect-free in non-ZeroGPU environments, ensuring compatibility across different setups.
|
| 59 |
def captioner(image):
|
| 60 |
-
#base64_image = image_to_base64_str(image)
|
| 61 |
# The BLIP model expects a PIL image directly
|
| 62 |
-
result =
|
| 63 |
-
#result = get_completion(base64_image, None, ITT_ENDPOINT)
|
| 64 |
|
| 65 |
return result[0]['generated_text']
|
| 66 |
|
| 67 |
# Image generate function
|
| 68 |
-
@spaces.GPU # Designed to be effect-free in non-ZeroGPU environments, ensuring compatibility across different setups.
|
| 69 |
def generate(prompt, steps):
|
| 70 |
-
# Generate image with Stable Diffusion
|
| 71 |
output = pipe(
|
| 72 |
prompt,
|
| 73 |
negative_prompt=None, # Handle empty negative prompt
|
| 74 |
num_inference_steps=25,
|
| 75 |
)
|
|
|
|
| 76 |
return output.images[0] # Return the first generated image (PIL format)
|
| 77 |
|
| 78 |
|
|
|
|
| 26 |
scheduler = EulerDiscreteScheduler.from_pretrained(model_id, subfolder="scheduler")
|
| 27 |
|
| 28 |
# Load the image-to-text pipeline with BLIP model
|
| 29 |
+
get_completion = pipeline("image-to-text", model="Salesforce/blip-image-captioning-base")
|
|
|
|
|
|
|
|
|
|
| 30 |
|
| 31 |
# Load the Stable Diffusion pipeline
|
| 32 |
pipe = StableDiffusionPipeline.from_pretrained(
|
|
|
|
| 37 |
)
|
| 38 |
pipe = pipe.to(device)
|
| 39 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 40 |
# Caption generate function
|
| 41 |
+
@spaces.GPU(duration=120) # Designed to be effect-free in non-ZeroGPU environments, ensuring compatibility across different setups.
|
| 42 |
def captioner(image):
|
|
|
|
| 43 |
# The BLIP model expects a PIL image directly
|
| 44 |
+
result = get_completion(image)
|
|
|
|
| 45 |
|
| 46 |
return result[0]['generated_text']
|
| 47 |
|
| 48 |
# Image generate function
|
| 49 |
+
@spaces.GPU(duration=120) # Designed to be effect-free in non-ZeroGPU environments, ensuring compatibility across different setups.
|
| 50 |
def generate(prompt, steps):
|
| 51 |
+
# Generate an image with Stable Diffusion
|
| 52 |
output = pipe(
|
| 53 |
prompt,
|
| 54 |
negative_prompt=None, # Handle empty negative prompt
|
| 55 |
num_inference_steps=25,
|
| 56 |
)
|
| 57 |
+
|
| 58 |
return output.images[0] # Return the first generated image (PIL format)
|
| 59 |
|
| 60 |
|