Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -2,9 +2,8 @@ import spaces
|
|
2 |
import torch
|
3 |
import re
|
4 |
import gradio as gr
|
5 |
-
from PIL import Image
|
6 |
-
import io
|
7 |
from transformers import AutoTokenizer, AutoModelForCausalLM
|
|
|
8 |
|
9 |
if torch.cuda.is_available():
|
10 |
device, dtype = "cuda", torch.float16
|
@@ -20,11 +19,10 @@ moondream = AutoModelForCausalLM.from_pretrained(
|
|
20 |
moondream.eval()
|
21 |
|
22 |
@spaces.GPU(duration=10)
|
23 |
-
def answer_questions(
|
24 |
prompts = [p.strip() for p in prompt_text.split(',')] # Splitting and cleaning prompts
|
25 |
-
# Extracting images from tuples
|
26 |
-
|
27 |
-
image_embeds = [moondream.encode_image(img) for img in image_objects]
|
28 |
answers = moondream.batch_answer(
|
29 |
images=image_embeds,
|
30 |
prompts=prompts,
|
|
|
2 |
import torch
|
3 |
import re
|
4 |
import gradio as gr
|
|
|
|
|
5 |
from transformers import AutoTokenizer, AutoModelForCausalLM
|
6 |
+
from PIL import Image
|
7 |
|
8 |
if torch.cuda.is_available():
|
9 |
device, dtype = "cuda", torch.float16
|
|
|
19 |
moondream.eval()
|
20 |
|
21 |
@spaces.GPU(duration=10)
|
22 |
+
def answer_questions(image_tuples, prompt_text):
|
23 |
prompts = [p.strip() for p in prompt_text.split(',')] # Splitting and cleaning prompts
|
24 |
+
images = [img[0] for img in image_tuples if img[0] is not None] # Extracting images from tuples, ignoring None
|
25 |
+
image_embeds = [moondream.encode_image(img) for img in images]
|
|
|
26 |
answers = moondream.batch_answer(
|
27 |
images=image_embeds,
|
28 |
prompts=prompts,
|