Keira commited on
Commit Β·
b646cf8
1
Parent(s): b1312fc
Add application file
Browse files- .DS_Store +0 -0
- app.py +64 -68
- readthis.md +117 -0
.DS_Store
CHANGED
|
Binary files a/.DS_Store and b/.DS_Store differ
|
|
|
app.py
CHANGED
|
@@ -11,85 +11,81 @@ html = """
|
|
| 11 |
<head>
|
| 12 |
<title>Sentiment Checker</title>
|
| 13 |
<style>
|
| 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 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
background: #ff4fa3;
|
| 71 |
-
}
|
| 72 |
-
|
| 73 |
-
/* Result text */
|
| 74 |
-
#result {
|
| 75 |
-
margin-top: 25px;
|
| 76 |
-
font-size: 20px;
|
| 77 |
-
color: white;
|
| 78 |
-
}
|
| 79 |
</style>
|
| 80 |
</head>
|
|
|
|
| 81 |
<body>
|
| 82 |
<h2>Sentiment Checker</h2>
|
|
|
|
| 83 |
<div class="search-box">
|
| 84 |
-
|
| 85 |
-
|
|
|
|
|
|
|
| 86 |
<p id="result"></p>
|
| 87 |
-
|
| 88 |
<script>
|
| 89 |
async function send() {
|
| 90 |
const text = document.getElementById("text").value;
|
| 91 |
const res = await fetch(`/predict?text=${encodeURIComponent(text)}`);
|
| 92 |
const data = await res.json();
|
|
|
|
| 93 |
document.getElementById("result").innerText =
|
| 94 |
data[0].label + " (" + data[0].score.toFixed(2) + ")";
|
| 95 |
}
|
|
|
|
| 11 |
<head>
|
| 12 |
<title>Sentiment Checker</title>
|
| 13 |
<style>
|
| 14 |
+
body {
|
| 15 |
+
margin: 0;
|
| 16 |
+
height: 100vh;
|
| 17 |
+
display: flex;
|
| 18 |
+
flex-direction: column;
|
| 19 |
+
align-items: center;
|
| 20 |
+
justify-content: center;
|
| 21 |
+
|
| 22 |
+
background: linear-gradient(135deg, #ff9ecb, #ffcce6, #ffe6f2);
|
| 23 |
+
font-family: Arial, sans-serif;
|
| 24 |
+
}
|
| 25 |
+
|
| 26 |
+
h2 {
|
| 27 |
+
font-size: 48px;
|
| 28 |
+
margin-bottom: 30px;
|
| 29 |
+
color: white;
|
| 30 |
+
}
|
| 31 |
+
|
| 32 |
+
.search-box {
|
| 33 |
+
display: flex;
|
| 34 |
+
align-items: center;
|
| 35 |
+
background: white;
|
| 36 |
+
border-radius: 50px;
|
| 37 |
+
padding: 10px 15px;
|
| 38 |
+
width: min(500px, 90vw);
|
| 39 |
+
box-shadow: 0 4px 20px rgba(0,0,0,0.1);
|
| 40 |
+
}
|
| 41 |
+
|
| 42 |
+
.search-box input {
|
| 43 |
+
border: none;
|
| 44 |
+
outline: none;
|
| 45 |
+
flex: 1;
|
| 46 |
+
font-size: 16px;
|
| 47 |
+
padding: 10px;
|
| 48 |
+
}
|
| 49 |
+
|
| 50 |
+
.search-box button {
|
| 51 |
+
border: none;
|
| 52 |
+
background: #ff69b4;
|
| 53 |
+
color: white;
|
| 54 |
+
padding: 10px 18px;
|
| 55 |
+
border-radius: 25px;
|
| 56 |
+
cursor: pointer;
|
| 57 |
+
font-weight: bold;
|
| 58 |
+
}
|
| 59 |
+
|
| 60 |
+
.search-box button:hover {
|
| 61 |
+
background: #ff4fa3;
|
| 62 |
+
}
|
| 63 |
+
|
| 64 |
+
#result {
|
| 65 |
+
margin-top: 20px;
|
| 66 |
+
font-size: 22px;
|
| 67 |
+
color: white;
|
| 68 |
+
text-align: center;
|
| 69 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 70 |
</style>
|
| 71 |
</head>
|
| 72 |
+
|
| 73 |
<body>
|
| 74 |
<h2>Sentiment Checker</h2>
|
| 75 |
+
|
| 76 |
<div class="search-box">
|
| 77 |
+
<input id="text" placeholder="Type something..." />
|
| 78 |
+
<button onclick="send()">Check</button>
|
| 79 |
+
</div>
|
| 80 |
+
|
| 81 |
<p id="result"></p>
|
| 82 |
+
|
| 83 |
<script>
|
| 84 |
async function send() {
|
| 85 |
const text = document.getElementById("text").value;
|
| 86 |
const res = await fetch(`/predict?text=${encodeURIComponent(text)}`);
|
| 87 |
const data = await res.json();
|
| 88 |
+
|
| 89 |
document.getElementById("result").innerText =
|
| 90 |
data[0].label + " (" + data[0].score.toFixed(2) + ")";
|
| 91 |
}
|
readthis.md
ADDED
|
@@ -0,0 +1,117 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
# Sentiment Checker (Docker + Hugging Face Spaces)
|
| 3 |
+
|
| 4 |
+
A minimal interactive web app that performs sentiment analysis using a Hugging Face model.
|
| 5 |
+
Users can type text, click a button, and instantly receive a prediction.
|
| 6 |
+
|
| 7 |
+
---
|
| 8 |
+
|
| 9 |
+
## π Live Concept
|
| 10 |
+
|
| 11 |
+
- Type text into a box
|
| 12 |
+
- Click **Check**
|
| 13 |
+
- Get sentiment (POSITIVE / NEGATIVE)
|
| 14 |
+
|
| 15 |
+
---
|
| 16 |
+
|
| 17 |
+
## π§ Why This Project Exists
|
| 18 |
+
|
| 19 |
+
Machine learning apps often fail to run across different environments due to:
|
| 20 |
+
- dependency conflicts
|
| 21 |
+
- mismatched library versions
|
| 22 |
+
- complex setup requirements
|
| 23 |
+
|
| 24 |
+
This project demonstrates how Docker solves these issues and enables seamless deployment on Hugging Face Spaces.
|
| 25 |
+
|
| 26 |
+
---
|
| 27 |
+
|
| 28 |
+
## π§° Tech Stack
|
| 29 |
+
|
| 30 |
+
- Python
|
| 31 |
+
- FastAPI
|
| 32 |
+
- Transformers (by Hugging Face)
|
| 33 |
+
- Docker
|
| 34 |
+
|
| 35 |
+
---
|
| 36 |
+
|
| 37 |
+
## π Project Structure
|
| 38 |
+
|
| 39 |
+
```
|
| 40 |
+
|
| 41 |
+
.
|
| 42 |
+
βββ app.py
|
| 43 |
+
βββ requirements.txt
|
| 44 |
+
βββ Dockerfile
|
| 45 |
+
|
| 46 |
+
````
|
| 47 |
+
|
| 48 |
+
---
|
| 49 |
+
|
| 50 |
+
## βοΈ How It Works
|
| 51 |
+
|
| 52 |
+
1. The frontend is a simple HTML page served by FastAPI
|
| 53 |
+
2. User input is sent to the `/predict` endpoint
|
| 54 |
+
3. A pre-trained sentiment model processes the text
|
| 55 |
+
4. The result is returned and displayed instantly
|
| 56 |
+
|
| 57 |
+
---
|
| 58 |
+
|
| 59 |
+
## π³ Docker Setup
|
| 60 |
+
|
| 61 |
+
### Build the image
|
| 62 |
+
```bash
|
| 63 |
+
docker build -t sentiment-app .
|
| 64 |
+
````
|
| 65 |
+
|
| 66 |
+
### Run the container
|
| 67 |
+
|
| 68 |
+
```bash
|
| 69 |
+
docker run -p 7860:7860 sentiment-app
|
| 70 |
+
```
|
| 71 |
+
|
| 72 |
+
Then open: [http://localhost:7860](http://localhost:7860)
|
| 73 |
+
|
| 74 |
+
---
|
| 75 |
+
|
| 76 |
+
## π€ Deployment (Hugging Face Spaces)
|
| 77 |
+
|
| 78 |
+
This app is designed to run on Hugging Face Spaces using Docker.
|
| 79 |
+
|
| 80 |
+
Steps:
|
| 81 |
+
|
| 82 |
+
1. Create a new Space
|
| 83 |
+
2. Select **Docker** as the SDK
|
| 84 |
+
3. Upload project files
|
| 85 |
+
4. The app will automatically build and deploy
|
| 86 |
+
|
| 87 |
+
---
|
| 88 |
+
|
| 89 |
+
## π‘ Why Docker Matters
|
| 90 |
+
|
| 91 |
+
Without Docker:
|
| 92 |
+
|
| 93 |
+
* Manual installation of dependencies
|
| 94 |
+
* Version conflicts (e.g., Torch, Transformers)
|
| 95 |
+
* Inconsistent results across machines
|
| 96 |
+
|
| 97 |
+
With Docker:
|
| 98 |
+
|
| 99 |
+
* Reproducible environment
|
| 100 |
+
* One-step deployment
|
| 101 |
+
* Works the same everywhere
|
| 102 |
+
|
| 103 |
+
---
|
| 104 |
+
|
| 105 |
+
## β οΈ Notes
|
| 106 |
+
|
| 107 |
+
* The first run may take longer due to model download
|
| 108 |
+
* Subsequent requests are much faster
|
| 109 |
+
|
| 110 |
+
---
|
| 111 |
+
|
| 112 |
+
## β
Key Takeaway
|
| 113 |
+
|
| 114 |
+
Docker enables reliable, reproducible deployment of machine learning applications, making it easy to share and run apps on platforms like Hugging Face Spaces without additional setup.
|
| 115 |
+
|
| 116 |
+
```
|
| 117 |
+
|