skkk commited on
Commit
2455b73
1 Parent(s): f97e79d

add example

Browse files
Files changed (3) hide show
  1. Rodin.py +5 -2
  2. app.py +29 -33
  3. assets/white_image.png +0 -0
Rodin.py CHANGED
@@ -7,6 +7,7 @@ import base64
7
  import io
8
  from PIL import Image
9
  from io import BytesIO
 
10
  from requests_toolbelt.multipart.encoder import MultipartEncoder
11
  from constant import *
12
 
@@ -53,6 +54,8 @@ def rodin_preprocess_image(generate_prompt, image, name, token):
53
  return response.json()
54
 
55
  def crop_image(image, type):
 
 
56
  new_image_width = 360 * (11520 // 720) # 每隔720像素裁切一次,每次裁切宽度为360
57
  new_image_height = 360 # 新图片的高度
58
  new_image = Image.new('RGB', (new_image_width, new_image_height))
@@ -135,7 +138,7 @@ class Generator:
135
  self.processed_image = None
136
 
137
  def preprocess(self, prompt, image_path, processed_image , task_uuid=""):
138
- if processed_image and prompt and task_uuid != "":
139
  log("INFO", "Using cached image and prompt...")
140
  return prompt, processed_image
141
  log("INFO", "Preprocessing image...")
@@ -205,7 +208,7 @@ class Generator:
205
  try:
206
  preview_image = next(reversed(history.items()))[1]["preview_image"]
207
  except Exception as e:
208
- print(history)
209
  raise e
210
  response = requests.get(preview_image, stream=True)
211
  if response.status_code == 200:
 
7
  import io
8
  from PIL import Image
9
  from io import BytesIO
10
+ import gradio as gr
11
  from requests_toolbelt.multipart.encoder import MultipartEncoder
12
  from constant import *
13
 
 
54
  return response.json()
55
 
56
  def crop_image(image, type):
57
+ if image == None:
58
+ raise gr.Error("Generate Image First")
59
  new_image_width = 360 * (11520 // 720) # 每隔720像素裁切一次,每次裁切宽度为360
60
  new_image_height = 360 # 新图片的高度
61
  new_image = Image.new('RGB', (new_image_width, new_image_height))
 
138
  self.processed_image = None
139
 
140
  def preprocess(self, prompt, image_path, processed_image , task_uuid=""):
141
+ if processed_image and prompt and (not task_uuid):
142
  log("INFO", "Using cached image and prompt...")
143
  return prompt, processed_image
144
  log("INFO", "Preprocessing image...")
 
208
  try:
209
  preview_image = next(reversed(history.items()))[1]["preview_image"]
210
  except Exception as e:
211
+ log("ERROR", f"Error in generating mesh: {history}")
212
  raise e
213
  response = requests.get(preview_image, stream=True)
214
  if response.status_code == 200:
app.py CHANGED
@@ -1,6 +1,6 @@
1
  import os
2
- os.system('pip uninstall -y gradio_fake3d')
3
- os.system('pip install gradio_fake3d-0.0.3-py3-none-any.whl')
4
 
5
  import gradio as gr
6
  import re
@@ -61,16 +61,16 @@ options = [
61
  ]
62
 
63
  example = [
64
- "assets/00.png",
65
- "assets/07.png",
66
- "assets/08.png",
67
- "assets/11.png",
68
- "assets/13.png",
69
- "assets/21.png",
70
- "assets/24.PNG",
71
- "assets/30.png",
72
- "assets/42.png",
73
- "assets/46.png",
74
  ]
75
 
76
  def do_nothing(text):
@@ -107,8 +107,11 @@ def handle_prompt_change(prompt):
107
  return hint_list
108
 
109
  def clear_task(task_input=None):
 
 
 
110
  log("INFO", "Clearing task...")
111
- return "", "", [], None
112
 
113
  def clear_task_id():
114
  return ""
@@ -160,22 +163,22 @@ with gr.Blocks() as demo:
160
  block_normal = gr.Button("Normal", min_width=0)
161
 
162
  button_more = gr.Button(value="Download", variant="primary", link=rodin_url)
 
 
163
 
164
  cache_raw_image = gr.Image(visible=False, type="pil")
165
  cacha_empty = gr.Text(visible=False)
166
  cache_image_base64 = gr.Text(visible=False)
167
- cache_task_uuid = gr.Text(value="", visible=False)
168
-
169
- # block_example = gr.Examples(
170
- # examples=example,
171
- # fn=clear_task,
172
- # inputs=[block_image],
173
- # outputs=[cache_task_uuid, block_prompt, block_prompt_hint, fake3d],
174
- # run_on_click=True,
175
- # label="Examples"
176
- # )
177
- # blcok_input_example = gr.Gallery(value=example, columns=10, allow_preview=False, interactive=False)
178
-
179
  block_image.upload(
180
  fn=do_nothing,
181
  js=change_button_name_to_generating,
@@ -208,13 +211,6 @@ with gr.Blocks() as demo:
208
  show_progress="hidden"
209
  )
210
 
211
- # block_image.change(
212
- # fn=do_nothing,
213
- # js=reset_button_name,
214
- # inputs=[cacha_empty],
215
- # outputs=[cacha_empty]
216
- # )
217
-
218
  button_generate.click(
219
  fn=do_nothing,
220
  js=change_button_name_to_generating,
@@ -261,4 +257,4 @@ with gr.Blocks() as demo:
261
 
262
 
263
  if __name__ == "__main__":
264
- demo.launch(show_api=False)
 
1
  import os
2
+ # os.system('pip uninstall -y gradio_fake3d')
3
+ # os.system('pip install gradio_fake3d-0.0.3-py3-none-any.whl')
4
 
5
  import gradio as gr
6
  import re
 
61
  ]
62
 
63
  example = [
64
+ ["assets/00.png"],
65
+ ["assets/07.png"],
66
+ ["assets/08.png"],
67
+ ["assets/11.png"],
68
+ ["assets/13.png"],
69
+ ["assets/21.png"],
70
+ ["assets/24.PNG"],
71
+ ["assets/30.png"],
72
+ ["assets/42.png"],
73
+ ["assets/46.png"]
74
  ]
75
 
76
  def do_nothing(text):
 
107
  return hint_list
108
 
109
  def clear_task(task_input=None):
110
+ """_summary_
111
+ [cache_task_uuid, block_prompt, block_prompt_hint, fake3d]
112
+ """
113
  log("INFO", "Clearing task...")
114
+ return "", "", [], "assets/white_image.png"
115
 
116
  def clear_task_id():
117
  return ""
 
163
  block_normal = gr.Button("Normal", min_width=0)
164
 
165
  button_more = gr.Button(value="Download", variant="primary", link=rodin_url)
166
+ cache_task_uuid = gr.Text(value="", visible=False)
167
+
168
 
169
  cache_raw_image = gr.Image(visible=False, type="pil")
170
  cacha_empty = gr.Text(visible=False)
171
  cache_image_base64 = gr.Text(visible=False)
172
+ block_example = gr.Examples(
173
+ examples=example,
174
+ fn=clear_task,
175
+ inputs=[block_image],
176
+ outputs=[cache_task_uuid, block_prompt, block_prompt_hint, fake3d],
177
+ run_on_click=True,
178
+ cache_examples=True,
179
+ label="Examples"
180
+ )
181
+
 
 
182
  block_image.upload(
183
  fn=do_nothing,
184
  js=change_button_name_to_generating,
 
211
  show_progress="hidden"
212
  )
213
 
 
 
 
 
 
 
 
214
  button_generate.click(
215
  fn=do_nothing,
216
  js=change_button_name_to_generating,
 
257
 
258
 
259
  if __name__ == "__main__":
260
+ demo.launch(show_api=False, show_error=True)
assets/white_image.png ADDED