Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -39,11 +39,27 @@ model.renderer.set_chunk_size(131072)
|
|
| 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:
|
| 45 |
raise gr.Error("No image uploaded!")
|
| 46 |
|
|
|
|
| 47 |
def preprocess(input_image, do_remove_background, foreground_ratio):
|
| 48 |
def fill_background(image):
|
| 49 |
image = np.array(image).astype(np.float32) / 255.0
|
|
@@ -62,6 +78,7 @@ def preprocess(input_image, do_remove_background, foreground_ratio):
|
|
| 62 |
image = fill_background(image)
|
| 63 |
return image
|
| 64 |
|
|
|
|
| 65 |
@spaces.GPU
|
| 66 |
def generate(image, mc_resolution, formats=["obj", "glb"]):
|
| 67 |
scene_codes = model(image, device=device)
|
|
@@ -77,19 +94,11 @@ def generate(image, mc_resolution, formats=["obj", "glb"]):
|
|
| 77 |
|
| 78 |
return mesh_path_obj.name, mesh_path_glb.name
|
| 79 |
|
| 80 |
-
def run_example(
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
# Step 2: Preprocess the image
|
| 85 |
-
preprocessed = preprocess(image_pil, do_remove_background, foreground_ratio)
|
| 86 |
-
|
| 87 |
-
# Step 3: Generate the 3D model
|
| 88 |
-
mesh_name_obj, mesh_name_glb = generate(preprocessed, mc_resolution, ["obj", "glb"])
|
| 89 |
-
|
| 90 |
return preprocessed, mesh_name_obj, mesh_name_glb
|
| 91 |
|
| 92 |
-
|
| 93 |
with gr.Blocks() as demo:
|
| 94 |
gr.Markdown(HEADER)
|
| 95 |
with gr.Row(variant="panel"):
|
|
|
|
| 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:
|
| 60 |
raise gr.Error("No image uploaded!")
|
| 61 |
|
| 62 |
+
|
| 63 |
def preprocess(input_image, do_remove_background, foreground_ratio):
|
| 64 |
def fill_background(image):
|
| 65 |
image = np.array(image).astype(np.float32) / 255.0
|
|
|
|
| 78 |
image = fill_background(image)
|
| 79 |
return image
|
| 80 |
|
| 81 |
+
|
| 82 |
@spaces.GPU
|
| 83 |
def generate(image, mc_resolution, formats=["obj", "glb"]):
|
| 84 |
scene_codes = model(image, device=device)
|
|
|
|
| 94 |
|
| 95 |
return mesh_path_obj.name, mesh_path_glb.name
|
| 96 |
|
| 97 |
+
def run_example(image_pil):
|
| 98 |
+
preprocessed = preprocess(image_pil, False, 0.9)
|
| 99 |
+
mesh_name_obj, mesh_name_glb = generate(preprocessed, 256, ["obj", "glb"])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 100 |
return preprocessed, mesh_name_obj, mesh_name_glb
|
| 101 |
|
|
|
|
| 102 |
with gr.Blocks() as demo:
|
| 103 |
gr.Markdown(HEADER)
|
| 104 |
with gr.Row(variant="panel"):
|