Spaces:
Build error
Build error
updated /predict description
Browse files
app.py
CHANGED
|
@@ -61,14 +61,23 @@ async def index():
|
|
| 61 |
@app.post("/predict", tags=["Machine Learning"])
|
| 62 |
async def predict(predictionFeatures: PredictionFeatures):
|
| 63 |
"""
|
| 64 |
-
|
| 65 |
-
The input is a string with the sentence to be predicted
|
| 66 |
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
|
| 71 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 72 |
|
| 73 |
url = "https://llepogam-hate-speech-detection-api.hf.space/predict"
|
| 74 |
headers = {
|
|
@@ -76,11 +85,13 @@ async def predict(predictionFeatures: PredictionFeatures):
|
|
| 76 |
"Content-Type": "application/json"
|
| 77 |
}
|
| 78 |
|
| 79 |
-
|
| 80 |
-
"Text": text
|
| 81 |
}
|
| 82 |
|
| 83 |
-
|
|
|
|
|
|
|
| 84 |
"""
|
| 85 |
|
| 86 |
# Convert input into a DataFrame
|
|
|
|
| 61 |
@app.post("/predict", tags=["Machine Learning"])
|
| 62 |
async def predict(predictionFeatures: PredictionFeatures):
|
| 63 |
"""
|
| 64 |
+
Predict whether the provided text contains hate speech.
|
|
|
|
| 65 |
|
| 66 |
+
### Input
|
| 67 |
+
- `predictionFeatures` (PredictionFeatures): An object containing the text to be analyzed.
|
| 68 |
+
- The input text is provided as a string.
|
| 69 |
|
| 70 |
+
### Output
|
| 71 |
+
Returns a dictionary with the following keys:
|
| 72 |
+
- `prediction` (str): Indicates whether the text is "offensive" or "not offensive".
|
| 73 |
+
- `probability` (float): A value between 0 and 1, representing the likelihood of hate speech.
|
| 74 |
+
- Texts with a probability >= 0.5 are classified as "offensive".
|
| 75 |
+
|
| 76 |
+
### Example Usage
|
| 77 |
+
To use this endpoint, send a POST request as follows:
|
| 78 |
+
|
| 79 |
+
```python
|
| 80 |
+
import requests
|
| 81 |
|
| 82 |
url = "https://llepogam-hate-speech-detection-api.hf.space/predict"
|
| 83 |
headers = {
|
|
|
|
| 85 |
"Content-Type": "application/json"
|
| 86 |
}
|
| 87 |
|
| 88 |
+
data = {
|
| 89 |
+
"Text": "your text here"
|
| 90 |
}
|
| 91 |
|
| 92 |
+
response = requests.post(url, headers=headers, json=data)
|
| 93 |
+
print(response.json())
|
| 94 |
+
```
|
| 95 |
"""
|
| 96 |
|
| 97 |
# Convert input into a DataFrame
|