Spaces:
Running
Running
New: Add Wheel
Browse files
app.py
CHANGED
|
@@ -112,7 +112,7 @@ def is_eng(review: str):
|
|
| 112 |
return lang_label[1] == "__label__en", lang_prob
|
| 113 |
|
| 114 |
### Do actual prediction #########################################################
|
| 115 |
-
@spaces.GPU(duration=
|
| 116 |
def predict(review: str):
|
| 117 |
|
| 118 |
review = (review or "").strip()
|
|
@@ -131,11 +131,134 @@ def predict(review: str):
|
|
| 131 |
prediction_flavours = predict_flavours(review, model_flavours, tokenizer_flavours, device)
|
| 132 |
t_end_flavours = time.time()
|
| 133 |
|
| 134 |
-
html_out = f"<b>{html.escape(review)}</b>"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 135 |
|
| 136 |
json_out = {
|
| 137 |
"review": review,
|
| 138 |
-
|
| 139 |
"device": device,
|
| 140 |
"duration": round((t_end_flavours - t_start_flavours), 3),
|
| 141 |
"is_en": {
|
|
@@ -143,9 +266,9 @@ def predict(review: str):
|
|
| 143 |
"prob": review_is_eng_prob
|
| 144 |
},
|
| 145 |
"results": [{
|
| 146 |
-
'icon': ICONS[name],
|
| 147 |
-
|
| 148 |
-
|
| 149 |
#'level': get_level(score)
|
| 150 |
}
|
| 151 |
for name, score in prediction_flavours.items()
|
|
|
|
| 112 |
return lang_label[1] == "__label__en", lang_prob
|
| 113 |
|
| 114 |
### Do actual prediction #########################################################
|
| 115 |
+
@spaces.GPU(duration=10) # Sekunden GPU-Zeit pro Call
|
| 116 |
def predict(review: str):
|
| 117 |
|
| 118 |
review = (review or "").strip()
|
|
|
|
| 131 |
prediction_flavours = predict_flavours(review, model_flavours, tokenizer_flavours, device)
|
| 132 |
t_end_flavours = time.time()
|
| 133 |
|
| 134 |
+
#html_out = f"<b>{html.escape(review)}</b>"
|
| 135 |
+
|
| 136 |
+
html_out = '''
|
| 137 |
+
<svg viewBox="0 0 500 500" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
|
| 138 |
+
|
| 139 |
+
<defs>
|
| 140 |
+
<path id="textPathU-68cfc5fd8ae1e" d="M 250, 250 m 0, 220 a -220,-220 0 1,1 0,-440 a -220,-220 0 1,1 0,440" style="stroke: red; fill: none;" />
|
| 141 |
+
<path id="textPathL-68cfc5fd8ae1e" d="M 250, 250 m 0, -220 a 220,220 0 1,0 0,440 a 220,220 0 1,0 0,-440" style="stroke: red; fill: none;" />
|
| 142 |
+
</defs>
|
| 143 |
+
|
| 144 |
+
<circle class="circle" r="40" cx="250" cy="250" style="stroke: black; fill: none;" />
|
| 145 |
+
<circle class="circle" r="80" cx="250" cy="250" style="stroke: black; fill: none;" />
|
| 146 |
+
<circle class="circle" r="120" cx="250" cy="250" style="stroke: black; fill: none;" />
|
| 147 |
+
<circle class="circle" r="160" cx="250" cy="250" style="stroke: black; fill: none;" />
|
| 148 |
+
<circle class="circle" r="200" cx="250" cy="250" style="stroke: black; fill: none;" />
|
| 149 |
+
|
| 150 |
+
<line class="line" x1="250" y1="210" x2="250" y2="50" style="stroke: black;" />
|
| 151 |
+
<line class="line" x1="278.28427124746" y1="221.71572875254" x2="391.42135623731" y2="108.57864376269" style="stroke: black;" />
|
| 152 |
+
<line class="line" x1="290" y1="250" x2="450" y2="250" style="stroke: black;" />
|
| 153 |
+
<line class="line" x1="278.28427124746" y1="278.28427124746" x2="391.42135623731" y2="391.42135623731" style="stroke: black;" />
|
| 154 |
+
<line class="line" x1="250" y1="290" x2="250" y2="450" style="stroke: black;" />
|
| 155 |
+
<line class="line" x1="221.71572875254" y1="278.28427124746" x2="108.57864376269" y2="391.42135623731" style="stroke: black;" />
|
| 156 |
+
<line class="line" x1="210" y1="250" x2="50" y2="250" style="stroke: black;" />
|
| 157 |
+
<line class="line" x1="221.71572875254" y1="221.71572875254" x2="108.57864376269" y2="108.57864376269" style="stroke: black;" />
|
| 158 |
+
|
| 159 |
+
<text text-anchor="middle" dy="0">
|
| 160 |
+
<textPath xlink:href="#textPathU-68cfc5fd8ae1e" startOffset="50%">
|
| 161 |
+
Grainy
|
| 162 |
+
</textPath>
|
| 163 |
+
</text>
|
| 164 |
+
|
| 165 |
+
<text text-anchor="middle" dy="0">
|
| 166 |
+
<textPath xlink:href="#textPathU-68cfc5fd8ae1e" startOffset="62.5%">
|
| 167 |
+
Grassy
|
| 168 |
+
</textPath>
|
| 169 |
+
</text>
|
| 170 |
+
|
| 171 |
+
<text text-anchor="middle" dy="0">
|
| 172 |
+
<textPath xlink:href="#textPathU-68cfc5fd8ae1e" startOffset="75%">
|
| 173 |
+
Fragrant
|
| 174 |
+
</textPath>
|
| 175 |
+
</text>
|
| 176 |
+
|
| 177 |
+
<text text-anchor="middle" dy="9px">
|
| 178 |
+
<textPath xlink:href="#textPathL-68cfc5fd8ae1e" startOffset="62.5%">
|
| 179 |
+
Fruity
|
| 180 |
+
</textPath>
|
| 181 |
+
</text>
|
| 182 |
+
|
| 183 |
+
<text text-anchor="middle" dy="9px">
|
| 184 |
+
<textPath xlink:href="#textPathL-68cfc5fd8ae1e" startOffset="50%">
|
| 185 |
+
Peaty
|
| 186 |
+
</textPath>
|
| 187 |
+
</text>
|
| 188 |
+
|
| 189 |
+
<text text-anchor="middle" dy="9px">
|
| 190 |
+
<textPath xlink:href="#textPathL-68cfc5fd8ae1e" startOffset="37.5%">
|
| 191 |
+
Woody
|
| 192 |
+
</textPath>
|
| 193 |
+
</text>
|
| 194 |
+
|
| 195 |
+
<text text-anchor="middle" dy="0">
|
| 196 |
+
<textPath xlink:href="#textPathU-68cfc5fd8ae1e" startOffset="25%">
|
| 197 |
+
Winey
|
| 198 |
+
</textPath>
|
| 199 |
+
</text>
|
| 200 |
+
|
| 201 |
+
<text text-anchor="middle" dy="0">
|
| 202 |
+
<textPath xlink:href="#textPathU-68cfc5fd8ae1e" startOffset="37.5%">
|
| 203 |
+
Off-Notes
|
| 204 |
+
</textPath>
|
| 205 |
+
</text>
|
| 206 |
+
|
| 207 |
+
<polyline class="graph" points></polyline>
|
| 208 |
+
|
| 209 |
+
<circle class="point" style="stroke: black; fill: white;" cx="250" cy="250" r="3.5" />
|
| 210 |
+
<circle class="point" style="stroke: black; fill: white;" cx="250" cy="250" r="3.5" />
|
| 211 |
+
<circle class="point" style="stroke: black; fill: white;" cx="250" cy="250" r="3.5" />
|
| 212 |
+
<circle class="point" style="stroke: black; fill: white;" cx="250" cy="250" r="3.5" />
|
| 213 |
+
<circle class="point" style="stroke: black; fill: white;" cx="250" cy="250" r="3.5" />
|
| 214 |
+
<circle class="point" style="stroke: black; fill: white;" cx="250" cy="250" r="3.5" />
|
| 215 |
+
<circle class="point" style="stroke: black; fill: white;" cx="250" cy="250" r="3.5" />
|
| 216 |
+
<circle class="point" style="stroke: black; fill: white;" cx="250" cy="250" r="3.5" />
|
| 217 |
+
|
| 218 |
+
</svg>
|
| 219 |
+
|
| 220 |
+
<script>
|
| 221 |
+
const setPoints = function (vals) {
|
| 222 |
+
|
| 223 |
+
const elemsPoint = document.querySelectorAll('.point');
|
| 224 |
+
const elemGraph = document.querySelector('.graph');
|
| 225 |
+
|
| 226 |
+
const points = [];
|
| 227 |
+
|
| 228 |
+
elemsPoint.forEach(function(elemPoint, i) {
|
| 229 |
+
// steps offset convert to bogenmass
|
| 230 |
+
const angle = (360 / config.segments * i + config.offsetAngle - 90) * (Math.PI * 2 / 360);
|
| 231 |
+
|
| 232 |
+
const val = vals[i];
|
| 233 |
+
|
| 234 |
+
const c = {
|
| 235 |
+
x: Math.cos(angle) * (val * config.inputRatio + config.innerRadius) + config.offsetCenter,
|
| 236 |
+
y: Math.sin(angle) * (val * config.inputRatio + config.innerRadius) + config.offsetCenter
|
| 237 |
+
}
|
| 238 |
+
|
| 239 |
+
points.push(`${c.x},${c.y}`);
|
| 240 |
+
|
| 241 |
+
elemGraph.setAttribute('points', points.join(' '));
|
| 242 |
+
|
| 243 |
+
elemPoint.setAttribute('cx', `${c.x}`);
|
| 244 |
+
elemPoint.setAttribute('cy', `${c.y}`);
|
| 245 |
+
});
|
| 246 |
+
}
|
| 247 |
+
|
| 248 |
+
const config = {
|
| 249 |
+
segments: 8,
|
| 250 |
+
offsetAngle: 0,
|
| 251 |
+
innerRadius: 40,
|
| 252 |
+
offsetCenter: 250,
|
| 253 |
+
inputRatio: 16
|
| 254 |
+
};
|
| 255 |
+
|
| 256 |
+
setPoints([0, 1, 1.5, 0, 2, 0, 3.4, 2])
|
| 257 |
+
'''
|
| 258 |
|
| 259 |
json_out = {
|
| 260 |
"review": review,
|
| 261 |
+
"model": FILENAME,
|
| 262 |
"device": device,
|
| 263 |
"duration": round((t_end_flavours - t_start_flavours), 3),
|
| 264 |
"is_en": {
|
|
|
|
| 266 |
"prob": review_is_eng_prob
|
| 267 |
},
|
| 268 |
"results": [{
|
| 269 |
+
#'icon': ICONS[name],
|
| 270 |
+
"name": name,
|
| 271 |
+
"score": score,
|
| 272 |
#'level': get_level(score)
|
| 273 |
}
|
| 274 |
for name, score in prediction_flavours.items()
|