Spaces:
Sleeping
Sleeping
Update model load to download it from huggingface repo if doesnt exists. Also update readme
Browse files- .env.example +2 -1
- README.md +27 -4
- a3c/play.py +9 -3
- requirements.txt +1 -0
.env.example
CHANGED
@@ -1,7 +1,8 @@
|
|
|
|
|
|
1 |
RS_FIREBASE_CREDENTIALS_PATH = 'firebase-credentials.json'
|
2 |
RS_WORDLE_USER = '[email protected]'
|
3 |
RS_WORDLE_URL = 'http://localhost:3000'
|
4 |
RS_WORDLE_MODEL_NAME = 'the_best_ai_model_saved.pth'
|
5 |
RS_WORDLE_PASSWORD = 'myemailpassword'
|
6 |
-
FLASK_DEBUG = 'true'
|
7 |
SECRET_KEY = 'asecretkey4flask'
|
|
|
1 |
+
FLASK_DEBUG = 'true'
|
2 |
+
HF_MODEL_REPO_NAME = "org/repo_name"
|
3 |
RS_FIREBASE_CREDENTIALS_PATH = 'firebase-credentials.json'
|
4 |
RS_WORDLE_USER = '[email protected]'
|
5 |
RS_WORDLE_URL = 'http://localhost:3000'
|
6 |
RS_WORDLE_MODEL_NAME = 'the_best_ai_model_saved.pth'
|
7 |
RS_WORDLE_PASSWORD = 'myemailpassword'
|
|
|
8 |
SECRET_KEY = 'asecretkey4flask'
|
README.md
CHANGED
@@ -1,3 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
# Wordle Solver with RL
|
2 |
|
3 |
A model that solves Wordle using reinforcement learning
|
@@ -12,7 +23,7 @@ And then, on the project root, execute:
|
|
12 |
|
13 |
`pip install -r requirements.txt`
|
14 |
|
15 |
-
## Running and execution modes
|
16 |
To run the program, on the project root execute:
|
17 |
|
18 |
`python main.py [ENV][MODE] [PARAMETERS]`
|
@@ -68,20 +79,32 @@ For word suggestion, run:
|
|
68 |
* a 2 if the letter was in the word and in the correct position
|
69 |
* --model_name [MODEL_NAME] --> Name of the pretrained model file which will play the game
|
70 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
71 |
## Make the model play RS-Wordle alone!
|
72 |
It is possible to make the model play the Rootstrap version of Wordle. To do that, you need to:
|
73 |
|
74 |
* Have a Rootstrap mail account
|
75 |
* Get access to the Firebase database of the RS-Wordle instance and a private key obtained from the Service accounts Project Setting. This is for authentication and has to be stored as a JSON file.
|
76 |
-
* Use a pre-trained model that will play the game
|
|
|
|
|
77 |
|
78 |
-
Then, you need to
|
79 |
|
80 |
```
|
81 |
RS_FIREBASE_CREDENTIALS_PATH=path/to/private_key.json
|
82 |
RS_WORDLE_USER=rootstrap_mail_user
|
83 |
RS_WORDLE_URL=rs_wordle_instance_url
|
84 |
-
RS_WORDLE_MODEL_NAME=pretrained_model_path
|
85 |
RS_WORDLE_PASSWORD=rootstrap_mail_password
|
86 |
```
|
87 |
|
|
|
1 |
+
---
|
2 |
+
title: Wordle Solver
|
3 |
+
emoji: 🔠
|
4 |
+
colorFrom: green
|
5 |
+
colorTo: yellow
|
6 |
+
sdk: streamlit
|
7 |
+
sdk_version: 1.25.0
|
8 |
+
pinned: false
|
9 |
+
app_file: streamlit.py
|
10 |
+
---
|
11 |
+
|
12 |
# Wordle Solver with RL
|
13 |
|
14 |
A model that solves Wordle using reinforcement learning
|
|
|
23 |
|
24 |
`pip install -r requirements.txt`
|
25 |
|
26 |
+
## CLI Running and execution modes
|
27 |
To run the program, on the project root execute:
|
28 |
|
29 |
`python main.py [ENV][MODE] [PARAMETERS]`
|
|
|
79 |
* a 2 if the letter was in the word and in the correct position
|
80 |
* --model_name [MODEL_NAME] --> Name of the pretrained model file which will play the game
|
81 |
|
82 |
+
## Play Wordle with the help of an AI using Streamlit
|
83 |
+
To run a Streamlit app to play wordle with the help of an AI assistant you need to:
|
84 |
+
|
85 |
+
* Have a pretrained model that knows how to play wordle:
|
86 |
+
1. You need to create a `.env` file in the project root with `RS_WORDLE_MODEL_NAME` property.
|
87 |
+
2. Download the pretrained model and put it under `checkpoints` dir, to do that you have two options:
|
88 |
+
* **Option 1**: Download it manually from our [Huggingface repo](https://huggingface.co/rootstrap-org/wordle-solver).
|
89 |
+
* **Option 2**: Let it download automatically by setting an `HF_MODEL_REPO_NAME` property with value `rootstrap-org/wordle-solver` in the `.env` file. You have to be authenticated in huggingface with huggingface_cli to do that.
|
90 |
+
3. Set the `RS_WORDLE_MODEL_NAME` property in `.env` with the model filename.
|
91 |
+
* Run the app by executing `streamlit run streamlit.py`
|
92 |
+
|
93 |
## Make the model play RS-Wordle alone!
|
94 |
It is possible to make the model play the Rootstrap version of Wordle. To do that, you need to:
|
95 |
|
96 |
* Have a Rootstrap mail account
|
97 |
* Get access to the Firebase database of the RS-Wordle instance and a private key obtained from the Service accounts Project Setting. This is for authentication and has to be stored as a JSON file.
|
98 |
+
* Use a pre-trained model that will play the game, and put it under `checkpoints` dir, to do that you have two options:
|
99 |
+
* **Option 1**: Download it manually from our [Huggingface repo](https://huggingface.co/rootstrap-org/wordle-solver).
|
100 |
+
* **Option 2**: Let it download automatically by setting an `HF_MODEL_REPO_NAME` property with value `rootstrap-org/wordle-solver` in the `.env` file. You have to be authenticated in Huggingface with huggingface_cli to do that.
|
101 |
|
102 |
+
Then, you need to add to the .env file the following properties:
|
103 |
|
104 |
```
|
105 |
RS_FIREBASE_CREDENTIALS_PATH=path/to/private_key.json
|
106 |
RS_WORDLE_USER=rootstrap_mail_user
|
107 |
RS_WORDLE_URL=rs_wordle_instance_url
|
|
|
108 |
RS_WORDLE_PASSWORD=rootstrap_mail_password
|
109 |
```
|
110 |
|
a3c/play.py
CHANGED
@@ -2,6 +2,7 @@ import os
|
|
2 |
|
3 |
import torch
|
4 |
from dotenv import load_dotenv
|
|
|
5 |
|
6 |
from wordle_env.state import update_from_mask
|
7 |
|
@@ -10,12 +11,13 @@ from .utils import v_wrap
|
|
10 |
|
11 |
load_dotenv()
|
12 |
|
13 |
-
|
|
|
|
|
14 |
|
15 |
|
16 |
def get_play_model_path():
|
17 |
-
|
18 |
-
return os.path.join(model_checkpoint_dir, PLAY_MODEL_NAME)
|
19 |
|
20 |
|
21 |
def get_net(env, pretrained_model_path):
|
@@ -24,6 +26,10 @@ def get_net(env, pretrained_model_path):
|
|
24 |
words_list = env.words
|
25 |
word_width = len(env.words[0])
|
26 |
net = GreedyNet(n_s, n_a, words_list, word_width)
|
|
|
|
|
|
|
|
|
27 |
net.load_state_dict(torch.load(pretrained_model_path))
|
28 |
return net
|
29 |
|
|
|
2 |
|
3 |
import torch
|
4 |
from dotenv import load_dotenv
|
5 |
+
from huggingface_hub import hf_hub_download
|
6 |
|
7 |
from wordle_env.state import update_from_mask
|
8 |
|
|
|
11 |
|
12 |
load_dotenv()
|
13 |
|
14 |
+
MODEL_NAME = os.getenv("RS_WORDLE_MODEL_NAME")
|
15 |
+
HF_MODEL_REPO_NAME = os.getenv("HF_MODEL_REPO_NAME")
|
16 |
+
MODEL_CHECKPOINT_DIR = "checkpoints"
|
17 |
|
18 |
|
19 |
def get_play_model_path():
|
20 |
+
return os.path.join(MODEL_CHECKPOINT_DIR, MODEL_NAME)
|
|
|
21 |
|
22 |
|
23 |
def get_net(env, pretrained_model_path):
|
|
|
26 |
words_list = env.words
|
27 |
word_width = len(env.words[0])
|
28 |
net = GreedyNet(n_s, n_a, words_list, word_width)
|
29 |
+
if not os.path.exists(pretrained_model_path):
|
30 |
+
pretrained_model_path = hf_hub_download(
|
31 |
+
HF_MODEL_REPO_NAME, MODEL_NAME, local_dir=MODEL_CHECKPOINT_DIR
|
32 |
+
)
|
33 |
net.load_state_dict(torch.load(pretrained_model_path))
|
34 |
return net
|
35 |
|
requirements.txt
CHANGED
@@ -5,6 +5,7 @@ Flask-Cors==3.0.10
|
|
5 |
Flask-Static-Digest==0.2.1
|
6 |
gunicorn==20.1.0
|
7 |
gym==0.21.0
|
|
|
8 |
matplotlib==3.6.3
|
9 |
python-dotenv==1.0.0
|
10 |
selenium==4.8.2
|
|
|
5 |
Flask-Static-Digest==0.2.1
|
6 |
gunicorn==20.1.0
|
7 |
gym==0.21.0
|
8 |
+
huggingface_hub
|
9 |
matplotlib==3.6.3
|
10 |
python-dotenv==1.0.0
|
11 |
selenium==4.8.2
|