Spaces:
Build error
Build error
call the preprocess api in the prediction
Browse files
app.py
CHANGED
|
@@ -5,6 +5,7 @@ from pydantic import BaseModel
|
|
| 5 |
from typing import Literal, List, Union
|
| 6 |
from fastapi import FastAPI, File, UploadFile
|
| 7 |
import joblib
|
|
|
|
| 8 |
|
| 9 |
description = """
|
| 10 |
Welcome to this offensive speech detection API.
|
|
@@ -99,8 +100,24 @@ async def predict(predictionFeatures: PredictionFeatures):
|
|
| 99 |
```
|
| 100 |
"""
|
| 101 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 102 |
# Convert input into a DataFrame
|
| 103 |
-
list_text = [
|
| 104 |
|
| 105 |
# Load model from MLflow
|
| 106 |
logged_model = 'runs:/227d2f8e431d40d6b5231add3a00d048/hate_speech_detection'
|
|
@@ -137,7 +154,28 @@ async def predict(preprocessingFeatures: PreprocessingFeatures):
|
|
| 137 |
### Output
|
| 138 |
Returns a dictionary with the following keys:
|
| 139 |
- `tweet` (str): Initial tweet.
|
| 140 |
-
- `text_clean` (str): Preprocessed tweets after removal of punctation and stop words and text lemmatization
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 141 |
|
| 142 |
"""
|
| 143 |
|
|
|
|
| 5 |
from typing import Literal, List, Union
|
| 6 |
from fastapi import FastAPI, File, UploadFile
|
| 7 |
import joblib
|
| 8 |
+
import requests
|
| 9 |
|
| 10 |
description = """
|
| 11 |
Welcome to this offensive speech detection API.
|
|
|
|
| 100 |
```
|
| 101 |
"""
|
| 102 |
|
| 103 |
+
|
| 104 |
+
|
| 105 |
+
#Call the API
|
| 106 |
+
url = "https://llepogam-hate-speech-detection-api.hf.space/preprocess"
|
| 107 |
+
headers = {
|
| 108 |
+
"accept": "application/json",
|
| 109 |
+
"Content-Type": "application/json"
|
| 110 |
+
}
|
| 111 |
+
|
| 112 |
+
data_to_preprocessed = {
|
| 113 |
+
"tweet": predictionFeatures.Text
|
| 114 |
+
}
|
| 115 |
+
|
| 116 |
+
response = requests.post(url, headers=headers, json=data_to_preprocessed)
|
| 117 |
+
|
| 118 |
+
|
| 119 |
# Convert input into a DataFrame
|
| 120 |
+
list_text = [response.json()['text_clean']['0']]
|
| 121 |
|
| 122 |
# Load model from MLflow
|
| 123 |
logged_model = 'runs:/227d2f8e431d40d6b5231add3a00d048/hate_speech_detection'
|
|
|
|
| 154 |
### Output
|
| 155 |
Returns a dictionary with the following keys:
|
| 156 |
- `tweet` (str): Initial tweet.
|
| 157 |
+
- `text_clean` (str): Preprocessed tweets after removal of punctation and stop words and text lemmatization.
|
| 158 |
+
|
| 159 |
+
### Example Usage
|
| 160 |
+
To use this endpoint, send a POST request as follows:
|
| 161 |
+
|
| 162 |
+
```python
|
| 163 |
+
import requests
|
| 164 |
+
|
| 165 |
+
url = "https://llepogam-hate-speech-detection-api.hf.space/preprocess"
|
| 166 |
+
headers = {
|
| 167 |
+
"accept": "application/json",
|
| 168 |
+
"Content-Type": "application/json"
|
| 169 |
+
}
|
| 170 |
+
|
| 171 |
+
data = {
|
| 172 |
+
"tweet": "@user this is the tweet which i want to preprocess ! #machinelearning #prediction"
|
| 173 |
+
}
|
| 174 |
+
|
| 175 |
+
response = requests.post(url, headers=headers, json=data)
|
| 176 |
+
print(response.json())
|
| 177 |
+
```
|
| 178 |
+
|
| 179 |
|
| 180 |
"""
|
| 181 |
|