Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,14 +1,13 @@
|
|
1 |
import gradio as gr
|
2 |
import numpy as np
|
3 |
import random
|
4 |
-
import spaces
|
5 |
import torch
|
6 |
-
from diffusers import DiffusionPipeline
|
7 |
from transformers import CLIPTextModel, CLIPTokenizer, T5EncoderModel, T5TokenizerFast
|
8 |
import boto3
|
9 |
-
import os
|
10 |
from io import BytesIO
|
11 |
import time
|
|
|
12 |
|
13 |
# S3 Configuration
|
14 |
S3_BUCKET = "afri"
|
@@ -29,22 +28,17 @@ MAX_SEED = np.iinfo(np.int32).max
|
|
29 |
MAX_IMAGE_SIZE = 2048
|
30 |
|
31 |
def save_image_to_s3(image):
|
32 |
-
# Convert PIL Image to bytes
|
33 |
img_byte_arr = BytesIO()
|
34 |
image.save(img_byte_arr, format='PNG')
|
35 |
img_byte_arr = img_byte_arr.getvalue()
|
36 |
|
37 |
-
# Generate a unique filename
|
38 |
filename = f"generated_image_{int(time.time())}.png"
|
39 |
|
40 |
-
# Upload to S3
|
41 |
s3_client.put_object(Bucket=S3_BUCKET,
|
42 |
Key=filename,
|
43 |
Body=img_byte_arr,
|
44 |
-
ContentType='image/png'
|
45 |
-
ACL='public-read')
|
46 |
|
47 |
-
# Generate a public URL
|
48 |
url = f"https://{S3_BUCKET}.s3.{S3_REGION}.amazonaws.com/{filename}"
|
49 |
return url
|
50 |
|
@@ -61,7 +55,6 @@ def infer(prompt, seed=42, randomize_seed=False, width=1024, height=1024, guidan
|
|
61 |
guidance_scale=guidance_scale
|
62 |
).images[0]
|
63 |
|
64 |
-
# Save image to S3 and get URL
|
65 |
image_url = save_image_to_s3(image)
|
66 |
|
67 |
return image_url, seed
|
@@ -152,4 +145,4 @@ with gr.Blocks(css=css) as demo:
|
|
152 |
outputs=[result, seed]
|
153 |
)
|
154 |
|
155 |
-
demo.launch()
|
|
|
1 |
import gradio as gr
|
2 |
import numpy as np
|
3 |
import random
|
|
|
4 |
import torch
|
5 |
+
from diffusers import DiffusionPipeline
|
6 |
from transformers import CLIPTextModel, CLIPTokenizer, T5EncoderModel, T5TokenizerFast
|
7 |
import boto3
|
|
|
8 |
from io import BytesIO
|
9 |
import time
|
10 |
+
import os
|
11 |
|
12 |
# S3 Configuration
|
13 |
S3_BUCKET = "afri"
|
|
|
28 |
MAX_IMAGE_SIZE = 2048
|
29 |
|
30 |
def save_image_to_s3(image):
|
|
|
31 |
img_byte_arr = BytesIO()
|
32 |
image.save(img_byte_arr, format='PNG')
|
33 |
img_byte_arr = img_byte_arr.getvalue()
|
34 |
|
|
|
35 |
filename = f"generated_image_{int(time.time())}.png"
|
36 |
|
|
|
37 |
s3_client.put_object(Bucket=S3_BUCKET,
|
38 |
Key=filename,
|
39 |
Body=img_byte_arr,
|
40 |
+
ContentType='image/png')
|
|
|
41 |
|
|
|
42 |
url = f"https://{S3_BUCKET}.s3.{S3_REGION}.amazonaws.com/{filename}"
|
43 |
return url
|
44 |
|
|
|
55 |
guidance_scale=guidance_scale
|
56 |
).images[0]
|
57 |
|
|
|
58 |
image_url = save_image_to_s3(image)
|
59 |
|
60 |
return image_url, seed
|
|
|
145 |
outputs=[result, seed]
|
146 |
)
|
147 |
|
148 |
+
demo.launch(share=True)
|