Spaces:
Sleeping
Download README.md from upandit/mood-app-api-version: direct link, hf CLI and curl.
- Browser
- Download file 6 kB
-
https://huggingface.co/spaces/upandit/mood-app-api-version/resolve/main/README.md
- Command line
-
hf download hf://spaces/upandit/mood-app-api-version/README.md
-
curl -L -o README.md https://huggingface.co/spaces/upandit/mood-app-api-version/resolve/main/README.md
A newer version of the Gradio SDK is available: 6.33.0
title: Dual-Mode Mood App
emoji: π
colorFrom: blue
colorTo: purple
sdk: gradio
sdk_version: 4.19.2
app_file: app.py
pinned: false
π Dual-Mode Mood App - MLOps Case Study
A Gradio-based web application demonstrating key MLOps concepts by comparing local vs. remote AI model deployment strategies. Built for DS/CS553 β Machine Learning Development and Operations (MLOps) Case Study 1.
Live Demo on Hugging Face Spaces:
π https://huggingface.co/spaces/upandit/mood-app-api-version π
π Features
- Dual-Tab Interface: Compare two deployment paradigms in a single application.
- π Analyze Sentiment (Local Model): Runs a lightweight DistilBERT model locally on the CPU for fast, private sentiment analysis.
- π‘ Generate Positive Thought (API Model): Leverages a powerful remote model via Hugging Face's Inference API for generative tasks.
- Built-in Performance Metrics: Response times are displayed, providing immediate data for comparing local vs. API latency.
- Automated MLOps Pipeline: GitHub Actions automatically syncs code to Hugging Face Spaces on every commit.
π οΈ Technical Architecture
Models Used
| Task | Model | Framework | Deployment |
|---|---|---|---|
| Sentiment Analysis | distilbert-base-uncased-finetuned-sst-2-english |
Transformers | Local CPU |
| Text Generation | HuggingFaceTB/SmolLM3-3B |
Hugging Face Inference API | Remote API |
Tech Stack
- Frontend: Gradio
- ML Framework: Hugging Face Transformers
- API Client: Hugging Face Hub
- CI/CD & Sync: GitHub Actions
- Hosting: Hugging Face Spaces
π¦ Installation & Local Run
To run this application locally:
Clone the repository:
git clone https://github.com/Madargaach-Holdings/hugging_face_mood_app cd hugging_face_mood_appCreate and activate a virtual environment:
python -m venv .venv # On macOS/Linux: source .venv/bin/activate # On Windows (Command Prompt): .venv\Scripts\activate.bat # On Windows (PowerShell): .venv\Scripts\Activate.ps1Install dependencies:
pip install -r requirements.txtRun the application:
python app.pyThe application will be available at
http://127.0.0.1:7860.
π€ MLOps Automation
This project demonstrates automated MLOps practices:
- Continuous Deployment: The
.github/workflows/test-and-sync.ymlworkflow automatically pushes all changes from themainbranch of this repository to the connected Hugging Face Space. - Secrets Management: The Hugging Face write token is securely stored as a secret (
HF_TOKEN) in the GitHub repository settings, enabling secure authentication for the sync process.
π Key Findings & trade-offs
This project serves as a practical exploration of the trade-offs between different model deployment strategies:
| Aspect | Local Execution | Remote API |
|---|---|---|
| Latency | Fast (~1-2s). No network call. | Slower (~5-10s). Network latency + API queue time. |
| Cost | $0 operational cost after download. | Potential cost at scale; subject to API pricing tiers. |
| Reliability | High. No external dependencies. | Variable. Depends on API uptime and rate limits. |
| Scalability | Limited by host hardware (CPU). | High. Leverages Hugging Face's infrastructure. |
| Ease of Setup | Simple. pip install and run. |
Complex. Requires API knowledge, authentication, and handling HTTP errors. |
| Model Power | Limited to smaller, efficient models. | High. Access to very large, state-of-the-art models. |
π₯ Authors
π License
This project is open source and available under the MIT License.
Note: This project was created for educational purposes as part of the MLOps course at WPI.
π³ Case Study 3: Docker & Monitoring
This repo has been updated to run in Docker and expose Prometheus metrics for both the container and the Python app.
Images and Ports
- Container app (Gradio): internal
7860β host35001 - Python Prometheus metrics: internal
8000β host35002 - Node Exporter metrics: internal
9100β host35003
Claimed port range for Team 10: 35000-35010.
Build
docker build -t group10_mood_app:latest .
Run (replace HF_TOKEN accordingly)
docker run --rm \
-e HF_TOKEN=$HF_TOKEN \
-p 35001:7860 \
-p 35002:8000 \
-p 35003:9100 \
--name group10_mood_app \
group10_mood_app:latest
Verify Endpoints
- App UI:
http://<host>:35001 - Python metrics:
http://<host>:35002/metrics - Node Exporter:
http://<host>:35003/metrics
Ngrok (example)
ngrok http 35001 # expose Gradio UI
ngrok http 35002 # expose Python metrics (optional)
ngrok http 35003 # expose Node Exporter (optional)
Notes
app.pystarts the Prometheus client on port8000and instruments:- local/API request counters, error counters, latency summaries, local model loaded gauge
- The container also runs
prometheus-node-exporteron port9100.