BenkHel commited on
Commit
761ef8c
·
verified ·
1 Parent(s): aaacb87

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -18
app.py CHANGED
@@ -55,9 +55,7 @@ tokenizer, model, image_processor, context_len = load_pretrained_model(
55
  model.config.training = False
56
 
57
  # FIXED PROMPT
58
- FIXED_PROMPT = "What type of waste is this item and how to dispose of it?"
59
- INTERNAL_PROMPT = "<image>\nWhat type of waste is this item and how to dispose of it?"
60
-
61
 
62
  def clear_history():
63
  state = default_conversation.copy()
@@ -68,15 +66,13 @@ def add_text(state, imagebox, textbox, image_process_mode):
68
  state = conv_templates[conv_mode].copy()
69
 
70
  if imagebox is not None:
 
71
  image = Image.open(imagebox).convert('RGB')
72
- visible_text = FIXED_PROMPT
73
- model_prompt = (INTERNAL_PROMPT, image, image_process_mode)
74
- state.append_message(state.roles[0], visible_text)
75
- state.append_message(state.roles[1], None)
76
- state.messages[-2].append(model_prompt)
77
  yield (state, state.to_gradio_chatbot(), "", None) + (disable_btn, disable_btn, disable_btn, enable_btn, enable_btn)
78
 
79
-
80
  def delete_text(state, image_process_mode):
81
  state.messages[-1][-1] = None
82
  prev_human_msg = state.messages[-2]
@@ -94,11 +90,7 @@ def regenerate(state, image_process_mode):
94
 
95
  @spaces.GPU
96
  def generate(state, imagebox, textbox, image_process_mode, temperature, top_p, max_output_tokens):
97
- hidden_data = state.messages[-2]
98
- if len(hidden_data) == 3 and isinstance(hidden_data[2], tuple):
99
- prompt, image, image_process_mode = hidden_data[2]
100
- else:
101
- prompt = FIXED_PROMPTT
102
  images = state.get_images(return_pil=True)
103
 
104
  ori_prompt = prompt
@@ -175,10 +167,8 @@ If you use this service or build upon this work, please cite the original public
175
  Li, Jiachen and Wang, Xinyao and Zhu, Sijie and Kuo, Chia-wen and Xu, Lu and Chen, Fan and Jain, Jitesh and Shi, Humphrey and Wen, Longyin.
176
  CuMo: Scaling Multimodal LLM with Co-Upcycled Mixture-of-Experts. arXiv preprint, 2024.
177
  [[arXiv](https://arxiv.org/abs/2405.05949)]
178
-
179
  By using this service, users are required to agree to the following terms:
180
  The service is a research preview intended for non-commercial use only. It only provides limited safety measures and may generate offensive content. It must not be used for any illegal, harmful, violent, racist, or sexual purposes.
181
-
182
  For an optimal experience, please use desktop computers for this demo, as mobile devices may compromise its quality.
183
  """)
184
 
@@ -199,7 +189,7 @@ block_css = """
199
 
200
  textbox = gr.Textbox(
201
  show_label=False,
202
- placeholder="Prompt is fixed: What material is this item and how to dispose of it?",
203
  container=False,
204
  interactive=False
205
  )
@@ -220,7 +210,7 @@ with gr.Blocks(title="CuMo", theme=gr.themes.Default(), css=block_css) as demo:
220
 
221
  #cur_dir = os.path.dirname(os.path.abspath(__file__))
222
  cur_dir = './cumo/serve'
223
- default_prompt = "<image>\nWhat material is this item and how to dispose of it?"
224
  gr.Examples(examples=[
225
  [f"{cur_dir}/examples/0165 CB.jpg", default_prompt],
226
  [f"{cur_dir}/examples/0225 PA.jpg", default_prompt],
 
55
  model.config.training = False
56
 
57
  # FIXED PROMPT
58
+ FIXED_PROMPT = "<image>\nWhat type of waste is this item and how to dispose of it?"
 
 
59
 
60
  def clear_history():
61
  state = default_conversation.copy()
 
66
  state = conv_templates[conv_mode].copy()
67
 
68
  if imagebox is not None:
69
+ textbox = FIXED_PROMPT
70
  image = Image.open(imagebox).convert('RGB')
71
+ textbox = (textbox, image, image_process_mode)
72
+ state.append_message(state.roles[0], textbox)
73
+ state.append_message(state.roles[1], None)
 
 
74
  yield (state, state.to_gradio_chatbot(), "", None) + (disable_btn, disable_btn, disable_btn, enable_btn, enable_btn)
75
 
 
76
  def delete_text(state, image_process_mode):
77
  state.messages[-1][-1] = None
78
  prev_human_msg = state.messages[-2]
 
90
 
91
  @spaces.GPU
92
  def generate(state, imagebox, textbox, image_process_mode, temperature, top_p, max_output_tokens):
93
+ prompt = FIXED_PROMPT
 
 
 
 
94
  images = state.get_images(return_pil=True)
95
 
96
  ori_prompt = prompt
 
167
  Li, Jiachen and Wang, Xinyao and Zhu, Sijie and Kuo, Chia-wen and Xu, Lu and Chen, Fan and Jain, Jitesh and Shi, Humphrey and Wen, Longyin.
168
  CuMo: Scaling Multimodal LLM with Co-Upcycled Mixture-of-Experts. arXiv preprint, 2024.
169
  [[arXiv](https://arxiv.org/abs/2405.05949)]
 
170
  By using this service, users are required to agree to the following terms:
171
  The service is a research preview intended for non-commercial use only. It only provides limited safety measures and may generate offensive content. It must not be used for any illegal, harmful, violent, racist, or sexual purposes.
 
172
  For an optimal experience, please use desktop computers for this demo, as mobile devices may compromise its quality.
173
  """)
174
 
 
189
 
190
  textbox = gr.Textbox(
191
  show_label=False,
192
+ placeholder="Prompt is fixed: What type of waste is this item and how to dispose of it?",
193
  container=False,
194
  interactive=False
195
  )
 
210
 
211
  #cur_dir = os.path.dirname(os.path.abspath(__file__))
212
  cur_dir = './cumo/serve'
213
+ default_prompt = "<image>\nWhat type of waste is this item and how to dispose of it?"
214
  gr.Examples(examples=[
215
  [f"{cur_dir}/examples/0165 CB.jpg", default_prompt],
216
  [f"{cur_dir}/examples/0225 PA.jpg", default_prompt],