Vu Anh Claude commited on
Commit
10d299f
·
1 Parent(s): 3715499

Clean up use_this_model.py to use only Hugging Face Hub

Browse files

- Remove local fallback, use only hf_hub_download
- Script now properly demonstrates model usage from published hub
- Model successfully downloads and works for Vietnamese text classification

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>

Files changed (1) hide show
  1. use_this_model.py +6 -27
use_this_model.py CHANGED
@@ -11,34 +11,13 @@ import numpy as np
11
 
12
  def load_model_from_hub():
13
  """Load the pre-trained model from Hugging Face Hub"""
14
- try:
15
- print("Downloading model from Hugging Face Hub...")
16
- model_path = hf_hub_download("undertheseanlp/sonar_core_1", "sklearn_model.joblib")
17
- print(f"Model downloaded to: {model_path}")
18
 
19
- print("Loading model...")
20
- model = joblib.load(model_path)
21
- return model
22
- except Exception as e:
23
- print(f"Error downloading from Hub: {e}")
24
- print("\nFalling back to local model for demonstration...")
25
-
26
- # Try to find local model
27
- from pathlib import Path
28
- runs_dir = Path("runs")
29
- if runs_dir.exists():
30
- run_dirs = [d for d in runs_dir.iterdir() if d.is_dir()]
31
- run_dirs.sort()
32
-
33
- for run_dir in reversed(run_dirs):
34
- models_dir = run_dir / "models"
35
- if models_dir.exists():
36
- for model_file in models_dir.glob("*.pkl"):
37
- if "VNTC" in model_file.name:
38
- print(f"Using local model: {model_file}")
39
- return joblib.load(model_file)
40
-
41
- raise FileNotFoundError("No model available. Please upload model to Hugging Face Hub or train locally.")
42
 
43
 
44
  def predict_vntc_examples(model):
 
11
 
12
  def load_model_from_hub():
13
  """Load the pre-trained model from Hugging Face Hub"""
14
+ print("Downloading model from Hugging Face Hub...")
15
+ model_path = hf_hub_download("undertheseanlp/sonar_core_1", "sklearn_model.joblib")
16
+ print(f"Model downloaded to: {model_path}")
 
17
 
18
+ print("Loading model...")
19
+ model = joblib.load(model_path)
20
+ return model
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
21
 
22
 
23
  def predict_vntc_examples(model):