Spaces:
Running
Running
abdiharyadi
commited on
Commit
β’
d4efbb2
1
Parent(s):
02f1163
feat: integrate StyleDetector, disable TextToAMR for fast test
Browse files- app.py +31 -12
- requirements.txt +1 -0
app.py
CHANGED
@@ -1,15 +1,18 @@
|
|
|
|
1 |
from git import Repo
|
2 |
import gradio as gr
|
3 |
from huggingface_hub import snapshot_download
|
|
|
4 |
import penman
|
5 |
import sys
|
6 |
|
7 |
-
|
|
|
8 |
sys.path.append("./amr-tst-indo")
|
9 |
|
10 |
from text_to_amr import TextToAMR
|
|
|
11 |
|
12 |
-
# Gold v2
|
13 |
amr_parsing_model_name = "mbart-en-id-smaller-indo-amr-parsing-translated-nafkhan"
|
14 |
snapshot_download(
|
15 |
repo_id=f"abdiharyadi/{amr_parsing_model_name}",
|
@@ -21,20 +24,36 @@ snapshot_download(
|
|
21 |
)
|
22 |
t2a = TextToAMR(model_name=amr_parsing_model_name)
|
23 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
24 |
def run(text, source_style):
|
25 |
-
source_amr, *_ = t2a([text])
|
26 |
-
source_amr.metadata = {}
|
27 |
-
source_amr_display = penman.encode(source_amr)
|
|
|
28 |
yield source_amr_display, "...", "...", "...", "..."
|
29 |
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
yield source_amr_display, triplets_display, "...", "...", "..."
|
36 |
|
37 |
-
style_words =
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
38 |
style_words_display = ", ".join(style_words)
|
39 |
yield source_amr_display, triplets_display, style_words_display, "...", "..."
|
40 |
|
|
|
1 |
+
import gdown
|
2 |
from git import Repo
|
3 |
import gradio as gr
|
4 |
from huggingface_hub import snapshot_download
|
5 |
+
import os
|
6 |
import penman
|
7 |
import sys
|
8 |
|
9 |
+
if not os.path.exists("amr-tst-indo"):
|
10 |
+
Repo.clone_from("https://github.com/AbdiHaryadi/amr-tst-indo.git", "amr-tst-indo")
|
11 |
sys.path.append("./amr-tst-indo")
|
12 |
|
13 |
from text_to_amr import TextToAMR
|
14 |
+
from style_detector import StyleDetector
|
15 |
|
|
|
16 |
amr_parsing_model_name = "mbart-en-id-smaller-indo-amr-parsing-translated-nafkhan"
|
17 |
snapshot_download(
|
18 |
repo_id=f"abdiharyadi/{amr_parsing_model_name}",
|
|
|
24 |
)
|
25 |
t2a = TextToAMR(model_name=amr_parsing_model_name)
|
26 |
|
27 |
+
gdown.download(
|
28 |
+
"https://drive.google.com/uc?id=1J_6PbYsQ6Kl4Qfs1wBVwd52_r9uTpIxx",
|
29 |
+
"./model-best.pt"
|
30 |
+
)
|
31 |
+
sd = StyleDetector(
|
32 |
+
config_path="./amr-tst-indo/indonesian-aste-generative/resources/exp-v2/exp-m0.yaml",
|
33 |
+
model_path="./model-best.pt"
|
34 |
+
)
|
35 |
+
|
36 |
def run(text, source_style):
|
37 |
+
# source_amr, *_ = t2a([text])
|
38 |
+
# source_amr.metadata = {}
|
39 |
+
# source_amr_display = penman.encode(source_amr)
|
40 |
+
source_amr_display = "(z0 / halo)"
|
41 |
yield source_amr_display, "...", "...", "...", "..."
|
42 |
|
43 |
+
triplet_display_dict = {"data": "..."}
|
44 |
+
def triplets_callback(triplets: list):
|
45 |
+
triplet_display_dict["data"] = "\n".join(f"({x[0]}, {x[1]}, {x[2]})" for x in triplets)
|
46 |
+
triplets_display = triplet_display_dict["data"]
|
47 |
+
yield source_amr_display, triplets_display, "...", "...", "..."
|
|
|
48 |
|
49 |
+
style_words = sd(text, triplets_callback=triplets_callback)
|
50 |
+
# style_words = ["bagus", "bersih"]
|
51 |
+
# triplets = [
|
52 |
+
# ("kamar", "sangat bagus", "positif"),
|
53 |
+
# ("kamar", "bersih", "positif")
|
54 |
+
# ]
|
55 |
+
# triplets_display = "\n".join(f"({x[0]}, {x[1]}, {x[2]})" for x in triplets)
|
56 |
+
triplets_display = triplet_display_dict["data"]
|
57 |
style_words_display = ", ".join(style_words)
|
58 |
yield source_amr_display, triplets_display, style_words_display, "...", "..."
|
59 |
|
requirements.txt
CHANGED
@@ -1,6 +1,7 @@
|
|
1 |
gitpython
|
2 |
scipy>=1.7.2
|
3 |
scikit_learn>=1.0.2
|
|
|
4 |
|
5 |
accelerate==0.32.1
|
6 |
amrlib==0.8.0
|
|
|
1 |
gitpython
|
2 |
scipy>=1.7.2
|
3 |
scikit_learn>=1.0.2
|
4 |
+
gdown
|
5 |
|
6 |
accelerate==0.32.1
|
7 |
amrlib==0.8.0
|