File size: 3,291 Bytes
ecab5c0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# Project Progress Log

This document tracks the step-by-step process of creating and deploying the Simple Sentiment Analyzer application.

## 1. Prerequisites & Initial Setup

- **Goal:** Build and deploy a sentiment analysis web application using Hugging Face.
- **Accounts:** A new Hugging Face account was created and verified via email. A GitHub account was already available.
- **Tools:** Confirmed that `python` and `git` were installed locally on the Ubuntu system.

## 2. Local Project Initialization

- **Directory:** Created a project directory named `sentiment-app`.
- **Dependency Management:** Chose to use `Poetry` for modern Python package and environment management.
- **Poetry Setup:**
    - Initialized the project with `poetry init`, creating the `pyproject.toml` configuration file.
    - Added the required libraries (`transformers`, `torch`, and `gradio`) using the `poetry add` command. This automatically created a virtual environment and installed the dependencies.

## 3. Application Development

- **Main Application (`app.py`):**
    - Created the `app.py` file.
    - Wrote the Python code to load a pre-trained sentiment analysis model using the `transformers` pipeline.
    - Wrote a function `analyze_sentiment` to process user input and return the model's prediction.
    - Built a web user interface using `Gradio`, creating a title, description, and a simple textbox input/output.

- **Deployment Dependencies (`requirements.txt`):**
    - To ensure compatibility with Hugging Face Spaces, a `requirements.txt` file was generated from the Poetry environment using the `poetry export` command.

## 4. Local Testing

- **Execution:** The application was run locally from the terminal using `poetry run python app.py`.
- **Verification:** The Gradio server started successfully. The application was accessed via a local URL (`http://127.0.0.1:7860`) in a web browser.
- **Functionality Check:** Tested the app with both positive and negative sentences to confirm it was working as expected.
- **Shutdown:** The local server was stopped gracefully using `Ctrl+C` in the terminal.

## 5. Deployment to Hugging Face Spaces

- **Git Initialization:** The project was already a Git repository. New files (`app.py`, `pyproject.toml`, `poetry.lock`, `requirements.txt`) were staged with `git add` and committed with `git commit`.

- **Space Creation:**
    - A new "Space" was created on the Hugging Face website.
    - The Space was configured with the `Gradio` SDK.

- **Connecting Local to Remote:**
    - The new Hugging Face Space's Git URL was added as a remote to the local repository under the name `huggingface` (`git remote add ...`).

- **First Push & Reconciliation:**
    - The initial `git push huggingface main` failed due to the remote Space having its own initial commit (with a `README.md` file), causing "divergent histories".
    - This was resolved by pulling the remote changes first using `git pull huggingface main --allow-unrelated-histories`. This merged the remote's `README.md` into the local project.

- **Documentation:**
    - The default `README.md` was updated with a detailed description of the project, its technologies, and usage instructions.
    - This `PROGRESS.md` file was created to document the project's entire lifecycle.