BoyuNLP commited on
Commit
cb99099
·
verified ·
1 Parent(s): 2d21e0c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +50 -4
app.py CHANGED
@@ -3,7 +3,7 @@ import json
3
  from datetime import datetime
4
  import gradio as gr
5
  import torch
6
- import spaces
7
  from PIL import Image, ImageDraw
8
  from qwen_vl_utils import process_vision_info
9
  from transformers import Qwen2VLForConditionalGeneration, AutoProcessor
@@ -83,7 +83,7 @@ def crop_image(image_path, click_xy, crop_factor=0.5):
83
 
84
  return cropped_image_path
85
 
86
- @spaces.GPU
87
  def run_showui(image, query, session_id, iterations=1):
88
  """Main function for iterative inference."""
89
  image_path = array_to_image_path(image, session_id)
@@ -228,11 +228,53 @@ examples = [
228
  # ["./examples/safari_google.png", "Click on search bar.", True],
229
  ]
230
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
231
  def build_demo(embed_mode, concurrency_count=1):
232
- with gr.Blocks(title="UGround Demo", theme=gr.themes.Default()) as demo:
233
  state_image_path = gr.State(value=None)
234
  state_session_id = gr.State(value=None)
235
 
 
 
 
 
236
  # if not embed_mode:
237
  # gr.HTML(
238
  # f"""
@@ -272,7 +314,7 @@ def build_demo(embed_mode, concurrency_count=1):
272
 
273
  textbox = gr.Textbox(
274
  show_label=True,
275
- placeholder="Enter a query (e.g., 'Click Nahant')",
276
  label="Query",
277
  )
278
  submit_btn = gr.Button(value="Submit", variant="primary")
@@ -365,6 +407,10 @@ def build_demo(embed_mode, concurrency_count=1):
365
  queue=False
366
  )
367
 
 
 
 
 
368
  return demo
369
 
370
  if __name__ == "__main__":
 
3
  from datetime import datetime
4
  import gradio as gr
5
  import torch
6
+ # import spaces
7
  from PIL import Image, ImageDraw
8
  from qwen_vl_utils import process_vision_info
9
  from transformers import Qwen2VLForConditionalGeneration, AutoProcessor
 
83
 
84
  return cropped_image_path
85
 
86
+ # @spaces.GPU
87
  def run_showui(image, query, session_id, iterations=1):
88
  """Main function for iterative inference."""
89
  image_path = array_to_image_path(image, session_id)
 
228
  # ["./examples/safari_google.png", "Click on search bar.", True],
229
  ]
230
 
231
+
232
+
233
+ title_markdown = ("""
234
+ # UGround: Universal Visual Grounding for GUI Agents
235
+ [[🏠Project Homepage](https://osu-nlp-group.github.io/UGround/)] [[Code](https://github.com/OSU-NLP-Group/UGround)] [[😊Model](https://huggingface.co/collections/osunlp/uground-677824fc5823d21267bc9812)][[📚Paper](https://arxiv.org/abs/2410.05243)]
236
+ """)
237
+
238
+ tos_markdown = ("""
239
+ ### Terms of use
240
+ By using this service, users are required to agree to the following terms:
241
+ 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. The service may collect user dialogue data for future research.
242
+ Please click the "Flag" button if you get any inappropriate answer! We will collect those to keep improving our moderator.
243
+ For an optimal experience, please use desktop computers for this demo, as mobile devices may compromise its quality.
244
+ """)
245
+
246
+
247
+ learn_more_markdown = ("""
248
+ ### License
249
+ The service is a research preview intended for non-commercial use only, subject to the model [License](https://github.com/facebookresearch/llama/blob/main/MODEL_CARD.md) of LLaMA, [Terms of Use](https://openai.com/policies/terms-of-use) of the data generated by OpenAI. Please contact us if you find any potential violation.
250
+ """)
251
+
252
+ block_css = """
253
+
254
+ #buttons button {
255
+ min-width: min(120px,100%);
256
+ }
257
+
258
+ #chatbot img {
259
+ max-width: 80%; /* 宽图片根据宽度调整 */
260
+ max-height: 80vh; /* 高图片根据视口高度调整 */
261
+ width: auto; /* 保持宽度自适应 */
262
+ height: auto; /* 保持高度自适应 */
263
+ object-fit: contain; /* 保持图片宽高比,不失真 */
264
+ }
265
+
266
+ """
267
+
268
+
269
  def build_demo(embed_mode, concurrency_count=1):
270
+ with gr.Blocks(title="UGround Demo", theme=gr.themes.Default(), css=block_css) as demo:
271
  state_image_path = gr.State(value=None)
272
  state_session_id = gr.State(value=None)
273
 
274
+
275
+ if not embed_mode:
276
+ gr.Markdown(title_markdown)
277
+
278
  # if not embed_mode:
279
  # gr.HTML(
280
  # f"""
 
314
 
315
  textbox = gr.Textbox(
316
  show_label=True,
317
+ placeholder="Enter an element description (referring expression) or a single-step instruction and press ENTER",
318
  label="Query",
319
  )
320
  submit_btn = gr.Button(value="Submit", variant="primary")
 
407
  queue=False
408
  )
409
 
410
+ if not embed_mode:
411
+ gr.Markdown(tos_markdown)
412
+ gr.Markdown(learn_more_markdown)
413
+
414
  return demo
415
 
416
  if __name__ == "__main__":