|
--- |
|
title: Spanish Tweet Classifier |
|
emoji: 😻 |
|
colorFrom: yellow |
|
colorTo: red |
|
sdk: streamlit |
|
sdk_version: 1.20.0 |
|
app_file: showcase_app.py |
|
pinned: false |
|
license: apache-2.0 |
|
--- |
|
|
|
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference |
|
|
|
|
|
# Development Instructions |
|
|
|
## Clone this project |
|
|
|
Go to the directory where you store your `dev` projects (e.g. `dev`) |
|
|
|
```sh |
|
cd ${HOME}/dev |
|
``` |
|
|
|
Clone the app repo from HF spaces: |
|
```sh |
|
git clone https://huggingface.co/spaces/spanish-classifier-tfg/spanish-tweet-classifier |
|
``` |
|
|
|
## Python environment management with Pyenv |
|
|
|
To avoid the problems of Python versions, lets use the `pyenv` tool. |
|
|
|
Before we start, let's go to our $HOME directory: |
|
```sh |
|
cd $HOME |
|
``` |
|
Now you shoud be in your root directory, e.g. `/Users/fperez` (You can check the current directory where you are with the command `pwd`) |
|
|
|
Then, let's update `brew` and install `pyenv` |
|
```sh |
|
brew update |
|
brew install pyenv |
|
``` |
|
|
|
Then, for the Zsh, execute in the terminal: |
|
```sh |
|
echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.zshrc |
|
echo 'command -v pyenv >/dev/null || export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.zshrc |
|
echo 'eval "$(pyenv init -)"' >> ~/.zshrc |
|
``` |
|
|
|
Then restart the terminal to allow the previous changes to work!!! |
|
|
|
If you executed the previous steps correctly, now you would be able to show all the python available versions at this time with `pyenv` lets execute: |
|
|
|
```sh |
|
pyenv versions |
|
``` |
|
|
|
This will show us something like this: |
|
``` |
|
system |
|
3.6.0 |
|
* anaconda3-4.3.0 (set by /Users/fperez/.python-version) |
|
``` |
|
|
|
Let's show the local Python version with `pyenv`, which should be the same shown when executing `python --version` |
|
```sh |
|
pyenv local |
|
``` |
|
This should show your current local active version of Python. In my case shows the Python version corresponding to the * shown above (anaconda3-4.3.0 which corresponds to Python version 3.6.0) |
|
|
|
Same applies for the global version: |
|
```sh |
|
pyenv global |
|
``` |
|
|
|
Let's install a new specific global version. We will use it later in this project with Poetry: |
|
```sh |
|
pyenv install 3.9.12 |
|
``` |
|
|
|
Now the 3.9.12 version of Python should be installed but not set as a default neither as local nor global Python versions yet. Let's check this: |
|
|
|
```sh |
|
pyenv version |
|
``` |
|
Should still show us the previous version present in your system (the same one as shown above for the `pyenv local`, 3.6.0 in my case). |
|
|
|
Let's set 3.9.12 as the default version: |
|
|
|
```sh |
|
pyenv global 3.9.12 |
|
pyenv local 3.9.12 |
|
``` |
|
|
|
Doing this, sets the global version in the file `~/.pyenv/version` and the local version in `~/.python-version` both to 3.9.12 (you can check the content of these files with `cat ~/.pyenv/version` and `cat `~/.python-version`). |
|
|
|
So, now: |
|
```sh |
|
python --version |
|
pyenv version |
|
``` |
|
should output `3.9.12` |
|
|
|
In the same way: |
|
```sh |
|
pyenv versions |
|
``` |
|
should output something similar to: |
|
``` |
|
system |
|
3.6.0 |
|
* 3.9.12 (set by /Users/fperez/dev/spanish-tweet-classifier/.python-version) |
|
anaconda3-4.3.0 |
|
``` |
|
|
|
Now the problem with Python versions should be solved in your Mac! If you start a new terminal, |
|
the `python --version` command should show `3.9.12`. Check it out by opening a new terminal! |
|
|
|
Find more info about pyenv [here](https://realpython.com/intro-to-pyenv/) |
|
|
|
## Virtual environments with Poetry |
|
|
|
Install [poetry](https://python-poetry.org/docs/): |
|
```sh |
|
curl -sSL https://install.python-poetry.org | python3 - |
|
``` |
|
|
|
Add poetry to your PATH env variable: |
|
```sh |
|
$HOME/.local/bin |
|
``` |
|
```sh |
|
echo 'export PATH="$PATH:$HOME/.local/bin"' >> ~/.zshrc |
|
``` |
|
|
|
Restart the terminal! |
|
|
|
When back, let's show the poetry version: |
|
```sh |
|
poetry --version |
|
``` |
|
should show you something like `1.4.0`. Now poetry is working. |
|
|
|
### Install dependencies with poetry |
|
|
|
Go to the project directory: |
|
```sh |
|
cd ~/dev/spanish-tweet-classifier |
|
``` |
|
|
|
Activate the shell, which in turn will create a Python virtual environment for the project. |
|
``` |
|
poetry shell |
|
``` |
|
|
|
As the poetry project has been configured to create a virtual environemnt in the project itself (see the contents |
|
of the `poetry.toml` file), this command will create a `.venv` directory in the root directory of the project. |
|
|
|
Install the project dependencies: |
|
```sh |
|
poetry install --with dev |
|
``` |
|
|
|
All the dependencies for the project will be included in the `.venv` created by the command above. |
|
|
|
```sh |
|
poetry env list |
|
``` |
|
should show something like: |
|
``` |
|
.venv (Activated) |
|
``` |
|
and the command |
|
```sh |
|
which python3 |
|
``` |
|
should show something like:; |
|
``` |
|
/Users/fperez/.pyenv/shims/python3 |
|
``` |
|
|
|
### VSCode with poetry |
|
|
|
Once the project has been configured with the virtual environment, you can use it (and you should) also in VSCode. |
|
|
|
Steps: |
|
|
|
1. Close VSCode (just in case you had the project window already open) |
|
2. In the project directory (e.g. `~/dev/spanish-tweet-classifier`), execute the command: |
|
```sh |
|
code . |
|
``` |
|
|
|
Then a new window for the project should appear in VSCode. When selecting a Python file it should show in the |
|
lower right part of the IDE the Python version 3.9.12 and the active virtual environment ('.venv': poetry). |
|
|
|
**NOTE:** If the `.venv` virtual enviroment is not activated by default, activate it manually in VSCode using `CMD+Shift+P` and selecting the Python interpreter from the `.venv` directory in the project. |
|
|
|
Also if you open a terminal in VSCode, the virtual environment should be detected and something similar to the |
|
following should appear in the terminal: |
|
``` |
|
source /Users/fperez/dev/spanish-tweet-classifier/.venv/bin/activate |
|
``` |
|
|
|
## Execute the showcase app locally in your laptop! |
|
|
|
After all the previous steps have been done, now you should be able to execute the application locally. All the dependencies for this app should be working so: |
|
|
|
1. Go to the root directory of the project |
|
```sh |
|
cd ~/dev/spanish-tweet-classifier |
|
``` |
|
2. If you have open a new terminal, be sure that you are in a poetry shell! Otherwise activate it with: |
|
```sh |
|
poetry shell |
|
``` |
|
3. Launch the showcase app with streamlit |
|
```sh |
|
poetry run streamlit run showcase_app.py |
|
``` |
|
4. The previous command should launch a browser windown pointing to [http://localhost:8501](http://localhost:8581) and you should be able to play with the app! |
|
5. In the terminal, you can stop the local web server started by streamlit pressing `CTRL+C` |