visheratin commited on
Commit
e4536f3
1 Parent(s): b219186

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -2
app.py CHANGED
@@ -45,6 +45,11 @@ def cached_vision_process(image, max_crops, num_tokens):
45
  def answer_question(image, question, max_crops, num_tokens):
46
  prompt = f"""<|im_start|>user
47
  <image>
 
 
 
 
 
48
  {question}<|im_end|>
49
  <|im_start|>assistant
50
  """
@@ -65,11 +70,15 @@ def answer_question(image, question, max_crops, num_tokens):
65
  thread.start()
66
 
67
  buffer = ""
 
68
  for new_text in streamer:
 
 
 
 
69
  buffer += new_text
70
- print(buffer)
71
  if len(buffer) > 1:
72
- yield buffer[len(prompt) :]
73
 
74
 
75
  with gr.Blocks() as demo:
 
45
  def answer_question(image, question, max_crops, num_tokens):
46
  prompt = f"""<|im_start|>user
47
  <image>
48
+ {question}<|im_end|>
49
+ <|im_start|>assistant
50
+ """
51
+ replace_prompt = f"""<|im_start|>user
52
+
53
  {question}<|im_end|>
54
  <|im_start|>assistant
55
  """
 
70
  thread.start()
71
 
72
  buffer = ""
73
+ output_started = False
74
  for new_text in streamer:
75
+ if not output_started:
76
+ if "<assistant>" in new_text:
77
+ output_started = True
78
+ continue
79
  buffer += new_text
 
80
  if len(buffer) > 1:
81
+ yield buffer
82
 
83
 
84
  with gr.Blocks() as demo: