nanom commited on
Commit
b1aa3b5
1 Parent(s): cba89ba

Updated interface

Browse files
Files changed (4) hide show
  1. README.md +2 -2
  2. app.py +31 -27
  3. modules/m_apvoice.py +9 -4
  4. modules/m_connector.py +13 -25
README.md CHANGED
@@ -1,6 +1,6 @@
1
  ---
2
- title: Passive Voice
3
- emoji: 🔥
4
  colorFrom: red
5
  colorTo: green
6
  sdk: gradio
 
1
  ---
2
+ title: Active to Passive Voice
3
+ emoji: 💤 🎤
4
  colorFrom: red
5
  colorTo: green
6
  sdk: gradio
app.py CHANGED
@@ -5,41 +5,45 @@ iface = gr.Blocks(css="container {max-width: 78%; margin: auto;}")
5
  conn = Connector()
6
 
7
  with iface:
8
- in_sentence = gr.Textbox(
9
- label = "Active sentence",
10
- lines=2,
11
- placeholder = "Enter here the sentence without contractions...",
12
- )
13
- btn_act2pas = gr.Button(
14
- value = "Pass to passive!"
15
- )
16
-
17
- error = gr.HTML()
18
-
19
- out_sentence = gr.HTML(
20
- label = "Out. Pasive sentences:",
21
- )
 
 
22
 
23
- gr.Examples(
24
- inputs = in_sentence,
25
- examples = [
26
- "The teacher corrected the exams in less than an hour",
27
- "Christopher Columbus discovered America in 1492",
28
- "Mchael Jackson sings Billy Jean",
29
- "They are painting the house" ,
30
- "My mom has prepared the dinner",
31
- "The man has not found the farm"
32
- ]
33
- )
 
 
34
 
35
  btn_act2pas.click(
36
  fn = conn.active2passive,
37
  inputs = in_sentence,
38
- outputs = [error, out_sentence]
39
  )
40
 
41
  iface.launch(
42
  # server_port= 9090,
43
- # server_name = "0.0.0.0",
44
  # share = True
45
  )
 
5
  conn = Connector()
6
 
7
  with iface:
8
+ gr.Markdown("<center><h5>Active to Passive Voice</h5></center>")
9
+ with gr.Row():
10
+ with gr.Column(scale=2):
11
+ in_sentence = gr.Textbox(
12
+ label = "Active sentence",
13
+ max_lines=2,
14
+ lines=1,
15
+ placeholder = "Enter here the sentence without contractions...",
16
+ )
17
+ btn_act2pas = gr.Button(
18
+ value = "Pass to passive!"
19
+ )
20
+ out = gr.HTML(
21
+ label = "Out. Pasive sentences:",
22
+ elem_id=".btn-group"
23
+ )
24
 
25
+ with gr.Column(variant='panel'):
26
+ gr.Examples(
27
+ inputs = in_sentence,
28
+ examples = [
29
+ "The teacher corrected the exams in less than an hour",
30
+ "Christopher Columbus discovered America in 1492",
31
+ "Mchael Jackson sings Billy Jean",
32
+ "They are painting the house" ,
33
+ "My mom has prepared the dinner",
34
+ "The man has not found the farm"
35
+ ],
36
+ examples_per_page=5
37
+ )
38
 
39
  btn_act2pas.click(
40
  fn = conn.active2passive,
41
  inputs = in_sentence,
42
+ outputs = out
43
  )
44
 
45
  iface.launch(
46
  # server_port= 9090,
47
+ server_name = "0.0.0.0",
48
  # share = True
49
  )
modules/m_apvoice.py CHANGED
@@ -3,7 +3,7 @@ import subprocess
3
  import spacy
4
  import pyinflect
5
  from difflib import ndiff
6
- from typing import List, Union, Tuple
7
 
8
  # BES auxiliary “be” Let it **be**.
9
  # HVS forms of “have” I**’ve** seen the Queen
@@ -192,7 +192,7 @@ class APVoice:
192
  self,
193
  active_sentence: str,
194
  debug: bool=False
195
- ) -> List[str]:
196
 
197
  active_sentence = active_sentence.strip()
198
  if active_sentence == "":
@@ -249,5 +249,10 @@ class APVoice:
249
  word = self.subjp2objp(word)
250
  p_agent += word + " "
251
 
