File tree Expand file tree Collapse file tree 3 files changed +4
-14
lines changed Expand file tree Collapse file tree 3 files changed +4
-14
lines changed Original file line number Diff line number Diff line change @@ -28,6 +28,7 @@ We appreciate a star ⭐ at [CocoIndex Github](https://github.com/cocoindex-io/c
2828```
2929ollama pull gemma3
3030ollama serve
31+ export OLLAMA_MODEL="gemma3" # Optional, for caption generation
3132```
3233
3334## Run the App
Original file line number Diff line number Diff line change 66from typing import Any , Literal
77
88import cocoindex
9- import requests
109import torch
1110from dotenv import load_dotenv
1211from fastapi import FastAPI , Query
2423CLIP_MODEL_DIMENSION = 768
2524
2625
27- def ollama_has_model (model ) -> bool :
28- try :
29- r = requests .get (f"{ OLLAMA_URL } /api/tags" , timeout = 1 )
30- r .raise_for_status ()
31- return any (m .get ("name" ) == model for m in r .json ().get ("models" , []))
32- except Exception :
33- return False
34-
35-
3626@functools .cache
3727def get_clip_model () -> tuple [CLIPModel , CLIPProcessor ]:
3828 model = CLIPModel .from_pretrained (CLIP_MODEL_NAME )
@@ -81,8 +71,8 @@ def image_object_embedding_flow(
8171 )
8272 img_embeddings = data_scope .add_collector ()
8373 with data_scope ["images" ].row () as img :
84- has_gemma3 = ollama_has_model ( OLLAMA_MODEL )
85- if has_gemma3 :
74+ has_ollama_model = os . getenv ( " OLLAMA_MODEL" ) == OLLAMA_MODEL
75+ if has_ollama_model :
8676 img ["caption" ] = flow_builder .transform (
8777 cocoindex .functions .ExtractByLlm (
8878 llm_spec = cocoindex .llm .LlmSpec (
@@ -115,7 +105,7 @@ def image_object_embedding_flow(
115105 "embedding" : img ["embedding" ],
116106 }
117107
118- if has_gemma3 :
108+ if has_ollama_model :
119109 print (
120110 f"Ollama model '{ OLLAMA_MODEL } ' is available — captions will be extracted."
121111 )
Original file line number Diff line number Diff line change @@ -11,7 +11,6 @@ dependencies = [
1111 " transformers>=4.29.0" ,
1212 " qdrant-client>=1.14.2" ,
1313 " uvicorn>=0.34.3" ,
14- " requests>=2.32.4" ,
1514]
1615
1716[tool .setuptools ]
You can’t perform that action at this time.
0 commit comments