Csplk commited on
Commit
ee5e19e
β€’
1 Parent(s): 8a8a62b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -7
app.py CHANGED
@@ -20,22 +20,24 @@ moondream.eval()
20
 
21
  @spaces.GPU(duration=10)
22
  def answer_questions(image_tuples, prompt_text):
23
- print(f"prompt_text:\n{prompt_text}\n")
24
- print(f"image_tuples:\n{image_tuples}\n")
25
 
 
26
  prompts = [p.strip() for p in prompt_text.split(',')] # Splitting and cleaning prompts
27
- image_embeds = [img[0] for img in image_tuples if img[0] is not None] # Extracting images from tuples, ignoring None
28
 
29
- print(f"image_embeds:\n{image_embeds}\n")
30
- print(f"split prompts:\n{prompts}\n")
31
 
 
 
 
 
32
  answers = moondream.batch_answer(
33
  images=image_embeds,
34
  prompts=prompts,
35
  tokenizer=tokenizer,
36
  )
37
 
38
- result = ""
39
  for question, answer in zip(prompts, answers):
40
  print(f"Q: {question}")
41
  print(f"A: {answer}")
@@ -45,10 +47,11 @@ def answer_questions(image_tuples, prompt_text):
45
  return result
46
 
47
  with gr.Blocks() as demo:
 
48
  gr.Markdown("# πŸŒ” moondream2\nA tiny vision language model. [GitHub](https://github.com/vikhyatk/moondream)")
49
  with gr.Row():
50
  img = gr.Gallery(label="Upload Images", type="pil")
51
- prompt = gr.Textbox(label="Input Prompts", placeholder="Enter prompts separated by commas. Ex: Describe this image, What is in this image?", lines=2)
52
  submit = gr.Button("Submit")
53
  output = gr.TextArea(label="Responses", lines=4)
54
  submit.click(answer_questions, [img, prompt], output)
 
20
 
21
  @spaces.GPU(duration=10)
22
  def answer_questions(image_tuples, prompt_text):
23
+ result = ""
 
24
 
25
+ print(f"prompt_text: {prompt_text}\n")
26
  prompts = [p.strip() for p in prompt_text.split(',')] # Splitting and cleaning prompts
27
+ print(f"prompts: {prompts}\n")
28
 
29
+ image_embeds = [img[0] for img in image_tuples if img[0] is not None] # Extracting images from tuples, ignoring None
 
30
 
31
+ # Check if the lengths of image_embeds and prompts are equal
32
+ if len(image_embeds) != len(prompts):
33
+ return ("Error: The number of images input and prompts input (seperate by commas in input text field) must be the same.")
34
+
35
  answers = moondream.batch_answer(
36
  images=image_embeds,
37
  prompts=prompts,
38
  tokenizer=tokenizer,
39
  )
40
 
 
41
  for question, answer in zip(prompts, answers):
42
  print(f"Q: {question}")
43
  print(f"A: {answer}")
 
47
  return result
48
 
49
  with gr.Blocks() as demo:
50
+ gr.Markdown("# moondream2 unofficial batch processing demo")
51
  gr.Markdown("# πŸŒ” moondream2\nA tiny vision language model. [GitHub](https://github.com/vikhyatk/moondream)")
52
  with gr.Row():
53
  img = gr.Gallery(label="Upload Images", type="pil")
54
+ prompt = gr.Textbox(label="Input Prompts", placeholder="Enter prompts (one prompt for each image provided) separated by commas. Ex: Describe this image, What is in this image?", lines=2)
55
  submit = gr.Button("Submit")
56
  output = gr.TextArea(label="Responses", lines=4)
57
  submit.click(answer_questions, [img, prompt], output)