Stremly commited on
Commit
759fe06
Β·
verified Β·
1 Parent(s): e995be0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -19
app.py CHANGED
@@ -45,36 +45,21 @@ def navigate(screenshot, task: str, platform: str, history):
45
  """
46
 
47
  # ───────────────────── normalise history input ──────────────────────────
 
48
  if history in (None, ""):
49
  history_list = []
50
  else:
51
  if isinstance(history, str):
52
  try:
53
- history_list = ast.literal_eval(history)
54
  except Exception as exc:
55
  raise ValueError("`history` must be a JSON/Python list: " + str(exc))
56
  else:
57
- history_list = history
58
 
59
  if not isinstance(history_list, list):
60
  raise ValueError("`history` must be a list of messages.")
61
 
62
- # ─────────────────── construct current user message ─────────────────────
63
- prompt_header = (
64
- "You are a GUI agent. You are given a task and your action history, "
65
- "with screenshots. You need to perform the next action to complete "
66
- "the task.\n\n## Output Format\n```\nThought: ...\nAction: ...\n```\n\n"
67
- "## Action Space\nclick(start_box='...') / type(...)\n\n"
68
- f"### Task\n{task}"
69
- )
70
-
71
- current_content = [
72
- {"type": "text", "text": prompt_header},
73
- {"type": "image_url", "image_url": screenshot},
74
- ]
75
-
76
- messages = history_list + [{"role": "user", "content": current_content}]
77
-
78
  # ─────────────────────────── model forward ─────────────────────────────
79
  text = processor.apply_chat_template(
80
  messages, tokenize=False, add_generation_prompt=True
@@ -128,7 +113,7 @@ demo = gr.Interface(
128
  gr.Image(label="With Click Point"),
129
  gr.Textbox(label="Raw Action JSON"),
130
  ],
131
- title="ShowUI‑2B Navigation Demo",
132
  )
133
 
134
  demo.launch(
 
45
  """
46
 
47
  # ───────────────────── normalise history input ──────────────────────────
48
+ messages=None
49
  if history in (None, ""):
50
  history_list = []
51
  else:
52
  if isinstance(history, str):
53
  try:
54
+ messages= ast.literal_eval(history)
55
  except Exception as exc:
56
  raise ValueError("`history` must be a JSON/Python list: " + str(exc))
57
  else:
58
+ messages = history
59
 
60
  if not isinstance(history_list, list):
61
  raise ValueError("`history` must be a list of messages.")
62
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
63
  # ─────────────────────────── model forward ─────────────────────────────
64
  text = processor.apply_chat_template(
65
  messages, tokenize=False, add_generation_prompt=True
 
113
  gr.Image(label="With Click Point"),
114
  gr.Textbox(label="Raw Action JSON"),
115
  ],
116
+ title="UI-Tars Navigation Demo",
117
  )
118
 
119
  demo.launch(