Spaces:
Runtime error
Runtime error
from typing import Tuple | |
from modules.m_apvoice import APVoice | |
class Connector: | |
def __init__( | |
self | |
) -> None: | |
self.apvoice = APVoice() | |
# <center>{}</center> | |
self.__out_template = """ | |
<html lang="en"> | |
<head> | |
<meta charset="utf-8"> | |
<meta name="viewport" content="width=device-width, initial-scale=1"> | |
<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"> | |
</head> | |
<body> | |
<center><div class="btn-group btn-group-sm" role="group">{}</div></center> | |
<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> | |
</body> | |
</html> | |
""" | |
self.__error_template = "<center><b>{}</b></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, error = "", "" | |
try: | |
subject, tobe, participle, agent, complement = self.apvoice.active2passive(sentence) | |
verb = f""" | |
""" | |
passive_sentece = f""" | |
{self.create_category(subject, 'subject','primary')} | |
{self.create_category(tobe,'to be','warning')} | |
{self.create_category(participle,'participle','danger')} | |
{self.create_category(agent,'agent','info')} | |
{self.create_category(complement,'compl.','dark')} | |
""" | |
out = self.__out_template.format(passive_sentece) | |
except Exception as e: | |
error = self.__error_template.format(str(e)) | |
return error, out |