diff --git a/offline_tasks/scripts/a.py b/offline_tasks/scripts/a.py new file mode 100644 index 0000000..b5e53fe --- /dev/null +++ b/offline_tasks/scripts/a.py @@ -0,0 +1,36 @@ +from modelscope import AutoProcessor, Gemma3nForConditionalGeneration +from PIL import Image +import requests +import torch +model_id = "google/gemma-3n-e4b-it" +model = Gemma3nForConditionalGeneration.from_pretrained(model_id, device_map="auto", torch_dtype=torch.bfloat16,).eval() +processor = AutoProcessor.from_pretrained(model_id) +messages = [ + { + "role": "system", + "content": [{"type": "text", "text": "You are a helpful assistant."}] + }, + { + "role": "user", + "content": [ + {"type": "image", "image": "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/bee.jpg"}, + {"type": "text", "text": "Describe this image in detail."} + ] + } +] +inputs = processor.apply_chat_template( + messages, + add_generation_prompt=True, + tokenize=True, + return_dict=True, + return_tensors="pt", +).to(model.device) +input_len = inputs["input_ids"].shape[-1] +with torch.inference_mode(): + generation = model.generate(**inputs, max_new_tokens=100, do_sample=False) + generation = generation[0][input_len:] +decoded = processor.decode(generation, skip_special_tokens=True) +print(decoded) +# **Overall Impression:** The image is a close-up shot of a vibrant garden scene, +# focusing on a cluster of pink cosmos flowers and a busy bumblebee. +# It has a slightly soft, natural feel, likely captured in daylight. \ No newline at end of file diff --git a/offline_tasks/scripts/load_index_to_redis.py b/offline_tasks/scripts/load_index_to_redis.py index 34b3810..ed26f6d 100644 --- a/offline_tasks/scripts/load_index_to_redis.py +++ b/offline_tasks/scripts/load_index_to_redis.py @@ -51,6 +51,15 @@ def load_index_file(file_path, redis_client, key_prefix, expire_seconds=None): # 格式2 (3字段): item_id \t item_name \t similar_items (推荐格式) # 取第一个字段作为key,最后一个字段作为value key_suffix = parts[0] + + # 修复:将浮点数ID转换为整数(如 "60678.0" -> "60678") + try: + if '.' in key_suffix: + key_suffix = str(int(float(key_suffix))) + except (ValueError, OverflowError): + # 如果转换失败,保持原样 + pass + value = parts[-1] redis_key = f"{key_prefix}:{key_suffix}" -- libgit2 0.21.2