Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3aeaf3eaf0 | ||
|
|
5dbfba9a84 |
No files matched your search
+4
-4
@@ -1,4 +1,4 @@
|
|||||||
FROM debian:bullseye-slim AS builder
|
FROM debian:bookworm-slim AS builder
|
||||||
|
|
||||||
RUN apt-get update && apt-get install -y \
|
RUN apt-get update && apt-get install -y \
|
||||||
build-essential \
|
build-essential \
|
||||||
@@ -14,7 +14,7 @@ RUN mkdir build-docker \
|
|||||||
&& cmake -DCMAKE_BUILD_TYPE=Release .. \
|
&& cmake -DCMAKE_BUILD_TYPE=Release .. \
|
||||||
&& make -j$(nproc)
|
&& make -j$(nproc)
|
||||||
|
|
||||||
FROM debian:bullseye-slim
|
FROM debian:bookworm-slim
|
||||||
|
|
||||||
RUN apt-get update && apt-get install -y \
|
RUN apt-get update && apt-get install -y \
|
||||||
libstdc++6 \
|
libstdc++6 \
|
||||||
@@ -23,6 +23,6 @@ RUN apt-get update && apt-get install -y \
|
|||||||
|
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
COPY --from=builder /app/build-docker/fasttext_lid_server .
|
COPY --from=builder /app/build-docker/fasttext_lid_server .
|
||||||
COPY lid.176.ftz .
|
RUN curl --remote-name https://dl.fbaipublicfiles.com/fasttext/supervised-models/lid.176.bin
|
||||||
|
|
||||||
CMD ["sh", "-c", "./fasttext_lid_server ${MODEL_FILE:-lid.176.ftz} ${PORT:-8080}"]
|
CMD ["sh", "-c", "./fasttext_lid_server ${MODEL_FILE:-lid.176.bin} ${PORT:-8080}"]
|
||||||
@@ -1,3 +1,7 @@
|
|||||||
|
## This is a fork
|
||||||
|
|
||||||
|
Forked from [badlogic/fasttext-lid-server](https://github.com/badlogic/fasttext-lid-server/), this repository uses a newer debian version (bookworm), uses the [bigger model](https://fasttext.cc/docs/en/language-identification) (126MB) and gives you the top 3 results instead of only 1.
|
||||||
|
|
||||||
# FastText Language ID Server
|
# FastText Language ID Server
|
||||||
|
|
||||||
HTTP server that provides language identification using FastText models.
|
HTTP server that provides language identification using FastText models.
|
||||||
@@ -6,7 +10,7 @@ HTTP server that provides language identification using FastText models.
|
|||||||
|
|
||||||
```bash
|
```bash
|
||||||
# Pull and run
|
# Pull and run
|
||||||
docker run -p 8080:8080 mariozechner/fasttext-lid-server
|
docker run -p 8080:8080 suspiciousactivity/fasttext-lid-server
|
||||||
|
|
||||||
# Test
|
# Test
|
||||||
curl "http://localhost:8080/detect?text=Hello%20world"
|
curl "http://localhost:8080/detect?text=Hello%20world"
|
||||||
@@ -18,10 +22,20 @@ curl "http://localhost:8080/detect?text=Hello%20world"
|
|||||||
- **Parameter**: `text` (required)
|
- **Parameter**: `text` (required)
|
||||||
- **Response**: JSON with language code and probability
|
- **Response**: JSON with language code and probability
|
||||||
```json
|
```json
|
||||||
{
|
[
|
||||||
"language": "en",
|
{
|
||||||
"probability": 0.987
|
"language": "en",
|
||||||
}
|
"probability": 0.987
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"language": "de",
|
||||||
|
"probability": 0.234
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"language": "nl",
|
||||||
|
"probability": 0.123
|
||||||
|
}
|
||||||
|
]
|
||||||
```
|
```
|
||||||
- **Errors**:
|
- **Errors**:
|
||||||
- 400: Missing text parameter
|
- 400: Missing text parameter
|
||||||
@@ -32,14 +46,14 @@ curl "http://localhost:8080/detect?text=Hello%20world"
|
|||||||
### Using docker run
|
### Using docker run
|
||||||
```bash
|
```bash
|
||||||
# Default settings
|
# Default settings
|
||||||
docker run -p 8080:8080 mariozechner/fasttext-lid-server
|
docker run -p 8080:8080 suspiciousactivity/fasttext-lid-server
|
||||||
|
|
||||||
# Custom settings
|
# Custom settings
|
||||||
docker run -p 9000:9000 \
|
docker run -p 9000:9000 \
|
||||||
-e PORT=9000 \
|
-e PORT=9000 \
|
||||||
-e MODEL_FILE=/models/custom.ftz \
|
-e MODEL_FILE=/models/custom.ftz \
|
||||||
-v $(pwd)/models:/models \
|
-v $(pwd)/models:/models \
|
||||||
mariozechner/fasttext-lid-server
|
suspiciousactivity/fasttext-lid-server
|
||||||
```
|
```
|
||||||
|
|
||||||
### Using docker compose
|
### Using docker compose
|
||||||
@@ -48,7 +62,7 @@ version: '3.8'
|
|||||||
|
|
||||||
services:
|
services:
|
||||||
lid-server:
|
lid-server:
|
||||||
image: mariozechner/fasttext-lid-server
|
image: suspiciousactivity/fasttext-lid-server
|
||||||
ports:
|
ports:
|
||||||
- "${PORT:-8080}:${PORT:-8080}"
|
- "${PORT:-8080}:${PORT:-8080}"
|
||||||
environment:
|
environment:
|
||||||
|
|||||||
BIN
Binary file not shown.
@@ -33,7 +33,7 @@ int main(int argc, char *argv[]) {
|
|||||||
auto text = req.get_param_value("text");
|
auto text = req.get_param_value("text");
|
||||||
std::istringstream iss(text);
|
std::istringstream iss(text);
|
||||||
std::vector<std::pair<fasttext::real, std::string>> predictions;
|
std::vector<std::pair<fasttext::real, std::string>> predictions;
|
||||||
ft.predictLine(iss, predictions, 1, 0.0);
|
ft.predictLine(iss, predictions, 3, 0.0);
|
||||||
|
|
||||||
if (predictions.empty()) {
|
if (predictions.empty()) {
|
||||||
res.status = 500;
|
res.status = 500;
|
||||||
@@ -41,8 +41,21 @@ int main(int argc, char *argv[]) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string result = "{\"language\":\"" + stripLabel(predictions[0].second) +
|
std::string result = "[";
|
||||||
"\",\"probability\":" + std::to_string(predictions[0].first) + "}";
|
|
||||||
|
bool first = true;
|
||||||
|
for (const auto& prediction : predictions) {
|
||||||
|
std::string predictionResult = "{\"language\":\"" + stripLabel(prediction.second) +
|
||||||
|
"\",\"probability\":" + std::to_string(prediction.first) + "}";
|
||||||
|
if (!first) {
|
||||||
|
result += ",";
|
||||||
|
}
|
||||||
|
result += predictionResult;
|
||||||
|
first = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
result += "]";
|
||||||
|
|
||||||
res.set_content(result, "application/json");
|
res.set_content(result, "application/json");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
+2
-2
@@ -1,8 +1,8 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
version=1.0.3
|
version=1.0.4
|
||||||
image_name="mariozechner/fasttext-lid-server"
|
image_name="suspiciousactivity/fasttext-lid-server"
|
||||||
|
|
||||||
# Check git status
|
# Check git status
|
||||||
if [ -n "$(git status --porcelain)" ]; then
|
if [ -n "$(git status --porcelain)" ]; then
|
||||||
|
|||||||
Reference in new issue
Block a user