vibs08 commited on
Commit
5c828ac
·
verified ·
1 Parent(s): e2e5798

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +27 -37
app.py CHANGED
@@ -23,17 +23,13 @@ from io import BytesIO
23
  from botocore.exceptions import NoCredentialsError, PartialCredentialsError
24
  import datetime
25
 
26
-
27
-
28
  app = FastAPI()
29
 
30
-
31
  subprocess.run(shlex.split('pip install wheel/torchmcubes-0.1.0-cp310-cp310-linux_x86_64.whl'))
32
 
33
  from tsr.system import TSR
34
  from tsr.utils import remove_background, resize_foreground, to_gradio_3d_orientation
35
 
36
- # os.environ["CUDA_VISIBLE_DEVICES"] = "1"
37
 
38
  HEADER = """FRAME AI"""
39
 
@@ -57,17 +53,6 @@ ACCESS = os.getenv("ACCESS")
57
  SECRET = os.getenv("SECRET")
58
  bedrock = boto3.client(service_name='bedrock', aws_access_key_id = ACCESS, aws_secret_access_key = SECRET, region_name='us-east-1')
59
  bedrock_runtime = boto3.client(service_name='bedrock-runtime', aws_access_key_id = ACCESS, aws_secret_access_key = SECRET, region_name='us-east-1')
60
- # def generate_image_from_text(pos_prompt):
61
- # # bedrock_runtime = boto3.client(region_name = 'us-east-1', service_name='bedrock-runtime')
62
- # parameters = {'text_prompts': [{'text': pos_prompt , 'weight':1},
63
- # {'text': """Blurry, out of frame, out of focus, Detailed, dull, duplicate, bad quality, low resolution, cropped""", 'weight': -1}],
64
- # 'cfg_scale': 7, 'seed': 0, 'samples': 1}
65
- # request_body = json.dumps(parameters)
66
- # response = bedrock_runtime.invoke_model(body=request_body,modelId = 'stability.stable-diffusion-xl-v1')
67
- # response_body = json.loads(response.get('body').read())
68
- # base64_image_data = base64.b64decode(response_body['artifacts'][0]['base64'])
69
-
70
- # return Image.open(io.BytesIO(base64_image_data))
71
 
72
 
73
  def gen_pos_prompt(text):
@@ -231,31 +216,36 @@ async def process_image(
231
  do_remove_background: bool = Form(...),
232
  foreground_ratio: float = Form(...),
233
  mc_resolution: int = Form(...),
 
234
  text_prompt: Optional[str] = Form(None)
235
  ):
236
- image_bytes = await file.read()
237
- input_image = Image.open(BytesIO(image_bytes))
238
-
239
- if enhance_image:
240
- image_pil = generate_image_from_text(encoded_image=input_image, seed=seed, pos_prompt=text_prompt)
241
- else:
242
- image_pil = input_image
243
-
244
- preprocessed = preprocess(image_pil, do_remove_background, foreground_ratio)
245
- mesh_name_obj, mesh_name_glb = generate(preprocessed, mc_resolution)
246
- timestamp = datetime.datetime.now().strftime('%Y%m%d%H%M%S%f')
247
- object_name = f'object_{timestamp}_1.obj'
248
- object_name_2 = f'object_{timestamp}_2.glb'
249
-
250
- if upload_file_to_s3(mesh_name_obj, 'framebucket3d',object_name) and upload_file_to_s3(mesh_name_glb, 'framebucket3d',object_name_2):
251
-
252
- return {
253
- "obj_path": f"https://framebucket3d.s3.amazonaws.com/{object_name}",
254
- "glb_path": f"https://framebucket3d.s3.amazonaws.com/{object_name_2}"
255
- }
256
-
 
 
 
 
257
  else:
258
- return {"Internal Server Error": False}
259
 
260
  if __name__ == "__main__":
261
  import uvicorn
 
23
  from botocore.exceptions import NoCredentialsError, PartialCredentialsError
24
  import datetime
25
 
 
 
26
  app = FastAPI()
27
 
 
28
  subprocess.run(shlex.split('pip install wheel/torchmcubes-0.1.0-cp310-cp310-linux_x86_64.whl'))
29
 
30
  from tsr.system import TSR
31
  from tsr.utils import remove_background, resize_foreground, to_gradio_3d_orientation
32
 
 
33
 
34
  HEADER = """FRAME AI"""
35
 
 
53
  SECRET = os.getenv("SECRET")
54
  bedrock = boto3.client(service_name='bedrock', aws_access_key_id = ACCESS, aws_secret_access_key = SECRET, region_name='us-east-1')
55
  bedrock_runtime = boto3.client(service_name='bedrock-runtime', aws_access_key_id = ACCESS, aws_secret_access_key = SECRET, region_name='us-east-1')
 
 
 
 
 
 
 
 
 
 
 
56
 
57
 
58
  def gen_pos_prompt(text):
 
216
  do_remove_background: bool = Form(...),
217
  foreground_ratio: float = Form(...),
218
  mc_resolution: int = Form(...),
219
+ auth: str = Form(...),
220
  text_prompt: Optional[str] = Form(None)
221
  ):
222
+
223
+ if auth == os.getenv("AUTHORIZE"):
224
+ image_bytes = await file.read()
225
+ input_image = Image.open(BytesIO(image_bytes))
226
+
227
+ if enhance_image:
228
+ image_pil = generate_image_from_text(encoded_image=input_image, seed=seed, pos_prompt=text_prompt)
229
+ else:
230
+ image_pil = input_image
231
+
232
+ preprocessed = preprocess(image_pil, do_remove_background, foreground_ratio)
233
+ mesh_name_obj, mesh_name_glb = generate(preprocessed, mc_resolution)
234
+ timestamp = datetime.datetime.now().strftime('%Y%m%d%H%M%S%f')
235
+ object_name = f'object_{timestamp}_1.obj'
236
+ object_name_2 = f'object_{timestamp}_2.glb'
237
+
238
+ if upload_file_to_s3(mesh_name_obj, 'framebucket3d',object_name) and upload_file_to_s3(mesh_name_glb, 'framebucket3d',object_name_2):
239
+
240
+ return {
241
+ "obj_path": f"https://framebucket3d.s3.amazonaws.com/{object_name}",
242
+ "glb_path": f"https://framebucket3d.s3.amazonaws.com/{object_name_2}"
243
+ }
244
+
245
+ else:
246
+ return {"Internal Server Error": False}
247
  else:
248
+ return {"Authentication":"Failed"}
249
 
250
  if __name__ == "__main__":
251
  import uvicorn