Spaces:
Runtime error
Runtime error
Commit
·
98314f0
1
Parent(s):
9cb5903
str() not JSON
Browse files
app.py
CHANGED
@@ -1,19 +1,18 @@
|
|
1 |
import gradio as gr
|
2 |
from transformers import pipeline
|
3 |
-
import json
|
4 |
|
5 |
def process_swedish_text(text):
|
6 |
# Models from https://huggingface.co/models
|
7 |
# https://huggingface.co/KBLab/bert-base-swedish-cased-ner
|
8 |
nlp = pipeline('ner', model='KBLab/bert-base-swedish-cased-ner', tokenizer='KBLab/bert-base-swedish-cased-ner')
|
9 |
# Run NER
|
10 |
-
|
11 |
-
print('
|
12 |
# Fix TypeError("'numpy.float32' object is not iterable")
|
13 |
-
|
14 |
-
print(
|
15 |
# Return values
|
16 |
-
return
|
17 |
|
18 |
gradio_interface = gr.Interface(fn=process_swedish_text, inputs="text", outputs="json")
|
19 |
gradio_interface.launch()
|
|
|
1 |
import gradio as gr
|
2 |
from transformers import pipeline
|
|
|
3 |
|
4 |
def process_swedish_text(text):
|
5 |
# Models from https://huggingface.co/models
|
6 |
# https://huggingface.co/KBLab/bert-base-swedish-cased-ner
|
7 |
nlp = pipeline('ner', model='KBLab/bert-base-swedish-cased-ner', tokenizer='KBLab/bert-base-swedish-cased-ner')
|
8 |
# Run NER
|
9 |
+
nlp_results = nlp(text)
|
10 |
+
print('nlp_results:', nlp_results)
|
11 |
# Fix TypeError("'numpy.float32' object is not iterable")
|
12 |
+
nlp_results_adjusted = map(lambda entity: entity | { 'score': float(entity['score']) }, nlp_results)
|
13 |
+
print('nlp_results_adjusted:', nlp_results_adjusted)
|
14 |
# Return values
|
15 |
+
return str({'entities': list(nlp_results_adjusted)})
|
16 |
|
17 |
gradio_interface = gr.Interface(fn=process_swedish_text, inputs="text", outputs="json")
|
18 |
gradio_interface.launch()
|