abdiharyadi commited on
Commit
ce0ea7d
·
1 Parent(s): 0025a57

style: change blank result to description, with time after executed

Browse files
Files changed (1) hide show
  1. app.py +51 -5
app.py CHANGED
@@ -5,6 +5,7 @@ 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")
@@ -34,11 +35,28 @@ sd = StyleDetector(
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, None, None, None, None
 
 
 
 
 
 
 
42
 
43
  triplets = sd.get_triplets(text)
44
  # triplets = [
@@ -46,19 +64,47 @@ def run(text, source_style):
46
  # ("kamar", "bersih", "positif")
47
  # ]
48
  triplets_display = "\n".join(f"({x[0]}, {x[1]}, {x[2]})" for x in triplets)
49
- yield source_amr_display, triplets_display, None, None, None
 
 
 
 
 
 
 
50
 
51
  style_words = sd.get_style_words_from_triplets(triplets)
52
  # style_words = ["bagus", "bersih"]
53
  style_words_display = ", ".join(style_words)
54
- yield source_amr_display, triplets_display, style_words_display, None, None
 
 
 
 
 
 
 
55
 
56
  target_amr = penman.decode("(z0 / dunia)")
57
  target_amr_display = penman.encode(target_amr)
58
- yield source_amr_display, triplets_display, style_words_display, target_amr_display, None
 
 
 
 
 
 
 
59
 
60
  result = f"dunia ({text=}, {source_style=})"
61
- yield source_amr_display, triplets_display, style_words_display, target_amr_display, result
 
 
 
 
 
 
 
62
 
63
  demo = gr.Interface(
64
  fn=run,
 
5
  import os
6
  import penman
7
  import sys
8
+ import time
9
 
10
  if not os.path.exists("amr-tst-indo"):
11
  Repo.clone_from("https://github.com/AbdiHaryadi/amr-tst-indo.git", "amr-tst-indo")
 
35
  )
36
 
37
  def run(text, source_style):
38
+ yield (
39
+ "(Memproses ...)",
40
+ "(Menunggu ...)",
41
+ "(Menunggu ...)",
42
+ "(Menunggu ...)",
43
+ "(Menunggu ...)",
44
+ )
45
+
46
+ start_time = time.time()
47
+
48
  # source_amr, *_ = t2a([text])
49
  # source_amr.metadata = {}
50
  # source_amr_display = penman.encode(source_amr)
51
  source_amr_display = "(z0 / halo)"
52
+ source_amr_display += f"\n\n({time.time() - start_time:.2f} s)"
53
+ yield (
54
+ source_amr_display,
55
+ "(Memproses ...)",
56
+ "(Menunggu ...)",
57
+ "(Menunggu ...)",
58
+ "(Menunggu ...)",
59
+ )
60
 
61
  triplets = sd.get_triplets(text)
62
  # triplets = [
 
64
  # ("kamar", "bersih", "positif")
65
  # ]
66
  triplets_display = "\n".join(f"({x[0]}, {x[1]}, {x[2]})" for x in triplets)
67
+ triplets_display += f"\n\n({time.time() - start_time:.2f} s)"
68
+ yield (
69
+ source_amr_display,
70
+ triplets_display,
71
+ "(Memproses ...)",
72
+ "(Menunggu ...)",
73
+ "(Menunggu ...)",
74
+ )
75
 
76
  style_words = sd.get_style_words_from_triplets(triplets)
77
  # style_words = ["bagus", "bersih"]
78
  style_words_display = ", ".join(style_words)
79
+ style_words_display += f"\n\n({time.time() - start_time:.2f} s)"
80
+ yield (
81
+ source_amr_display,
82
+ triplets_display,
83
+ style_words_display,
84
+ "(Memproses ...)",
85
+ "(Menunggu ...)",
86
+ )
87
 
88
  target_amr = penman.decode("(z0 / dunia)")
89
  target_amr_display = penman.encode(target_amr)
90
+ target_amr_display += f"\n\n({time.time() - start_time:.2f} s)"
91
+ yield (
92
+ source_amr_display,
93
+ triplets_display,
94
+ style_words_display,
95
+ target_amr_display,
96
+ "(Memproses ...)",
97
+ )
98
 
99
  result = f"dunia ({text=}, {source_style=})"
100
+ result += f"\n\n({time.time() - start_time:.2f} s)"
101
+ yield (
102
+ source_amr_display,
103
+ triplets_display,
104
+ style_words_display,
105
+ target_amr_display,
106
+ result
107
+ )
108
 
109
  demo = gr.Interface(
110
  fn=run,