Fizzarolli commited on
Commit
fda67b7
1 Parent(s): 4e2b6d8
Files changed (1) hide show
  1. app.py +2 -4
app.py CHANGED
@@ -16,9 +16,9 @@ processor = AutoProcessor.from_pretrained(MODEL_ID)
16
 
17
  @spaces.GPU
18
  def tag_image(image, max_new_tokens=128):
19
- inputs = processor(images=image, text="<image>tag en", return_tensors="pt")
20
  streamer = TextIteratorStreamer(tokenizer=processor.tokenizer, skip_prompt=True)
21
- generation_kwargs = dict(inputs, streamer=streamer, max_new_tokens=max_new_tokens)
22
  thread = Thread(target=model.generate, kwargs=generation_kwargs)
23
 
24
  text = ""
@@ -26,8 +26,6 @@ def tag_image(image, max_new_tokens=128):
26
  for new_text in streamer:
27
  text += new_text
28
  yield text
29
-
30
- thread.join()
31
 
32
  return text
33
 
 
16
 
17
  @spaces.GPU
18
  def tag_image(image, max_new_tokens=128):
19
+ inputs = processor(images=image, text="<image>tag en", return_tensors="pt").to("cuda")
20
  streamer = TextIteratorStreamer(tokenizer=processor.tokenizer, skip_prompt=True)
21
+ generation_kwargs = dict(inputs, streamer=streamer, max_new_tokens=max_new_tokens, use_cache=True, cache_implementation="hybrid")
22
  thread = Thread(target=model.generate, kwargs=generation_kwargs)
23
 
24
  text = ""
 
26
  for new_text in streamer:
27
  text += new_text
28
  yield text
 
 
29
 
30
  return text
31