yu-rp commited on
Commit
ab0ee40
·
1 Parent(s): 01f7c83

add examples

Browse files
Files changed (1) hide show
  1. app.py +97 -20
app.py CHANGED
@@ -26,6 +26,97 @@ MARKDOWN = """
26
  </div>
27
  """
28
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
29
  def get_base64_images(image):
30
  image = image.convert('RGB')
31
  buffer = BytesIO()
@@ -100,12 +191,14 @@ def change_api_method(api_method):
100
  if api_method == "CLIP_Based API":
101
  model_dict = init_clip()
102
  new_generate_llava_response_button = gr.Button("Pre-Answer", interactive=False)
 
103
  elif api_method == "LLaVA_Based API":
104
  model_dict = init_llava()
105
  new_generate_llava_response_button = gr.Button("Pre-Answer", interactive=True)
 
106
  else:
107
  raise NotImplementedError
108
- return model_dict, {}, new_generate_llava_response_button, new_text_pre_answer, new_image_output
109
 
110
  def clear_cache(cache_dict):
111
  return {}
@@ -193,7 +286,7 @@ text_pre_answer = gr.Textbox(
193
  interactive=False,
194
  type="text")
195
  text_highlight_text = gr.Textbox(
196
- label = "Hint Text.",
197
  info = "The text based on which the mask will be generated. For LLaVA-Based API, it should be a substring of the pre-answer.",
198
  placeholder="Enter the hint text",
199
  lines=1,
@@ -286,24 +379,8 @@ with gr.Blocks() as demo:
286
  text_original_image_response.render()
287
  text_API_image_response.render()
288
  with gr.Accordion("Examples"):
289
- examples_images_responses = gr.Examples(
290
- [
291
-
292
- ],
293
- [
294
- image_input,
295
- image_output,
296
- text_query,
297
- text_pre_answer,
298
- text_highlight_text,
299
- slider_enhance_coe,
300
- slider_kernel_size,
301
- radio_interpolate_method_name,
302
- slider_mask_grayscale,
303
- text_original_image_response,
304
- text_API_image_response
305
- ],
306
- )
307
 
308
  radio_api_method.change(
309
  fn=change_api_method,
 
26
  </div>
27
  """
28
 
29
+ def init_clip_examples():
30
+ return gr.Examples(
31
+ [
32
+ [
33
+ "https://raw.githubusercontent.com/yu-rp/asserts/main/API_Prompting/clip_example_1_ori.jpg",
34
+ "https://raw.githubusercontent.com/yu-rp/asserts/main/API_Prompting/clip_example_1_masked.webp",
35
+ "What fruit is in the left part of the fridge?",
36
+ "-",
37
+ "fruit",
38
+ 30,
39
+ 3,
40
+ "BICUBIC",
41
+ 0,
42
+ "On the left side of the fridge, there are strawberries and blueberries visible in containers.",
43
+ "In the left part of the fridge, there are strawberries in a clear plastic container."
44
+ ],
45
+ [
46
+ "https://raw.githubusercontent.com/yu-rp/asserts/main/API_Prompting/example_2_ori.jpg",
47
+ "https://raw.githubusercontent.com/yu-rp/asserts/main/API_Prompting/clip_example_2_masked.webp",
48
+ "On the right desk, what is to the left of the laptop?",
49
+ "-",
50
+ "desk",
51
+ 5,
52
+ 3,
53
+ "BICUBIC",
54
+ 0,
55
+ "On the right desk, to the left of the laptop, there is a small pile of books stacked next to the laptop.",
56
+ "To the left of the laptop on the right desk, there is a desk lamp."
57
+ ],
58
+ ],
59
+ [
60
+ image_input,
61
+ image_output,
62
+ text_query,
63
+ text_pre_answer,
64
+ text_highlight_text,
65
+ slider_enhance_coe,
66
+ slider_kernel_size,
67
+ radio_interpolate_method_name,
68
+ slider_mask_grayscale,
69
+ text_original_image_response,
70
+ text_API_image_response
71
+ ],
72
+ label = "Examples for CLIP_Based API"
73
+ )
74
+ def init_llava_examples():
75
+ return gr.Examples(
76
+ [
77
+ [
78
+ "https://raw.githubusercontent.com/yu-rp/asserts/main/API_Prompting/llava_example_1_ori.jpg",
79
+ "https://raw.githubusercontent.com/yu-rp/asserts/main/API_Prompting/llava_example_1_masked.webp",
80
+ "Which direction is the red bird facing?",
81
+ " The red bird is facing away from the camera.</s>",
82
+ "red bird",
83
+ 20,
84
+ 3,
85
+ "BICUBIC",
86
+ 100,
87
+ "The red bird in the image is facing to the right.",
88
+ "The red bird is facing towards the left in the image."
89
+ ],
90
+ [
91
+ "https://raw.githubusercontent.com/yu-rp/asserts/main/API_Prompting/example_2_ori.jpg",
92
+ "https://raw.githubusercontent.com/yu-rp/asserts/main/API_Prompting/llava_example_2_masked.webp",
93
+ "On the right desk, what is to the left of the laptop?",
94
+ " On the right desk, there is a lamp to the left of the laptop.</s>",
95
+ " On the right desk, there is a lamp to the left of the laptop.</s>",
96
+ 30,
97
+ 3,
98
+ "BICUBIC",
99
+ 0,
100
+ "On the right desk, to the left of the laptop, there is a small pile of books stacked next to the laptop.",
101
+ "To the left of the laptop on the right desk, there is a green desk lamp."
102
+ ],
103
+ ],
104
+ [
105
+ image_input,
106
+ image_output,
107
+ text_query,
108
+ text_pre_answer,
109
+ text_highlight_text,
110
+ slider_enhance_coe,
111
+ slider_kernel_size,
112
+ radio_interpolate_method_name,
113
+ slider_mask_grayscale,
114
+ text_original_image_response,
115
+ text_API_image_response
116
+ ],
117
+ label = "Examples for LLaVA_Based API"
118
+ )
119
+
120
  def get_base64_images(image):
121
  image = image.convert('RGB')
122
  buffer = BytesIO()
 
191
  if api_method == "CLIP_Based API":
192
  model_dict = init_clip()
193
  new_generate_llava_response_button = gr.Button("Pre-Answer", interactive=False)
194
+ # new_examples = init_clip_examples()
195
  elif api_method == "LLaVA_Based API":
196
  model_dict = init_llava()
197
  new_generate_llava_response_button = gr.Button("Pre-Answer", interactive=True)
198
+ # new_examples = init_llava_examples()
199
  else:
200
  raise NotImplementedError
201
+ return model_dict, {}, new_generate_llava_response_button, new_text_pre_answer, new_image_output#, new_examples
202
 
203
  def clear_cache(cache_dict):
204
  return {}
 
286
  interactive=False,
287
  type="text")
288
  text_highlight_text = gr.Textbox(
289
+ label = "Hint Text",
290
  info = "The text based on which the mask will be generated. For LLaVA-Based API, it should be a substring of the pre-answer.",
291
  placeholder="Enter the hint text",
292
  lines=1,
 
379
  text_original_image_response.render()
380
  text_API_image_response.render()
381
  with gr.Accordion("Examples"):
382
+ clip_examples = init_clip_examples()
383
+ llava_examples = init_llava_examples()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
384
 
385
  radio_api_method.change(
386
  fn=change_api_method,