chienweichang commited on
Commit
d118bab
1 Parent(s): f4286ee

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +3 -5
app.py CHANGED
@@ -3,13 +3,11 @@ from pydantic import BaseModel
3
  from typing import List
4
  from transformers import AutoTokenizer, AutoModel
5
  import torch
6
- import os
7
 
8
  class EmbeddingModel:
9
  def __init__(self, model_name="intfloat/multilingual-e5-large"):
10
- cache_dir = os.getenv("MODEL_CACHE_DIR", "./model_cache")
11
- self.tokenizer = AutoTokenizer.from_pretrained(model_name, cache_dir=cache_dir)
12
- self.model = AutoModel.from_pretrained(model_name, cache_dir=cache_dir)
13
 
14
  def get_embedding(self, text):
15
  inputs = self.tokenizer(text, return_tensors="pt", padding=True, truncation=True, max_length=512)
@@ -52,4 +50,4 @@ async def create_embeddings(request: EmbeddingRequest):
52
  "total_tokens": sum(len(text.split()) for text in request.input)
53
  }
54
  )
55
- return response
 
3
  from typing import List
4
  from transformers import AutoTokenizer, AutoModel
5
  import torch
 
6
 
7
  class EmbeddingModel:
8
  def __init__(self, model_name="intfloat/multilingual-e5-large"):
9
+ self.tokenizer = AutoTokenizer.from_pretrained(model_name)
10
+ self.model = AutoModel.from_pretrained(model_name)
 
11
 
12
  def get_embedding(self, text):
13
  inputs = self.tokenizer(text, return_tensors="pt", padding=True, truncation=True, max_length=512)
 
50
  "total_tokens": sum(len(text.split()) for text in request.input)
51
  }
52
  )
53
+ return response