Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,9 +1,10 @@
|
|
|
|
1 |
import gradio as gr
|
2 |
from colpali_engine.models import ColQwen2, ColQwen2Processor
|
3 |
import torch
|
4 |
from PIL import Image
|
5 |
import logging
|
6 |
-
import
|
7 |
|
8 |
# Setup logging
|
9 |
logging.basicConfig(level=logging.INFO)
|
@@ -12,7 +13,7 @@ logger = logging.getLogger("colqwen-api")
|
|
12 |
# Initialize model
|
13 |
logger.info("Loading ColQwen2 model...")
|
14 |
model = ColQwen2.from_pretrained(
|
15 |
-
"vidore/colqwen2-v1.0",
|
16 |
torch_dtype=torch.bfloat16,
|
17 |
device_map="auto",
|
18 |
)
|
@@ -23,11 +24,9 @@ logger.info("Model loaded successfully")
|
|
23 |
def process_image(image):
|
24 |
try:
|
25 |
logger.info("Processing image")
|
26 |
-
# Convert to PIL Image if needed
|
27 |
if not isinstance(image, Image.Image):
|
28 |
image = Image.fromarray(image)
|
29 |
|
30 |
-
# Process image
|
31 |
inputs = processor(
|
32 |
images=image,
|
33 |
return_tensors="pt"
|
@@ -55,5 +54,5 @@ interface = gr.Interface(
|
|
55 |
description="Generate embeddings from images using ColQwen2"
|
56 |
)
|
57 |
|
58 |
-
#
|
59 |
-
interface.launch(server_name="0.0.0.0"
|
|
|
1 |
+
# app.py in Hugging Face Space
|
2 |
import gradio as gr
|
3 |
from colpali_engine.models import ColQwen2, ColQwen2Processor
|
4 |
import torch
|
5 |
from PIL import Image
|
6 |
import logging
|
7 |
+
import os
|
8 |
|
9 |
# Setup logging
|
10 |
logging.basicConfig(level=logging.INFO)
|
|
|
13 |
# Initialize model
|
14 |
logger.info("Loading ColQwen2 model...")
|
15 |
model = ColQwen2.from_pretrained(
|
16 |
+
"vidore/colqwen2-v1.0",
|
17 |
torch_dtype=torch.bfloat16,
|
18 |
device_map="auto",
|
19 |
)
|
|
|
24 |
def process_image(image):
|
25 |
try:
|
26 |
logger.info("Processing image")
|
|
|
27 |
if not isinstance(image, Image.Image):
|
28 |
image = Image.fromarray(image)
|
29 |
|
|
|
30 |
inputs = processor(
|
31 |
images=image,
|
32 |
return_tensors="pt"
|
|
|
54 |
description="Generate embeddings from images using ColQwen2"
|
55 |
)
|
56 |
|
57 |
+
# Let Gradio choose an available port
|
58 |
+
interface.launch(server_name="0.0.0.0")
|