Csplk commited on
Commit
db2ea29
β€’
1 Parent(s): 39bc0cc

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -4
app.py CHANGED
@@ -22,13 +22,32 @@ moondream.eval()
22
  def answer_questions(image_tuples, prompt_text):
23
  result = ""
24
 
25
- prompts = [p.strip() for p in prompt_text.split(',')] # Splitting and cleaning prompts
 
26
  image_embeds = [img[0] for img in image_tuples if img[0] is not None] # Extracting images from tuples, ignoring None
27
 
28
  # Check if the lengths of image_embeds and prompts are equal
29
- if len(image_embeds) != len(prompts):
30
- return ("Error: The number of images input and prompts input (seperate by commas in input text field) must be the same.")
31
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
32
  answers = moondream.batch_answer(
33
  images=image_embeds,
34
  prompts=prompts,
@@ -39,6 +58,7 @@ def answer_questions(image_tuples, prompt_text):
39
  result += (f"Q: {question}\nA: {answer}\n\n")
40
 
41
  return result
 
42
 
43
  with gr.Blocks() as demo:
44
  gr.Markdown("# moondream2 unofficial batch processing demo")
 
22
  def answer_questions(image_tuples, prompt_text):
23
  result = ""
24
 
25
+ prompts = [p.strip() for p in prompt_text.split(',')] # Splitting and cleaning prompts
26
+ print(f"prompts\n{prompts}\n")
27
  image_embeds = [img[0] for img in image_tuples if img[0] is not None] # Extracting images from tuples, ignoring None
28
 
29
  # Check if the lengths of image_embeds and prompts are equal
30
+ #if len(image_embeds) != len(prompts):
31
+ #return ("Error: The number of images input and prompts input (seperate by commas in input text field) must be the same.")
32
+
33
+ answers = []
34
+ for prompt in prompts:
35
+ image_answers = moondream.batch_answer(
36
+ images=[img.convert("RGB") for img in image_embeds],
37
+ prompts=[prompt] * len(image_embeds),
38
+ tokenizer=tokenizer,
39
+ )
40
+ answers.append(image_answers)
41
+
42
+ for i in range(len(image_tuples)):
43
+ image_name = f"image{i+1}"
44
+ image_answers = [answer[i] for answer in answers]
45
+ print(f"image{i+1}_answers \n {image_answers} \n")
46
+ data.append([image_name] + image_answers)
47
+
48
+ result = {'headers': prompts, 'data': data}
49
+ return result
50
+ '''
51
  answers = moondream.batch_answer(
52
  images=image_embeds,
53
  prompts=prompts,
 
58
  result += (f"Q: {question}\nA: {answer}\n\n")
59
 
60
  return result
61
+ '''
62
 
63
  with gr.Blocks() as demo:
64
  gr.Markdown("# moondream2 unofficial batch processing demo")