Spaces:
Running
Running
from typing import Tuple | |
from modules.m_apvoice import APVoice | |
class Connector: | |
def __init__( | |
self | |
) -> None: | |
self.apvoice = APVoice() | |
self.__out_template = """ | |
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-GLhlTQ8iRABdZLl6O3oVMWSktQOp6b7In1Zl3/Jr59b6EGGoI1aFkw7cmDA6j6gD" crossorigin="anonymous"> | |
<center>{}</center> | |
""" | |
self.__error_template = "<center><h3><b>{}</b></h3></center>" | |
def create_category( | |
self, | |
text: str, | |
category: str, | |
color: str | |
) -> str: | |
html = f""" | |
<div type="button" title="{category}" class="btn btn-{color} btn-sm p-2"> | |
<b>{text}</b><br> | |
<span class="badge text-bg-light">{category}</span> | |
</div> | |
""" | |
return html if text != "" else "" | |
def active2passive( | |
self, | |
sentence: str | |
) -> Tuple[str,str]: | |
out = "" | |
try: | |
out = self.apvoice.active2passive(sentence) | |
out = f""" | |
{self.create_category(out['subject'], 'subject','primary')} | |
{self.create_category(out['tobe'],'to be','warning')} | |
{self.create_category(out['participle'],'participle','danger')} | |
{self.create_category(out['agent'],'agent','info')} | |
{self.create_category(out['complement'],'compl.','dark')} | |
""" | |
out = self.__out_template.format(out) | |
except Exception as e: | |
out = self.__error_template.format(str(e)) | |
return out |