tomsoderlund commited on
Commit
ac76be2
1 Parent(s): 478dcd7

process_swedish_text v2

Browse files
Files changed (2) hide show
  1. README.md +3 -2
  2. app.py +13 -4
README.md CHANGED
@@ -8,12 +8,13 @@ sdk_version: 3.12.0
8
  app_file: app.py
9
  pinned: false
10
  license: openrail
 
11
  ---
12
 
13
  # Swedish Entity Recognition
14
 
15
  Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
16
 
17
- ## REST API via Gradio
18
 
19
- curl -X POST -H 'Content-type: application/json' --data '{ "data": ["Mrs API"] }' https://tomsoderlund-swedish-entity-recognition.hf.space/run/predict
 
8
  app_file: app.py
9
  pinned: false
10
  license: openrail
11
+ models: ["KBLab/bert-base-swedish-cased-ner"]
12
  ---
13
 
14
  # Swedish Entity Recognition
15
 
16
  Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
17
 
18
+ ## REST API via Gradio “Use via API” (see page footer)
19
 
20
+ curl -X POST -H 'Content-type: application/json' --data '{ "data": ["Wirwachs malmgård är en på 1770-talet uppförd egendom som ligger på västra Södermalm i Stockholm."] }' https://tomsoderlund-swedish-entity-recognition.hf.space/run/predict
app.py CHANGED
@@ -1,7 +1,16 @@
1
  import gradio as gr
2
 
3
- def greet(name):
4
- return "Hello " + name + "!!"
 
 
5
 
6
- iface = gr.Interface(fn=greet, inputs="text", outputs="text")
7
- iface.launch()
 
 
 
 
 
 
 
 
1
  import gradio as gr
2
 
3
+ # Models from https://huggingface.co/models
4
+ # https://huggingface.co/KBLab/bert-base-swedish-cased-ner
5
+ ml_model = 'KBLab/bert-base-swedish-cased-ner'
6
+ ner_pipeline = pipeline(model=ml_model, task='ner')
7
 
8
+ def process_swedish_text(text):
9
+ pipeline_results = ner_pipeline(text)
10
+ print('NER results:', pipeline_results)
11
+ pipeline_results_adjusted = map(lambda entity: entity | { 'score': float(entity['score']) }, pipeline_results)
12
+ print(pipeline_results_adjusted)
13
+ return pipeline_results_adjusted
14
+
15
+ gradio_interface = gr.Interface(fn=process_swedish_text, inputs="text", outputs="JSON")
16
+ gradio_interface.launch()