spanish-classifier-tfg/spanish-tweet-classifier
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)
cd ${HOME}/devClone the app repo from HF spaces:
git clone https://huggingface.co/spaces/spanish-classifier-tfg/spanish-tweet-classifierPython 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:
cd $HOMENow 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
brew update
brew install pyenvThen, for the Zsh, execute in the terminal:
echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.zshrc
echo 'command -v pyenv >/dev/null || export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.zshrc
echo 'eval "$(pyenv init -)"' >> ~/.zshrcThen 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:
pyenv versionsThis 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
pyenv localThis 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:
pyenv globalLet's install a new specific global version. We will use it later in this project with Poetry:
pyenv install 3.9.12Now 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:
pyenv versionShould 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:
pyenv global 3.9.12
pyenv local 3.9.12Doing 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:
python --version
pyenv versionshould output 3.9.12
In the same way:
pyenv versionsshould output something similar to:
system
3.6.0
* 3.9.12 (set by /Users/fperez/dev/spanish-tweet-classifier/.python-version)
anaconda3-4.3.0Now 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
Virtual environments with Poetry
Install poetry:
curl -sSL https://install.python-poetry.org | python3 -Add poetry to your PATH env variable:
$HOME/.local/binecho 'export PATH="$PATH:$HOME/.local/bin"' >> ~/.zshrcRestart the terminal!
When back, let's show the poetry version:
poetry --versionshould show you something like 1.4.0. Now poetry is working.
Install dependencies with poetry
Go to the project directory:
cd ~/dev/spanish-tweet-classifierActivate the shell, which in turn will create a Python virtual environment for the project.
poetry shellAs 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:
poetry install --with devAll the dependencies for the project will be included in the .venv created by the command above.
poetry env listshould show something like:
.venv (Activated)and the command
which python3should show something like:;
/Users/fperez/.pyenv/shims/python3VSCode with poetry
Once the project has been configured with the virtual environment, you can use it (and you should) also in VSCode.
Steps:
- Close VSCode (just in case you had the project window already open)
- In the project directory (e.g.
~/dev/spanish-tweet-classifier), execute the command:
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/activateExecute 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:
- Go to the root directory of the project
cd ~/dev/spanish-tweet-classifier- If you have open a new terminal, be sure that you are in a poetry shell! Otherwise activate it with:
poetry shell- Launch the showcase app with streamlit
poetry run streamlit run showcase_app.py- The previous command should launch a browser windown pointing to http://localhost:8501 and you should be able to play with the app!
- In the terminal, you can stop the local web server started by streamlit pressing
CTRL+C