252
- # return f"{p_subj.capitalize()} {p_tobe} {p_verb} {p_agent.strip().lower()} {complement}"
253
- return [p_subj.capitalize(), p_tobe, p_verb, p_agent.strip().lower(), complement]
 
 
 
 
 
 
3
  import spacy
4
  import pyinflect
5
  from difflib import ndiff
6
+ from typing import List, Union, Tuple, Dict
7
 
8
  # BES auxiliary “be” Let it **be**.
9
  # HVS forms of “have” I**’ve** seen the Queen
 
192
  self,
193
  active_sentence: str,
194
  debug: bool=False
195
+ ) -> Dict[str, str]:
196
 
197
  active_sentence = active_sentence.strip()
198
  if active_sentence == "":
 
249
  word = self.subjp2objp(word)
250
  p_agent += word + " "
251
 
252
+ return {
253
+ 'subject': p_subj.capitalize(),
254
+ 'tobe':p_tobe,
255
+ 'participle': p_verb,
256
+ 'agent': p_agent[0].lower() + p_agent[1:].strip(),
257
+ 'complement':complement
258
+ }
modules/m_connector.py CHANGED
@@ -8,21 +8,11 @@ class Connector:
8
 
9
  self.apvoice = APVoice()
10
 
11
- # <center>{}</center>
12
  self.__out_template = """
13
- <html lang="en">
14
- <head>
15
- <meta charset="utf-8">
16
- <meta name="viewport" content="width=device-width, initial-scale=1">
17
  <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-GLhlTQ8iRABdZLl6O3oVMWSktQOp6b7In1Zl3/Jr59b6EGGoI1aFkw7cmDA6j6gD" crossorigin="anonymous">
18
- </head>
19
- <body>
20
- <center><div class="btn-group btn-group-sm" role="group">{}</div></center>
21
- <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/js/bootstrap.bundle.min.js" integrity="sha384-w76AqPfDkMBDXo30jS1Sgez6pr3x5MlQ1ZAGC+nuZB+EYdgRZgiwxhTBTkF7CXvN" crossorigin="anonymous"></script>
22
- </body>
23
- </html>
24
  """
25
- self.__error_template = "<center><b>{}</b></center>"
26
 
27
  def create_category(
28
  self,
@@ -44,21 +34,19 @@ class Connector:
44
  sentence: str
45
  ) -> Tuple[str,str]:
46
 
47
- out, error = "", ""
48
  try:
49
- subject, tobe, participle, agent, complement = self.apvoice.active2passive(sentence)
50
- verb = f"""
 
 
 
 
 
51
  """
52
- passive_sentece = f"""
53
- {self.create_category(subject, 'subject','primary')}
54
- {self.create_category(tobe,'to be','warning')}
55
- {self.create_category(participle,'participle','danger')}
56
- {self.create_category(agent,'agent','info')}
57
- {self.create_category(complement,'compl.','dark')}
58
- """
59
- out = self.__out_template.format(passive_sentece)
60
 
61
  except Exception as e:
62
- error = self.__error_template.format(str(e))
63
 
64
- return error, out
 
8
 
9
  self.apvoice = APVoice()
10
 
 
11
  self.__out_template = """
 
 
 
 
12
  <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-GLhlTQ8iRABdZLl6O3oVMWSktQOp6b7In1Zl3/Jr59b6EGGoI1aFkw7cmDA6j6gD" crossorigin="anonymous">
13
+ <center>{}</center>
 
 
 
 
 
14
  """
15
+ self.__error_template = "<center><h3><b>{}</b></h3></center>"
16
 
17
  def create_category(
18
  self,
 
34
  sentence: str
35
  ) -> Tuple[str,str]:
36
 
37
+ out = ""
38
  try:
39
+ out = self.apvoice.active2passive(sentence)
40
+ out = f"""
41
+ {self.create_category(out['subject'], 'subject','primary')}
42
+ {self.create_category(out['tobe'],'to be','warning')}
43
+ {self.create_category(out['participle'],'participle','danger')}
44
+ {self.create_category(out['agent'],'agent','info')}
45
+ {self.create_category(out['complement'],'compl.','dark')}
46
  """
47
+ out = self.__out_template.format(out)
 
 
 
 
 
 
 
48
 
49
  except Exception as e:
50
+ out = self.__error_template.format(str(e))
51
 
52
+ return out