Spaces:
Sleeping
Sleeping
Upload 2 files
Browse files- README.md +66 -11
- requirements.txt +6 -0
README.md
CHANGED
|
@@ -1,11 +1,66 @@
|
|
| 1 |
-
---
|
| 2 |
-
title: Sentiment
|
| 3 |
-
emoji:
|
| 4 |
-
colorFrom:
|
| 5 |
-
colorTo:
|
| 6 |
-
sdk: docker
|
| 7 |
-
pinned: false
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
title: Sentiment Analysis API
|
| 3 |
+
emoji: 🎭
|
| 4 |
+
colorFrom: blue
|
| 5 |
+
colorTo: purple
|
| 6 |
+
sdk: docker
|
| 7 |
+
pinned: false
|
| 8 |
+
---
|
| 9 |
+
|
| 10 |
+
# Sentiment Analysis API
|
| 11 |
+
|
| 12 |
+
This Space provides a REST API for sentiment analysis using a fine-tuned transformer model.
|
| 13 |
+
|
| 14 |
+
## API Endpoints
|
| 15 |
+
|
| 16 |
+
- `GET /` - API information
|
| 17 |
+
- `GET /health` - Health check
|
| 18 |
+
- `POST /predict` - Analyze sentiment
|
| 19 |
+
- `GET /docs` - Interactive API documentation (Swagger UI)
|
| 20 |
+
|
| 21 |
+
## Usage Example
|
| 22 |
+
|
| 23 |
+
```bash
|
| 24 |
+
curl -X POST "https://YOUR-USERNAME-sentiment-api.hf.space/predict" \
|
| 25 |
+
-H "Content-Type: application/json" \
|
| 26 |
+
-d '{"text": "I love this product!"}'
|
| 27 |
+
```
|
| 28 |
+
|
| 29 |
+
Response:
|
| 30 |
+
```json
|
| 31 |
+
{
|
| 32 |
+
"sentiment": "positive",
|
| 33 |
+
"confidence": 0.9234
|
| 34 |
+
}
|
| 35 |
+
```
|
| 36 |
+
|
| 37 |
+
## Model
|
| 38 |
+
|
| 39 |
+
This API uses a sentiment classification model trained on [describe your dataset].
|
| 40 |
+
Model repository: [link to your model repo]
|
| 41 |
+
|
| 42 |
+
## Integration
|
| 43 |
+
|
| 44 |
+
You can call this API from any application:
|
| 45 |
+
|
| 46 |
+
```javascript
|
| 47 |
+
// JavaScript/TypeScript
|
| 48 |
+
fetch('https://YOUR-USERNAME-sentiment-api.hf.space/predict', {
|
| 49 |
+
method: 'POST',
|
| 50 |
+
headers: {'Content-Type': 'application/json'},
|
| 51 |
+
body: JSON.stringify({text: 'Hello world'})
|
| 52 |
+
})
|
| 53 |
+
.then(r => r.json())
|
| 54 |
+
.then(data => console.log(data));
|
| 55 |
+
```
|
| 56 |
+
|
| 57 |
+
```python
|
| 58 |
+
# Python
|
| 59 |
+
import requests
|
| 60 |
+
|
| 61 |
+
response = requests.post(
|
| 62 |
+
'https://YOUR-USERNAME-sentiment-api.hf.space/predict',
|
| 63 |
+
json={'text': 'Hello world'}
|
| 64 |
+
)
|
| 65 |
+
print(response.json())
|
| 66 |
+
```
|
requirements.txt
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
fastapi
|
| 2 |
+
uvicorn[standard]
|
| 3 |
+
torch
|
| 4 |
+
transformers
|
| 5 |
+
huggingface_hub
|
| 6 |
+
pydantic
|