Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
@@ -20,36 +20,34 @@ pipe = StableDiffusionPipeline.from_pretrained(
|
|
20 |
pipe = pipe.to(device)
|
21 |
|
22 |
def text_to_image(summary, image_name):
|
23 |
-
|
24 |
-
#
|
25 |
s3 = boto3.client('s3',
|
26 |
-
|
27 |
-
|
28 |
|
29 |
image_name = '-'.join(image_name.split()) + ".webp"
|
30 |
-
|
31 |
def save_image_to_s3(image):
|
32 |
-
#
|
33 |
image_buffer = BytesIO()
|
34 |
image.save(image_buffer, format='WEBP')
|
35 |
image_buffer.seek(0)
|
36 |
-
|
37 |
-
#
|
38 |
s3_key = "public/" + image_name
|
39 |
-
|
40 |
-
#
|
41 |
s3.upload_fileobj(image_buffer, S3_BUCKET_NAME, s3_key)
|
42 |
-
|
43 |
def generator_image(summary):
|
44 |
prompt = summary
|
45 |
image = pipe(prompt).images[0]
|
46 |
-
|
47 |
-
#
|
48 |
save_image_to_s3(image)
|
49 |
-
|
50 |
-
# generate image
|
51 |
generator_image(summary)
|
52 |
-
|
53 |
return image_name
|
54 |
|
55 |
|
|
|
20 |
pipe = pipe.to(device)
|
21 |
|
22 |
def text_to_image(summary, image_name):
|
23 |
+
|
24 |
+
# Create an instance of the S3 client
|
25 |
s3 = boto3.client('s3',
|
26 |
+
aws_access_key_id=AWS_ACCESS_KEY_ID,
|
27 |
+
aws_secret_access_key=AWS_SECRET_ACCESS_KEY)
|
28 |
|
29 |
image_name = '-'.join(image_name.split()) + ".webp"
|
30 |
+
|
31 |
def save_image_to_s3(image):
|
32 |
+
# Create a BytesIO object to store the image.
|
33 |
image_buffer = BytesIO()
|
34 |
image.save(image_buffer, format='WEBP')
|
35 |
image_buffer.seek(0)
|
36 |
+
|
37 |
+
# Full path of the file in the bucket
|
38 |
s3_key = "public/" + image_name
|
39 |
+
|
40 |
+
# Upload the image to the S3 bucket
|
41 |
s3.upload_fileobj(image_buffer, S3_BUCKET_NAME, s3_key)
|
42 |
+
|
43 |
def generator_image(summary):
|
44 |
prompt = summary
|
45 |
image = pipe(prompt).images[0]
|
46 |
+
|
47 |
+
# Save the image in S3
|
48 |
save_image_to_s3(image)
|
49 |
+
|
|
|
50 |
generator_image(summary)
|
|
|
51 |
return image_name
|
52 |
|
53 |
|