cogniveon commited on
Commit
9a43384
1 Parent(s): 15c5cc8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +3 -24
app.py CHANGED
@@ -5,29 +5,7 @@ pipe = pipeline("token-classification", model="cogniveon/nlpcw_bert-base-uncased
5
 
6
  def predict(input) -> list[tuple[str, str | float | None]] | dict | None:
7
  output = pipe(input)
8
- entities = []
9
-
10
- # Collect entities with their start and end positions
11
- for entity in output:
12
- entities.append({
13
- "entity": entity["entity_group"],
14
- "word": entity["word"],
15
- "score": round(entity["score"], 4),
16
- "start": entity["start"],
17
- "end": entity["end"]
18
- })
19
-
20
- highlighted_text = [(input[:entities[0]['start']], None)] # Initial text before the first entity
21
-
22
- # Generate highlighted text segments
23
- for i, entity in enumerate(entities):
24
- highlighted_text.append((input[entity['start']:entity['end']], entity['entity']))
25
- if i < len(entities) - 1:
26
- highlighted_text.append((input[entity['end']:entities[i+1]['start']], None))
27
- else:
28
- highlighted_text.append((input[entity['end']:], None)) # Remaining text after the last entity
29
-
30
- return highlighted_text
31
 
32
 
33
  demo = gr.Interface(
@@ -44,4 +22,5 @@ demo = gr.Interface(
44
  examples=[
45
  ["We developed a variant of gene set enrichment analysis (GSEA) to determine whether a genetic pathway shows evidence for age regulation [23]."],
46
  ],
47
- ).launch()
 
 
5
 
6
  def predict(input) -> list[tuple[str, str | float | None]] | dict | None:
7
  output = pipe(input)
8
+ return {"text": input, "entities": output}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9
 
10
 
11
  demo = gr.Interface(
 
22
  examples=[
23
  ["We developed a variant of gene set enrichment analysis (GSEA) to determine whether a genetic pathway shows evidence for age regulation [23]."],
24
  ],
25
+ flagging_callback=gr.CSVLogger()
26
+ ).launch(debug=True)