fffiloni commited on
Commit
042d40b
1 Parent(s): 53b4fd0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -7
app.py CHANGED
@@ -81,12 +81,15 @@ def extract_frames(video_in, interval=24, output_format='.jpg'):
81
 
82
  return frames
83
 
84
- from transformers import AutoModelForCausalLM, CodeGenTokenizerFast as Tokenizer
85
  from PIL import Image
86
 
87
- cap_model_id = "vikhyatk/moondream1"
88
- cap_model = AutoModelForCausalLM.from_pretrained(cap_model_id, trust_remote_code=True)
89
- cap_tokenizer = Tokenizer.from_pretrained(cap_model_id)
 
 
 
90
 
91
  def process_image(image_in):
92
  '''
@@ -100,9 +103,9 @@ def process_image(image_in):
100
  print(result)
101
  return result
102
  '''
103
- image = Image.open(image_in)
104
- enc_image = cap_model.encode_image(image)
105
- result = cap_model.answer_question(enc_image, "Describe precisely the image in one sentence.", cap_tokenizer)
106
  print(result)
107
  return result
108
 
 
81
 
82
  return frames
83
 
84
+ from transformers import AutoModelForCausalLM, AutoTokenizer
85
  from PIL import Image
86
 
87
+ model_id = "vikhyatk/moondream2"
88
+ revision = "2024-03-06"
89
+ model = AutoModelForCausalLM.from_pretrained(
90
+ model_id, trust_remote_code=True, revision=revision
91
+ )
92
+ tokenizer = AutoTokenizer.from_pretrained(model_id, revision=revision)
93
 
94
  def process_image(image_in):
95
  '''
 
103
  print(result)
104
  return result
105
  '''
106
+ image = Image.open('<IMAGE_PATH>')
107
+ enc_image = model.encode_image(image)
108
+ result = model.answer_question(enc_image, "Describe the image in one sentence.", tokenizer)
109
  print(result)
110
  return result
111