skkk commited on
Commit
e4a8bf9
1 Parent(s): ff880b9

fix some bugs

Browse files
.gitignore ADDED
@@ -0,0 +1 @@
 
 
1
+ __pycache__
Rodin.py CHANGED
@@ -103,21 +103,22 @@ class Generator:
103
  _, self.token = login(user_id, password)
104
  self.task_uuid = None
105
 
106
- def preprocess(self, prompt, image_path):
 
 
 
107
  image_file = open(image_path, 'rb')
108
-
109
  if image_file == None:
110
  print("Invalid image file.")
111
-
112
  try:
113
- if not prompt:
114
- preprocess_response = rodin_preprocess_image(generate_prompt=True, image=image_file, name="images.jpeg", token=self.token)
115
- else:
116
  preprocess_response = rodin_preprocess_image(generate_prompt=False, image=image_file, name="images.jpeg", token=self.token)
 
 
117
  if 'error' in preprocess_response:
118
  print("Error in image preprocessing:", preprocess_response['error'])
119
  else:
120
- if not prompt:
121
  prompt = preprocess_response.get('prompt', 'Default prompt if none returned')
122
  processed_image = "data:image/png;base64," + preprocess_response.get('processed_image', None)
123
  finally:
@@ -149,8 +150,9 @@ class Generator:
149
  subscription_key = update_response['job']['subscription_key']
150
  checker = JobStatusChecker(BASE_URL, subscription_key)
151
  checker.start()
152
-
153
- preview_image = rodin_history(task_uuid, self.token)["v1"]["preview_image"]
 
154
  response = requests.get(preview_image, stream=True)
155
  if response.status_code == 200:
156
  # 创建一个PIL Image对象
 
103
  _, self.token = login(user_id, password)
104
  self.task_uuid = None
105
 
106
+ def preprocess(self, prompt, image_path, cache_image_base64, task_uuid=""):
107
+ if cache_image_base64 and prompt and task_uuid != "":
108
+ return prompt, cache_image_base64
109
+
110
  image_file = open(image_path, 'rb')
 
111
  if image_file == None:
112
  print("Invalid image file.")
 
113
  try:
114
+ if prompt and task_uuid:
 
 
115
  preprocess_response = rodin_preprocess_image(generate_prompt=False, image=image_file, name="images.jpeg", token=self.token)
116
+ else:
117
+ preprocess_response = rodin_preprocess_image(generate_prompt=True, image=image_file, name="images.jpeg", token=self.token)
118
  if 'error' in preprocess_response:
119
  print("Error in image preprocessing:", preprocess_response['error'])
120
  else:
121
+ if not (prompt and task_uuid):
122
  prompt = preprocess_response.get('prompt', 'Default prompt if none returned')
123
  processed_image = "data:image/png;base64," + preprocess_response.get('processed_image', None)
124
  finally:
 
150
  subscription_key = update_response['job']['subscription_key']
151
  checker = JobStatusChecker(BASE_URL, subscription_key)
152
  checker.start()
153
+
154
+ preview_image = next(reversed(rodin_history(task_uuid, self.token).items()))[1]["preview_image"]
155
+ print(f"Preview image URL: {rodin_history(task_uuid, self.token)}")
156
  response = requests.get(preview_image, stream=True)
157
  if response.status_code == 200:
158
  # 创建一个PIL Image对象
__pycache__/Rodin.cpython-310.pyc DELETED
Binary file (6.32 kB)
 
__pycache__/app.cpython-310.pyc DELETED
Binary file (5.55 kB)
 
__pycache__/constant.cpython-310.pyc DELETED
Binary file (739 Bytes)
 
app.py CHANGED
@@ -1,5 +1,5 @@
1
  import os
2
- # os.system('pip uninstall -y gradio_fake3d')
3
  os.system('pip install gradio_fake3d-0.0.2-py3-none-any.whl')
4
 
5
  import gradio as gr
@@ -152,7 +152,7 @@ with gr.Blocks() as demo:
152
  cache_raw_image = gr.Image(visible=False, type="pil")
153
  cache_image_base64 = gr.Text(visible=False)
154
  cacha_empty = gr.Text(visible=False)
155
- cache_task_uuid = gr.Text(value="", visible=False)
156
 
157
  # button_generate.click(fn=return_render, inputs=[block_image], outputs=[raw_image, fake3d])
158
  block_image.change(
@@ -164,7 +164,7 @@ with gr.Blocks() as demo:
164
 
165
  button_generate.click(
166
  fn=generator.preprocess,
167
- inputs=[block_prompt, block_image],
168
  outputs=[block_prompt, cache_image_base64],
169
  show_progress="minimal"
170
  ).success(
 
1
  import os
2
+ os.system('pip uninstall -y gradio_fake3d')
3
  os.system('pip install gradio_fake3d-0.0.2-py3-none-any.whl')
4
 
5
  import gradio as gr
 
152
  cache_raw_image = gr.Image(visible=False, type="pil")
153
  cache_image_base64 = gr.Text(visible=False)
154
  cacha_empty = gr.Text(visible=False)
155
+ cache_task_uuid = gr.Text(value="")
156
 
157
  # button_generate.click(fn=return_render, inputs=[block_image], outputs=[raw_image, fake3d])
158
  block_image.change(
 
164
 
165
  button_generate.click(
166
  fn=generator.preprocess,
167
+ inputs=[block_prompt, block_image, cache_image_base64, cache_task_uuid],
168
  outputs=[block_prompt, cache_image_base64],
169
  show_progress="minimal"
170
  ).success(