ElderRyan commited on
Commit
91dcd62
Β·
verified Β·
1 Parent(s): 24dab39

Upload folder using huggingface_hub

Browse files
Files changed (1) hide show
  1. inference_example.py +93 -0
inference_example.py ADDED
@@ -0,0 +1,93 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ """
3
+ Inference example for Polyjuice MBTI model from Hugging Face
4
+
5
+ Since this is a custom Rust/PyTorch model, it cannot use HF Inference API.
6
+ Users need to download the model files and use the Rust binary for inference.
7
+
8
+ This script shows how to download and prepare for inference.
9
+ """
10
+
11
+ from huggingface_hub import hf_hub_download
12
+ import os
13
+ import subprocess
14
+ import json
15
+
16
+ def download_model(repo_id="ElderRyan/polyjuice", cache_dir="./model_cache"):
17
+ """Download model files from Hugging Face"""
18
+
19
+ print(f"Downloading model from {repo_id}...")
20
+
21
+ files_to_download = [
22
+ "mlp_weights_multitask.pt",
23
+ "tfidf_vectorizer_multitask.json",
24
+ "config.json"
25
+ ]
26
+
27
+ downloaded_paths = {}
28
+
29
+ for filename in files_to_download:
30
+ print(f" Downloading {filename}...")
31
+ path = hf_hub_download(
32
+ repo_id=repo_id,
33
+ filename=filename,
34
+ cache_dir=cache_dir
35
+ )
36
+ downloaded_paths[filename] = path
37
+ print(f" βœ“ Saved to: {path}")
38
+
39
+ return downloaded_paths
40
+
41
+ def show_usage():
42
+ """Show how to use the downloaded model"""
43
+
44
+ print("\n" + "="*60)
45
+ print("MODEL DOWNLOADED SUCCESSFULLY")
46
+ print("="*60)
47
+ print("\nThis is a Rust-based model. To use it:")
48
+ print("\n1. Clone the Rust project:")
49
+ print(" git clone https://github.com/RyanKung/polyjuice")
50
+ print(" cd polyjuice")
51
+ print("\n2. Copy downloaded model files:")
52
+ print(" mkdir -p models")
53
+ print(" cp <downloaded_path>/mlp_weights_multitask.pt models/")
54
+ print(" cp <downloaded_path>/tfidf_vectorizer_multitask.json models/")
55
+ print("\n3. Build and run:")
56
+ print(" cargo build --release")
57
+ print(" ./target/release/psycial hybrid predict \"Your text here\"")
58
+ print("\n" + "="*60)
59
+ print("\nAlternatively, use the web interface at:")
60
+ print("https://polyjuice.0xbase.ai")
61
+ print("="*60 + "\n")
62
+
63
+ def main():
64
+ print("\n╔═══════════════════════════════════════════════════════════╗")
65
+ print("β•‘ Polyjuice MBTI Classifier - Model Download β•‘")
66
+ print("β•šβ•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•\n")
67
+
68
+ # Download model
69
+ paths = download_model()
70
+
71
+ # Load and display config
72
+ with open(paths["config.json"], 'r') as f:
73
+ config = json.load(f)
74
+
75
+ print("\n" + "="*60)
76
+ print("MODEL INFORMATION")
77
+ print("="*60)
78
+ print(f"Model Type: {config.get('model_type', 'N/A')}")
79
+ print(f"Input Features: {config.get('input_features', 'N/A')}")
80
+ print(f"Architecture: {config.get('architecture', 'N/A')}")
81
+ print(f"\nAccuracy:")
82
+ acc = config.get('accuracy', {})
83
+ print(f" Overall: {acc.get('overall', 'N/A')}%")
84
+ print(f" E/I: {acc.get('e_i', 'N/A')}%")
85
+ print(f" S/N: {acc.get('s_n', 'N/A')}%")
86
+ print(f" T/F: {acc.get('t_f', 'N/A')}%")
87
+ print(f" J/P: {acc.get('j_p', 'N/A')}%")
88
+
89
+ show_usage()
90
+
91
+ if __name__ == "__main__":
92
+ main()
93
+