skkk commited on
Commit
d274192
1 Parent(s): 5ff67bd
Files changed (1) hide show
  1. Rodin.py +14 -15
Rodin.py CHANGED
@@ -88,7 +88,7 @@ def rodin_mesh(prompt, group_uuid, settings, images, name, token):
88
  'Authorization': f'Bearer {token}'
89
  }
90
  response = requests.post(f"{BASE_URL}/task/rodin_mesh", data=m, headers=headers)
91
- return response.json()
92
 
93
  # Convert base64 to binary since the result from `rodin_preprocess_image` is encoded with base64
94
  def convert_base64_to_binary(base64_string):
@@ -105,7 +105,7 @@ def rodin_update(prompt, task_uuid, token, settings):
105
  'Authorization': f'Bearer {token}'
106
  }
107
  response = requests.post(f"{BASE_URL}/task/rodin_update", data={"uuid": task_uuid, "prompt": prompt, "settings": settings}, headers=headers)
108
- return response.json()
109
 
110
  def load_image(img_path):
111
  try:
@@ -116,9 +116,9 @@ def load_image(img_path):
116
  # 按比例缩小图像到长度为1024
117
  width, height = image.size
118
  if width > height:
119
- scale = 1024 / width
120
  else:
121
- scale = 1024 / height
122
  new_width = int(width * scale)
123
  new_height = int(height * scale)
124
  resized_image = image.resize((new_width, new_height))
@@ -200,13 +200,14 @@ class Generator:
200
  settings = {'view_weights': [1]} # Define weights as per your requirements, for multiple images, use multiple values, e,g [0.5, 0.5]
201
  images = [processed_image] # List of images, all the images should be processed first
202
 
203
- mesh_response = rodin_mesh(prompt=prompt, group_uuid=None, settings=settings, images=images, name="images.jpeg", token=self.token)
204
- progress_checker = JobStatusChecker(BASE_URL, mesh_response['job']['subscription_key'])
205
  try:
 
 
206
  progress_checker.start()
207
  except Exception as e:
208
- log("ERROR", f"Error in generating mesh: {e}")
209
- time.sleep(5)
210
 
211
  task_uuid = mesh_response['uuid'] # The task_uuid should be same during whole generation process
212
  else:
@@ -216,17 +217,15 @@ class Generator:
216
  "seed": random.randint(0, 10000), # Customize your seed here
217
  "escore": 5.5, # Temprature
218
  }
219
-
220
- update_response = rodin_update(new_prompt, task_uuid, self.token, settings)
221
-
222
- # Check progress
223
- subscription_key = update_response['job']['subscription_key']
224
- checker = JobStatusChecker(BASE_URL, subscription_key)
225
  try:
 
 
 
226
  checker.start()
227
  except Exception as e:
228
  log("ERROR", f"Error in updating mesh: {e}")
229
- time.sleep(5)
230
 
231
  try:
232
  history = rodin_history(task_uuid, self.token)
 
88
  'Authorization': f'Bearer {token}'
89
  }
90
  response = requests.post(f"{BASE_URL}/task/rodin_mesh", data=m, headers=headers)
91
+ return response
92
 
93
  # Convert base64 to binary since the result from `rodin_preprocess_image` is encoded with base64
94
  def convert_base64_to_binary(base64_string):
 
105
  'Authorization': f'Bearer {token}'
106
  }
107
  response = requests.post(f"{BASE_URL}/task/rodin_update", data={"uuid": task_uuid, "prompt": prompt, "settings": settings}, headers=headers)
108
+ return response
109
 
110
  def load_image(img_path):
111
  try:
 
116
  # 按比例缩小图像到长度为1024
117
  width, height = image.size
118
  if width > height:
119
+ scale = 512 / width
120
  else:
121
+ scale = 512 / height
122
  new_width = int(width * scale)
123
  new_height = int(height * scale)
124
  resized_image = image.resize((new_width, new_height))
 
200
  settings = {'view_weights': [1]} # Define weights as per your requirements, for multiple images, use multiple values, e,g [0.5, 0.5]
201
  images = [processed_image] # List of images, all the images should be processed first
202
 
203
+ res = rodin_mesh(prompt=prompt, group_uuid=None, settings=settings, images=images, name="images.jpeg", token=self.token)
 
204
  try:
205
+ mesh_response = res.json()
206
+ progress_checker = JobStatusChecker(BASE_URL, mesh_response['job']['subscription_key'])
207
  progress_checker.start()
208
  except Exception as e:
209
+ log("ERROR", f"Error in generating mesh: {e} and response: {res}")
210
+ raise gr.Error("Error in generating mesh, please try again later.")
211
 
212
  task_uuid = mesh_response['uuid'] # The task_uuid should be same during whole generation process
213
  else:
 
217
  "seed": random.randint(0, 10000), # Customize your seed here
218
  "escore": 5.5, # Temprature
219
  }
220
+ res = rodin_update(new_prompt, task_uuid, self.token, settings)
 
 
 
 
 
221
  try:
222
+ update_response = res.json()
223
+ subscription_key = update_response['job']['subscription_key']
224
+ checker = JobStatusChecker(BASE_URL, subscription_key)
225
  checker.start()
226
  except Exception as e:
227
  log("ERROR", f"Error in updating mesh: {e}")
228
+ raise gr.Error("Error in generating mesh, please try again later.")
229
 
230
  try:
231
  history = rodin_history(task_uuid, self.token)