rdezwart commited on
Commit
2f92f19
1 Parent(s): 5a0207c

Change how we ask the model questions

Browse files

Brings it closer to the moondream2 example space. I really wish I could test locally.

Files changed (1) hide show
  1. app.py +8 -2
app.py CHANGED
@@ -9,6 +9,12 @@ moondream_model = AutoModelForCausalLM.from_pretrained(
9
  moondream_id, trust_remote_code=True, code_revision=moondream_revision
10
  )
11
 
 
 
 
 
 
 
12
  with gr.Blocks() as app:
13
  gr.Markdown(
14
  """
@@ -24,8 +30,8 @@ with gr.Blocks() as app:
24
  img = gr.Image(label="Image")
25
  output = gr.TextArea(label="Output")
26
 
27
- submit.click(moondream_model.answer_question, [img, prompt, moondream_tokenizer], output)
28
- prompt.submit(moondream_model.answer_question, [img, prompt, moondream_tokenizer], output)
29
 
30
  if __name__ == "__main__":
31
  app.launch()
 
9
  moondream_id, trust_remote_code=True, code_revision=moondream_revision
10
  )
11
 
12
+
13
+ def answer_question(_img, _prompt):
14
+ image_embeds = moondream_model.encode_image(_img)
15
+ return moondream_model.answer_question(image_embeds, _prompt, moondream_tokenizer)
16
+
17
+
18
  with gr.Blocks() as app:
19
  gr.Markdown(
20
  """
 
30
  img = gr.Image(label="Image")
31
  output = gr.TextArea(label="Output")
32
 
33
+ submit.click(answer_question, [img, prompt], output)
34
+ prompt.submit(answer_question, [img, prompt], output)
35
 
36
  if __name__ == "__main__":
37
  app.launch()