thien1892 commited on
Commit
22dfa3a
1 Parent(s): c0e2b23

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +26 -5
README.md CHANGED
@@ -24,12 +24,33 @@ model-index:
24
  This is a trained model of a **Q-Learning** agent playing **Taxi-v3** .
25
 
26
  ## Usage
27
-
28
  ```python
29
-
30
- model = load_from_hub(repo_id="thien1892/taxi-v3", filename="q-learning.pkl")
 
 
 
 
 
 
 
 
 
 
 
 
31
 
32
- # Don't forget to check if you need to add additional attributes (is_slippery=False etc)
33
- env = gym.make(model["env_id"])
 
 
34
  ```
 
 
 
 
 
 
 
35
 
 
24
  This is a trained model of a **Q-Learning** agent playing **Taxi-v3** .
25
 
26
  ## Usage
27
+ 1. Load model
28
  ```python
29
+ from urllib.error import HTTPError
30
+ from huggingface_hub import hf_hub_download
31
+
32
+ def load_from_hub(repo_id: str, filename: str) -> str:
33
+ """
34
+ Download a model from Hugging Face Hub.
35
+ :param repo_id: id of the model repository from the Hugging Face Hub
36
+ :param filename: name of the model zip file from the repository
37
+ """
38
+ # Get the model from the Hub, download and cache the model on your local disk
39
+ pickle_model = hf_hub_download(
40
+ repo_id=repo_id,
41
+ filename=filename
42
+ )
43
 
44
+ with open(pickle_model, 'rb') as f:
45
+ downloaded_model_file = pickle.load(f)
46
+
47
+ return downloaded_model_file
48
  ```
49
+ 2. Evaluate model
50
+ ```
51
+ model = load_from_hub(repo_id="thien1892/q-taxi-v3", filename="q-learning.pkl") # Try to use another model
52
+ print(model)
53
+ env = gym.make(model["env_id"])
54
+ evaluate_agent(env, model["max_steps"], model["n_eval_episodes"], model["qtable"], model["eval_seed"])
55
+ ```
56