christophalt commited on
Commit
03f1ac5
1 Parent(s): 864a486

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -14
app.py CHANGED
@@ -3,9 +3,10 @@ import gradio as gr
3
  from dataclasses import dataclass
4
  from prettytable import PrettyTable
5
 
6
- from pytorch_ie import AnnotationList, BinaryRelation, Span, LabeledSpan, Pipeline, TextDocument, annotation_field
7
- from pytorch_ie.models import TransformerSpanClassificationModel, TransformerTextClassificationModel
8
- from pytorch_ie.taskmodules import TransformerSpanClassificationTaskModule, TransformerRETextClassificationTaskModule
 
9
 
10
  from typing import List
11
 
@@ -16,17 +17,11 @@ class ExampleDocument(TextDocument):
16
  relations: AnnotationList[BinaryRelation] = annotation_field(target="entities")
17
 
18
 
19
- model_name_or_path = "pie/example-ner-spanclf-conll03"
20
- ner_taskmodule = TransformerSpanClassificationTaskModule.from_pretrained(model_name_or_path)
21
- ner_model = TransformerSpanClassificationModel.from_pretrained(model_name_or_path)
22
 
23
- ner_pipeline = Pipeline(model=ner_model, taskmodule=ner_taskmodule, device=-1, num_workers=0)
24
-
25
- model_name_or_path = "pie/example-re-textclf-tacred"
26
- re_taskmodule = TransformerRETextClassificationTaskModule.from_pretrained(model_name_or_path)
27
- re_model = TransformerTextClassificationModel.from_pretrained(model_name_or_path)
28
-
29
- re_pipeline = Pipeline(model=re_model, taskmodule=re_taskmodule, device=-1, num_workers=0)
30
 
31
 
32
  def predict(text):
@@ -57,7 +52,10 @@ def predict(text):
57
 
58
  iface = gr.Interface(
59
  fn=predict,
60
- inputs="textbox",
 
 
 
61
  outputs="html",
62
  )
63
  iface.launch()
 
3
  from dataclasses import dataclass
4
  from prettytable import PrettyTable
5
 
6
+ from pytorch_ie.annotations import LabeledSpan, BinaryRelation
7
+ from pytorch_ie.auto import AutoPipeline
8
+ from pytorch_ie.core import AnnotationList, annotation_field
9
+ from pytorch_ie.documents import TextDocument
10
 
11
  from typing import List
12
 
 
17
  relations: AnnotationList[BinaryRelation] = annotation_field(target="entities")
18
 
19
 
20
+ ner_model_name_or_path = "pie/example-ner-spanclf-conll03"
21
+ re_model_name_or_path = "pie/example-re-textclf-tacred"
 
22
 
23
+ ner_pipeline = AutoPipeline.from_pretrained(ner_model_name_or_path, device=-1, num_workers=0)
24
+ re_pipeline = AutoPipeline.from_pretrained(re_model_name_or_path, device=-1, num_workers=0)
 
 
 
 
 
25
 
26
 
27
  def predict(text):
 
52
 
53
  iface = gr.Interface(
54
  fn=predict,
55
+ inputs=gr.inputs.Textbox(
56
+ lines=5,
57
+ default="There is still some uncertainty that Musk - also chief executive of electric car maker Tesla and rocket company SpaceX - will pull off his planned buyout.",
58
+ ),
59
  outputs="html",
60
  )
61
  iface.launch()