mr-kush commited on
Commit
0b7394e
·
verified ·
1 Parent(s): 81343bf

fix the runtime error

Browse files
Files changed (1) hide show
  1. app.py +5 -32
app.py CHANGED
@@ -4,47 +4,24 @@ from typing import Union, List
4
  from predict_dept_model import DepartmentPredictor
5
  from contextlib import asynccontextmanager
6
  from response_schema import ClassificationOutput, TextInput
7
- from huggingface_hub import scan_cache_dir, HfApi
 
 
 
8
 
9
  # hf api
10
  api = HfApi()
11
 
12
- def clear_hf_cache(model_repo: str) -> None:
13
- """
14
- Clears the Hugging Face model cache for the specified repository.
15
-
16
- Args:
17
- model_repo (str): The model repository identifier (e.g., 'mr-kush/sambodhan-department-classification-model').
18
- """
19
- # Scan the cache directory
20
- cache_info = scan_cache_dir()
21
-
22
- # Find the repository in the cache
23
- repo_info = next((repo for repo in cache_info.cached_repos if repo.repo_id == model_repo), None)
24
-
25
- if repo_info:
26
- # Delete all revisions of the repository
27
- delete_strategy = cache_info.delete_revisions(*repo_info.revisions)
28
- print(f"Will free {delete_strategy.expected_freed_size_str}")
29
- delete_strategy.execute()
30
- print("Cache deletion done.")
31
- else:
32
- print(f"Repository '{model_repo}' not found in cache.")
33
-
34
-
35
 
36
 
37
  # Setting up startup and shutdown logic
38
  @asynccontextmanager
39
  async def lifespan(app: FastAPI):
40
-
41
- # Clear the Hugging Face model cache
42
- clear_hf_cache("mr-kush/sambodhan-department-classification-model")
43
-
44
  # Load the model
45
  global predictor
46
  predictor = DepartmentPredictor()
47
  yield
 
48
 
49
  app = FastAPI(
50
  title="Sambodhan Department Classifier API",
@@ -71,10 +48,6 @@ def predict_department(input_data: TextInput):
71
 
72
  @app.get("/")
73
  def root():
74
- # Define the model repository ID
75
- model_repo = "mr-kush/sambodhan-department-classification-model"
76
-
77
-
78
  # Fetch the latest commit hash (revision) from the model repository
79
  latest_tag = api.list_repo_refs(repo_id=model_repo, repo_type="model").tags[0].name
80
 
 
4
  from predict_dept_model import DepartmentPredictor
5
  from contextlib import asynccontextmanager
6
  from response_schema import ClassificationOutput, TextInput
7
+ from huggingface_hub import HfApi
8
+
9
+ # Define the model repository ID
10
+ model_repo = "mr-kush/sambodhan-department-classification-model"
11
 
12
  # hf api
13
  api = HfApi()
14
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
15
 
16
 
17
  # Setting up startup and shutdown logic
18
  @asynccontextmanager
19
  async def lifespan(app: FastAPI):
 
 
 
 
20
  # Load the model
21
  global predictor
22
  predictor = DepartmentPredictor()
23
  yield
24
+
25
 
26
  app = FastAPI(
27
  title="Sambodhan Department Classifier API",
 
48
 
49
  @app.get("/")
50
  def root():
 
 
 
 
51
  # Fetch the latest commit hash (revision) from the model repository
52
  latest_tag = api.list_repo_refs(repo_id=model_repo, repo_type="model").tags[0].name
53