Spaces:
Sleeping
Sleeping
Add Application files
Browse files- app.py +35 -3
- requirements.txt +41 -16
app.py
CHANGED
|
@@ -1,4 +1,36 @@
|
|
| 1 |
-
import
|
|
|
|
| 2 |
|
| 3 |
-
|
| 4 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio
|
| 2 |
+
from transformers import pipline
|
| 3 |
|
| 4 |
+
def merge_split_token(tokens):
|
| 5 |
+
merged = []
|
| 6 |
+
for token in tokens:
|
| 7 |
+
if token["word"].startswith('##'):
|
| 8 |
+
merged[-1]["word"] += token["word"][2:]
|
| 9 |
+
else:
|
| 10 |
+
merged.append(token)
|
| 11 |
+
|
| 12 |
+
return merged
|
| 13 |
+
def process_trans_text(text):
|
| 14 |
+
nlp=pipline("ner", model='KBLab/bert-base-swedish-cased-ner', tokenizer='KBLab/bert-base-swedish-cased-ner')
|
| 15 |
+
nlp_results = nlp(text)
|
| 16 |
+
print('nlp_results:', nlp_results)
|
| 17 |
+
|
| 18 |
+
nlp_results_merge = merge_split_token(nlp_results)
|
| 19 |
+
nlp_results_adjusted = map(lambda entity: dict(entity, **{ 'score': float(entity['score']) }), nlp_results_merge)
|
| 20 |
+
print('nlp_results_adjusted:', nlp_results_adjusted)
|
| 21 |
+
# Return values
|
| 22 |
+
return {'entities': list(nlp_results_adjusted)}
|
| 23 |
+
|
| 24 |
+
gradio_intreface = gradio.Interface(
|
| 25 |
+
fn=process_trans_text,
|
| 26 |
+
inputs="text",
|
| 27 |
+
output="text",
|
| 28 |
+
examples=[
|
| 29 |
+
["Jag heter Tom och bor i Stockholm."],
|
| 30 |
+
["Groens malmgård är en av Stockholms malmgårdar, belägen vid Malmgårdsvägen 53 på Södermalm i Stockholm."]
|
| 31 |
+
],
|
| 32 |
+
title="Entity Recognition",
|
| 33 |
+
description="Something text"
|
| 34 |
+
)
|
| 35 |
+
|
| 36 |
+
gradio_intreface.launch()
|
requirements.txt
CHANGED
|
@@ -1,44 +1,69 @@
|
|
|
|
|
| 1 |
altair==5.2.0
|
|
|
|
|
|
|
| 2 |
attrs==23.2.0
|
| 3 |
-
blinker==1.7.0
|
| 4 |
-
cachetools==5.3.2
|
| 5 |
certifi==2023.11.17
|
| 6 |
charset-normalizer==3.3.2
|
| 7 |
click==8.1.7
|
| 8 |
-
|
| 9 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
idna==3.6
|
| 11 |
-
importlib-
|
| 12 |
Jinja2==3.1.3
|
| 13 |
jsonschema==4.21.1
|
| 14 |
jsonschema-specifications==2023.12.1
|
|
|
|
| 15 |
markdown-it-py==3.0.0
|
| 16 |
MarkupSafe==2.1.4
|
|
|
|
| 17 |
mdurl==0.1.2
|
| 18 |
numpy==1.26.3
|
|
|
|
| 19 |
packaging==23.2
|
| 20 |
pandas==2.2.0
|
| 21 |
pillow==10.2.0
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
Pygments==2.17.2
|
|
|
|
| 26 |
python-dateutil==2.8.2
|
|
|
|
| 27 |
pytz==2023.3.post1
|
|
|
|
| 28 |
referencing==0.32.1
|
|
|
|
| 29 |
requests==2.31.0
|
| 30 |
rich==13.7.0
|
| 31 |
rpds-py==0.17.1
|
|
|
|
|
|
|
|
|
|
|
|
|
| 32 |
six==1.16.0
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
toolz==0.12.1
|
| 38 |
-
|
|
|
|
|
|
|
| 39 |
typing_extensions==4.9.0
|
| 40 |
tzdata==2023.4
|
| 41 |
-
tzlocal==5.2
|
| 42 |
urllib3==2.1.0
|
| 43 |
-
|
| 44 |
-
|
|
|
|
| 1 |
+
aiofiles==23.2.1
|
| 2 |
altair==5.2.0
|
| 3 |
+
annotated-types==0.6.0
|
| 4 |
+
anyio==4.2.0
|
| 5 |
attrs==23.2.0
|
|
|
|
|
|
|
| 6 |
certifi==2023.11.17
|
| 7 |
charset-normalizer==3.3.2
|
| 8 |
click==8.1.7
|
| 9 |
+
colorama==0.4.6
|
| 10 |
+
contourpy==1.2.0
|
| 11 |
+
cycler==0.12.1
|
| 12 |
+
fastapi==0.109.0
|
| 13 |
+
ffmpy==0.3.1
|
| 14 |
+
filelock==3.13.1
|
| 15 |
+
fonttools==4.47.2
|
| 16 |
+
fsspec==2023.12.2
|
| 17 |
+
gradio==4.15.0
|
| 18 |
+
gradio_client==0.8.1
|
| 19 |
+
h11==0.14.0
|
| 20 |
+
httpcore==1.0.2
|
| 21 |
+
httpx==0.26.0
|
| 22 |
+
huggingface-hub==0.20.3
|
| 23 |
idna==3.6
|
| 24 |
+
importlib-resources==6.1.1
|
| 25 |
Jinja2==3.1.3
|
| 26 |
jsonschema==4.21.1
|
| 27 |
jsonschema-specifications==2023.12.1
|
| 28 |
+
kiwisolver==1.4.5
|
| 29 |
markdown-it-py==3.0.0
|
| 30 |
MarkupSafe==2.1.4
|
| 31 |
+
matplotlib==3.8.2
|
| 32 |
mdurl==0.1.2
|
| 33 |
numpy==1.26.3
|
| 34 |
+
orjson==3.9.12
|
| 35 |
packaging==23.2
|
| 36 |
pandas==2.2.0
|
| 37 |
pillow==10.2.0
|
| 38 |
+
pydantic==2.5.3
|
| 39 |
+
pydantic_core==2.14.6
|
| 40 |
+
pydub==0.25.1
|
| 41 |
Pygments==2.17.2
|
| 42 |
+
pyparsing==3.1.1
|
| 43 |
python-dateutil==2.8.2
|
| 44 |
+
python-multipart==0.0.6
|
| 45 |
pytz==2023.3.post1
|
| 46 |
+
PyYAML==6.0.1
|
| 47 |
referencing==0.32.1
|
| 48 |
+
regex==2023.12.25
|
| 49 |
requests==2.31.0
|
| 50 |
rich==13.7.0
|
| 51 |
rpds-py==0.17.1
|
| 52 |
+
ruff==0.1.14
|
| 53 |
+
safetensors==0.4.2
|
| 54 |
+
semantic-version==2.10.0
|
| 55 |
+
shellingham==1.5.4
|
| 56 |
six==1.16.0
|
| 57 |
+
sniffio==1.3.0
|
| 58 |
+
starlette==0.35.1
|
| 59 |
+
tokenizers==0.15.1
|
| 60 |
+
tomlkit==0.12.0
|
| 61 |
toolz==0.12.1
|
| 62 |
+
tqdm==4.66.1
|
| 63 |
+
transformers==4.37.0
|
| 64 |
+
typer==0.9.0
|
| 65 |
typing_extensions==4.9.0
|
| 66 |
tzdata==2023.4
|
|
|
|
| 67 |
urllib3==2.1.0
|
| 68 |
+
uvicorn==0.27.0
|
| 69 |
+
websockets==11.0.3
|