Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -39,21 +39,6 @@ model.renderer.set_chunk_size(131072)
|
|
| 39 |
model.to(device)
|
| 40 |
|
| 41 |
rembg_session = rembg.new_session()
|
| 42 |
-
my_aws_access_key_id = os.getenv("ACCESS")
|
| 43 |
-
my_aws_secret_access_key = os.getenv("SECRET")
|
| 44 |
-
bedrock_runtime = boto3.client(service_name='bedrock-runtime', aws_access_key_id = my_aws_access_key_id, aws_secret_access_key = my_aws_secret_access_key, region_name='us-east-1')
|
| 45 |
-
|
| 46 |
-
def generate_image_from_text(pos_prompt):
|
| 47 |
-
# bedrock_runtime = boto3.client(region_name = 'us-east-1', service_name='bedrock-runtime')
|
| 48 |
-
parameters = {'text_prompts': [{'text': pos_prompt , 'weight':1},
|
| 49 |
-
{'text': """Blurry, out of frame, out of focus, Detailed, dull, duplicate, bad quality, low resolution, cropped""", 'weight': -1}],
|
| 50 |
-
'cfg_scale': 7, 'seed': 0, 'samples': 1}
|
| 51 |
-
request_body = json.dumps(parameters)
|
| 52 |
-
response = bedrock_runtime.invoke_model(body=request_body,modelId = 'stability.stable-diffusion-xl-v1')
|
| 53 |
-
response_body = json.loads(response.get('body').read())
|
| 54 |
-
base64_image_data = base64.b64decode(response_body['artifacts'][0]['base64'])
|
| 55 |
-
|
| 56 |
-
return Image.open(io.BytesIO(base64_image_data))
|
| 57 |
|
| 58 |
def check_input_image(input_image):
|
| 59 |
if input_image is None:
|
|
@@ -109,10 +94,10 @@ with gr.Blocks() as demo:
|
|
| 109 |
with gr.Row(variant="panel"):
|
| 110 |
with gr.Column():
|
| 111 |
with gr.Row():
|
| 112 |
-
text_prompt = gr.Textbox(
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
)
|
| 116 |
input_image = gr.Image(
|
| 117 |
label="Generated Image",
|
| 118 |
image_mode="RGBA",
|
|
@@ -156,21 +141,21 @@ with gr.Blocks() as demo:
|
|
| 156 |
interactive=False,
|
| 157 |
)
|
| 158 |
gr.Markdown("Note: The model shown here has a darker appearance. Download to get correct results.")
|
| 159 |
-
|
| 160 |
-
|
| 161 |
-
|
| 162 |
-
|
| 163 |
-
|
| 164 |
-
|
| 165 |
-
|
| 166 |
-
|
| 167 |
-
|
| 168 |
-
|
| 169 |
-
|
| 170 |
-
|
| 171 |
submit.click(fn=check_input_image, inputs=[text_prompt]).success(
|
| 172 |
fn=run_example,
|
| 173 |
-
inputs=[
|
| 174 |
outputs=[processed_image, output_model_obj, output_model_glb],
|
| 175 |
)
|
| 176 |
|
|
|
|
| 39 |
model.to(device)
|
| 40 |
|
| 41 |
rembg_session = rembg.new_session()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 42 |
|
| 43 |
def check_input_image(input_image):
|
| 44 |
if input_image is None:
|
|
|
|
| 94 |
with gr.Row(variant="panel"):
|
| 95 |
with gr.Column():
|
| 96 |
with gr.Row():
|
| 97 |
+
# text_prompt = gr.Textbox(
|
| 98 |
+
# label="Text Prompt",
|
| 99 |
+
# placeholder="Enter a text prompt for image generation"
|
| 100 |
+
# )
|
| 101 |
input_image = gr.Image(
|
| 102 |
label="Generated Image",
|
| 103 |
image_mode="RGBA",
|
|
|
|
| 141 |
interactive=False,
|
| 142 |
)
|
| 143 |
gr.Markdown("Note: The model shown here has a darker appearance. Download to get correct results.")
|
| 144 |
+
with gr.Row(variant="panel"):
|
| 145 |
+
gr.Examples(
|
| 146 |
+
examples=[
|
| 147 |
+
os.path.join("examples", img_name) for img_name in sorted(os.listdir("examples"))
|
| 148 |
+
],
|
| 149 |
+
inputs=[text_prompt],
|
| 150 |
+
outputs=[processed_image, output_model_obj, output_model_glb],
|
| 151 |
+
cache_examples=True,
|
| 152 |
+
fn=partial(run_example, do_remove_background=True, foreground_ratio=0.85, mc_resolution=256),
|
| 153 |
+
label="Examples",
|
| 154 |
+
examples_per_page=20
|
| 155 |
+
)
|
| 156 |
submit.click(fn=check_input_image, inputs=[text_prompt]).success(
|
| 157 |
fn=run_example,
|
| 158 |
+
inputs=[input_image, do_remove_background, foreground_ratio, mc_resolution],
|
| 159 |
outputs=[processed_image, output_model_obj, output_model_glb],
|
| 160 |
)
|
| 161 |
|