PerryCheng614 commited on
Commit
6e0c709
1 Parent(s): d45f38a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -2
app.py CHANGED
@@ -32,14 +32,19 @@ async def process_image_stream(image_path, prompt, max_tokens=512):
32
  "max_tokens": max_tokens
33
  }))
34
 
35
- # Initialize response
36
  response = ""
 
37
 
38
  # Receive streaming response
39
  async for message in websocket:
40
  try:
41
  data = json.loads(message)
42
  if data["status"] == "generating":
 
 
 
 
43
  response += data["token"]
44
  yield response
45
  elif data["status"] == "complete":
@@ -77,7 +82,9 @@ demo = gr.Interface(
77
  Upload an image and ask questions about it. The model will analyze the image and provide detailed answers to your queries.
78
  """,
79
  examples=[
80
- ["example_images/example_1.jpg", "Describe this image", 128],
 
 
81
  ]
82
  )
83
 
 
32
  "max_tokens": max_tokens
33
  }))
34
 
35
+ # Initialize response and token counter
36
  response = ""
37
+ token_count = 0
38
 
39
  # Receive streaming response
40
  async for message in websocket:
41
  try:
42
  data = json.loads(message)
43
  if data["status"] == "generating":
44
+ # Skip first three tokens if they match specific patterns
45
+ if token_count < 3 and data["token"] in [" ", " \n", "\n", "<|im_start|>", "assistant"]:
46
+ token_count += 1
47
+ continue
48
  response += data["token"]
49
  yield response
50
  elif data["status"] == "complete":
 
82
  Upload an image and ask questions about it. The model will analyze the image and provide detailed answers to your queries.
83
  """,
84
  examples=[
85
+ ["example_images/example_1.jpg", "What kind of cat is this?", 128],
86
+ ["example_images/example_2.jpg", "What color is this dress? ", 128],
87
+ ["example_images/example_3.jpg", "What is this image about?", 128],
88
  ]
89
  )
90