kwang2049 commited on
Commit
edbc37a
·
1 Parent(s): 0ec181f
Files changed (3) hide show
  1. app.py +10 -3
  2. pipeline.py +29 -0
  3. requirements.txt +5 -0
app.py CHANGED
@@ -1,7 +1,14 @@
 
1
  import gradio as gr
 
 
2
 
3
- def greet(name):
4
- return "Hello " + name + "!!"
5
 
6
- demo = gr.Interface(fn=greet, inputs="text", outputs="text")
 
 
 
 
 
7
  demo.launch()
 
1
+ from typing import Any, Dict
2
  import gradio as gr
3
+ from pipeline import LongCorefPipeline
4
+ from huggingface_hub import snapshot_download
5
 
6
+ long_coref = LongCorefPipeline(snapshot_download("kwang2049/long-coref"))
 
7
 
8
+
9
+ def fn(doc: str) -> Dict[str, Any]:
10
+ return long_coref(doc)
11
+
12
+
13
+ demo = gr.Interface(fn=fn, inputs="text", outputs="text")
14
  demo.launch()
pipeline.py ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ from typing import Dict, Any
3
+ from long_coref.coref.prediction import CorefPredictor
4
+ from long_coref.coref.utils import ArchiveContent
5
+ from allennlp.common.params import Params
6
+
7
+ CHECKPOINT = "coref-spanbert-large-2021.03.10"
8
+
9
+
10
+ class LongCorefPipeline:
11
+ def __init__(self, path=""):
12
+ archive_content = ArchiveContent(
13
+ archive_dir=os.path.join(path, CHECKPOINT),
14
+ weight_path=os.path.join(path, CHECKPOINT, "weights.th"),
15
+ config=Params.from_file(os.path.join(path, CHECKPOINT, "config.json")),
16
+ )
17
+ self.predictor = CorefPredictor.from_extracted_archive(archive_content)
18
+
19
+ def __call__(self, data: str) -> Dict[str, Any]:
20
+ """
21
+ data args:
22
+ inputs (:obj: `str`)
23
+ date (:obj: `str`)
24
+ Return:
25
+ A :obj:`list` | `dict`: will be serialized and returned
26
+ """
27
+ # get inputs
28
+ prediction = self.predictor.resolve_paragraphs(data.split("\n\n"))
29
+ return prediction.to_dict()
requirements.txt ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ long-coref @ git+https://github.com/kwang2049/long-coref.git@727612f441a91662565254a71c3bee72acf88797
2
+ en-core-web-sm @ https://github.com/explosion/spacy-models/releases/download/en_core_web_sm-3.3.0/en_core_web_sm-3.3.0-py3-none-any.whl
3
+ thinc==8.2.5
4
+ numpy==1.26.4
5
+ spacy==3.7.6