BoyuNLP commited on
Commit
5179973
1 Parent(s): cd625c1
llava/conversation.py CHANGED
@@ -133,17 +133,17 @@ class Conversation:
133
  image = image.resize((336, 336))
134
  else:
135
  raise ValueError(f"Invalid image_process_mode: {image_process_mode}")
136
- if max(image.size) > max_len:
137
- max_hw, min_hw = max(image.size), min(image.size)
138
- aspect_ratio = max_hw / min_hw
139
- shortest_edge = int(min(max_len / aspect_ratio, min_len, min_hw))
140
- longest_edge = int(shortest_edge * aspect_ratio)
141
- W, H = image.size
142
- if H > W:
143
- H, W = longest_edge, shortest_edge
144
- else:
145
- H, W = shortest_edge, longest_edge
146
- image = image.resize((W, H))
147
  if return_pil:
148
  return image
149
  else:
 
133
  image = image.resize((336, 336))
134
  else:
135
  raise ValueError(f"Invalid image_process_mode: {image_process_mode}")
136
+ # if max(image.size) > max_len:
137
+ # max_hw, min_hw = max(image.size), min(image.size)
138
+ # aspect_ratio = max_hw / min_hw
139
+ # shortest_edge = int(min(max_len / aspect_ratio, min_len, min_hw))
140
+ # longest_edge = int(shortest_edge * aspect_ratio)
141
+ # W, H = image.size
142
+ # if H > W:
143
+ # H, W = longest_edge, shortest_edge
144
+ # else:
145
+ # H, W = shortest_edge, longest_edge
146
+ # image = image.resize((W, H))
147
  if return_pil:
148
  return image
149
  else:
llava/serve/gradio_web_server.py CHANGED
@@ -61,7 +61,7 @@ def resize_image(image, default_width=(1344, 896), request_width=None):
61
  from PIL import Image, ImageDraw
62
 
63
 
64
- def draw_circle_on_image(image, x, y, radius=10, color=(255, 0, 0)):
65
  """
66
  在给定的图片上绘制一个红色圆圈,并返回新的图片。如果 x, y 坐标不在图片范围内,
67
  并且 y 超出了图片高度,则尝试将 y 减去 224;如果调整后的 y 仍然超出范围,则返回原图。
@@ -382,6 +382,7 @@ def http_bot(state, model_selector, temperature, top_p, max_new_tokens, request:
382
 
383
  if len(all_images) > 0:
384
  # 假设我们对第一张图片进行 resize 并展示
 
385
  resized_image = draw_circle_on_image(resize_image(all_images[0]),original_coord[0],original_coord[1])
386
  # state.append_message(state.roles[1], ("", resized_image,"Default"))
387
  yield (state, state.to_gradio_chatbot(resized_image)) + (enable_btn,) * 5
@@ -425,8 +426,8 @@ block_css = """
425
  }
426
 
427
  #chatbot img {
428
- max-width: 100%; /* 宽图片根据宽度调整 */
429
- max-height: 100vh; /* 高图片根据视口高度调整 */
430
  width: auto; /* 保持宽度自适应 */
431
  height: auto; /* 保持高度自适应 */
432
  object-fit: contain; /* 保持图片宽高比,不失真 */
@@ -444,13 +445,14 @@ def build_demo(embed_mode, cur_dir=None, concurrency_count=1):
444
 
445
  with gr.Row():
446
  with gr.Column(scale=3):
447
- with gr.Row(elem_id="model_selector_row"):
448
- model_selector = gr.Dropdown(
449
- choices=models,
450
- value=models[0] if len(models) > 0 else "",
451
- interactive=True,
452
- show_label=False,
453
- container=False)
 
454
 
455
  imagebox = gr.Image(type="pil")
456
  image_process_mode = gr.Radio(
@@ -464,11 +466,14 @@ def build_demo(embed_mode, cur_dir=None, concurrency_count=1):
464
  [f"{cur_dir}/amazon.jpg",f"Search bar at the top of the page"],
465
  # [f"{cur_dir}/examples/waterview.jpg", "What are the things I should be cautious about when I visit here?"],
466
  ], inputs=[imagebox, textbox])
467
-
468
- with gr.Accordion("Parameters", open=False) as parameter_row:
469
- temperature = gr.Slider(minimum=0.0, maximum=1.0, value=0.2, step=0.1, interactive=True, label="Temperature",)
470
- top_p = gr.Slider(minimum=0.0, maximum=1.0, value=0.7, step=0.1, interactive=True, label="Top P",)
471
- max_output_tokens = gr.Slider(minimum=0, maximum=1024, value=512, step=64, interactive=True, label="Max output tokens",)
 
 
 
472
 
473
  with gr.Column(scale=8):
474
  chatbot = gr.Chatbot(
 
61
  from PIL import Image, ImageDraw
62
 
63
 
64
+ def draw_circle_on_image(image, x, y, radius=20, color=(255, 0, 0)):
65
  """
66
  在给定的图片上绘制一个红色圆圈,并返回新的图片。如果 x, y 坐标不在图片范围内,
67
  并且 y 超出了图片高度,则尝试将 y 减去 224;如果调整后的 y 仍然超出范围,则返回原图。
 
382
 
383
  if len(all_images) > 0:
384
  # 假设我们对第一张图片进行 resize 并展示
385
+
386
  resized_image = draw_circle_on_image(resize_image(all_images[0]),original_coord[0],original_coord[1])
387
  # state.append_message(state.roles[1], ("", resized_image,"Default"))
388
  yield (state, state.to_gradio_chatbot(resized_image)) + (enable_btn,) * 5
 
426
  }
427
 
428
  #chatbot img {
429
+ max-width: 80%; /* 宽图片根据宽度调整 */
430
+ max-height: 80vh; /* 高图片根据视口高度调整 */
431
  width: auto; /* 保持宽度自适应 */
432
  height: auto; /* 保持高度自适应 */
433
  object-fit: contain; /* 保持图片宽高比,不失真 */
 
445
 
446
  with gr.Row():
447
  with gr.Column(scale=3):
448
+ # with gr.Row(elem_id="model_selector_row"):
449
+ # model_selector = gr.Dropdown(
450
+ # choices=models,
451
+ # value=models[0] if len(models) > 0 else "",
452
+ # interactive=True,
453
+ # show_label=False,
454
+ # container=False)
455
+ model_selector="llava-v1.5-UGround_v1"
456
 
457
  imagebox = gr.Image(type="pil")
458
  image_process_mode = gr.Radio(
 
466
  [f"{cur_dir}/amazon.jpg",f"Search bar at the top of the page"],
467
  # [f"{cur_dir}/examples/waterview.jpg", "What are the things I should be cautious about when I visit here?"],
468
  ], inputs=[imagebox, textbox])
469
+ temperature=0
470
+ top_p=0.7
471
+ max_output_tokens=16384
472
+ #
473
+ # with gr.Accordion("Parameters", open=False) as parameter_row:
474
+ # temperature = gr.Slider(minimum=0.0, maximum=1.0, value=0.2, step=0.1, interactive=True, label="Temperature",)
475
+ # top_p = gr.Slider(minimum=0.0, maximum=1.0, value=0.7, step=0.1, interactive=True, label="Top P",)
476
+ # max_output_tokens = gr.Slider(minimum=0, maximum=1024, value=512, step=64, interactive=True, label="Max output tokens",)
477
 
478
  with gr.Column(scale=8):
479
  chatbot = gr.Chatbot(