Keyven commited on
Commit
3d3aea0
β€’
1 Parent(s): 3a929c0

Update response function

Browse files
Files changed (1) hide show
  1. app.py +7 -7
app.py CHANGED
@@ -48,7 +48,6 @@ def format_text(text):
48
 
49
 
50
  def get_chat_response(chatbot, task_history, model, tokenizer):
51
- """Generate a response using the model."""
52
  chat_query = chatbot[-1][0]
53
  query = task_history[-1][0]
54
  history_cp = copy.deepcopy(task_history)
@@ -77,17 +76,18 @@ def get_chat_response(chatbot, task_history, model, tokenizer):
77
  name = f"tmp{secrets.token_hex(5)}.jpg"
78
  filename = temp_dir / name
79
  image.save(str(filename))
80
- chatbot[-1] = (chat_query, (str(filename),))
81
  chat_response = response.replace("<ref>", "")
82
  chat_response = chat_response.replace(r"</ref>", "")
 
83
  if chat_response != "":
84
  chatbot.append((None, chat_response))
85
  else:
86
- chatbot[-1] = (chat_query, response)
87
- full_response = response # modified this line to ensure full_response is not empty
88
 
89
  task_history.append((message, full_response))
90
- chatbot.append((format_text(message), format_text(full_response)))
91
 
92
  return chatbot, task_history
93
 
@@ -160,8 +160,8 @@ with gr.Blocks(css=css) as demo:
160
 
161
  gr.Markdown("### Key Features:\n- **Strong Performance**: Surpasses existing LVLMs on multiple English benchmarks including Zero-shot Captioning and VQA.\n- **Multi-lingual Support**: Supports English, Chinese, and multi-lingual conversation.\n- **High Resolution**: Utilizes 448*448 resolution for fine-grained recognition and understanding.")
162
  submit_btn.click(handle_text_input, [chatbot, task_history, query], [chatbot, task_history]).then(
163
- get_chat_response, [chatbot, task_history, model, tokenizer], [chatbot], show_progress=True
164
- )
165
 
166
 
167
 
 
48
 
49
 
50
  def get_chat_response(chatbot, task_history, model, tokenizer):
 
51
  chat_query = chatbot[-1][0]
52
  query = task_history[-1][0]
53
  history_cp = copy.deepcopy(task_history)
 
76
  name = f"tmp{secrets.token_hex(5)}.jpg"
77
  filename = temp_dir / name
78
  image.save(str(filename))
79
+ chatbot[-1] = (format_text(chat_query), (str(filename),)) # Hier verwenden wir format_text statt _parse_text
80
  chat_response = response.replace("<ref>", "")
81
  chat_response = chat_response.replace(r"</ref>", "")
82
+ chat_response = re.sub(BOX_TAG_PATTERN, "", chat_response)
83
  if chat_response != "":
84
  chatbot.append((None, chat_response))
85
  else:
86
+ chatbot[-1] = (format_text(chat_query), response) # Hier verwenden wir format_text statt _parse_text
87
+ full_response = format_text(response) # Hier verwenden wir format_text statt _parse_text
88
 
89
  task_history.append((message, full_response))
90
+ chatbot.append((format_text(message), format_text(full_response))) # Hier verwenden wir format_text statt _parse_text
91
 
92
  return chatbot, task_history
93
 
 
160
 
161
  gr.Markdown("### Key Features:\n- **Strong Performance**: Surpasses existing LVLMs on multiple English benchmarks including Zero-shot Captioning and VQA.\n- **Multi-lingual Support**: Supports English, Chinese, and multi-lingual conversation.\n- **High Resolution**: Utilizes 448*448 resolution for fine-grained recognition and understanding.")
162
  submit_btn.click(handle_text_input, [chatbot, task_history, query], [chatbot, task_history]).then(
163
+ get_chat_response, [chatbot, task_history, model, tokenizer], [chatbot], show_progress=True
164
+ )
165
 
166
 
167