Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -2,6 +2,8 @@ import spaces
|
|
2 |
import torch
|
3 |
import re
|
4 |
import gradio as gr
|
|
|
|
|
5 |
from transformers import AutoTokenizer, AutoModelForCausalLM
|
6 |
|
7 |
if torch.cuda.is_available():
|
@@ -20,7 +22,9 @@ moondream.eval()
|
|
20 |
@spaces.GPU(duration=10)
|
21 |
def answer_questions(images, prompt_text):
|
22 |
prompts = [p.strip() for p in prompt_text.split(',')] # Splitting and cleaning prompts
|
23 |
-
|
|
|
|
|
24 |
answers = moondream.batch_answer(
|
25 |
images=image_embeds,
|
26 |
prompts=prompts,
|
|
|
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():
|
|
|
22 |
@spaces.GPU(duration=10)
|
23 |
def answer_questions(images, prompt_text):
|
24 |
prompts = [p.strip() for p in prompt_text.split(',')] # Splitting and cleaning prompts
|
25 |
+
# Extracting images from tuples and converting to PIL images
|
26 |
+
image_objects = [Image.open(io.BytesIO(img[0])) for img in images]
|
27 |
+
image_embeds = [moondream.encode_image(img) for img in image_objects]
|
28 |
answers = moondream.batch_answer(
|
29 |
images=image_embeds,
|
30 |
prompts=prompts,
|