This commit is contained in:
Believethehype 2023-11-19 20:39:55 +01:00
parent 1a5b4bf024
commit ecf1ab3d2e
4 changed files with 11 additions and 49 deletions

View File

@ -1,6 +1,6 @@
class DVMTaskInterface:
TASK: str
KIND: int
TASK: str
COST: int
def NIP89_announcement(self):

View File

@ -16,39 +16,6 @@ pandas==2.1.3
Pillow==10.1.0
pluggy==1.3.0
pycryptodome==3.19.0
python-dateutil==2.8.2
python-dotenv==1.0.0
python-editor==1.0.4
pytz==2023.3.post1
pyuseragents==1.0.5
readchar==4.0.5
requests==2.31.0
safeIO==1.2
six==1.16.0
soupsieve==2.5
translatepy==2.3
tzdata==2023.3
urllib3==2.1.0
wcwidth==0.2.10
(venv) tobias@Tobiass-MacBook-Pro-2 dvm % pip freeze
beautifulsoup4==4.12.2
bech32==1.2.0
blessed==1.20.0
certifi==2023.7.22
charset-normalizer==3.3.2
emoji==2.8.0
ffmpegio==0.8.5
ffmpegio-core==0.8.5
idna==3.4
inquirer==3.1.3
install==1.3.5
nostr-sdk==0.0.4
numpy==1.26.2
packaging==23.2
pandas==2.1.3
Pillow==10.1.0
pluggy==1.3.0
pycryptodome==3.19.0
pypdf==3.17.1
python-dateutil==2.8.2
python-dotenv==1.0.0

View File

@ -9,8 +9,8 @@ from utils.nostr_utils import get_event_by_id, get_referenced_event_by_id
class TextExtractionPDF(DVMTaskInterface):
TASK: str = "pdf-to-text"
KIND: int = EventDefinitions.KIND_NIP90_EXTRACT_TEXT
TASK: str = "pdf-to-text"
COST: int = 20
def __init__(self, name, pk):
@ -25,13 +25,11 @@ class TextExtractionPDF(DVMTaskInterface):
nip89.content = "{\"name\":\"" + self.NAME + "\",\"image\":\"https://image.nostr.build/c33ca6fc4cc038ca4adb46fdfdfda34951656f87ee364ef59095bae1495ce669.jpg\",\"about\":\"I extract Text from pdf documents\",\"nip90Params\":{}}"
return nip89
def is_input_supported(self, input_type, input_content):
if input_type != "url":
return False
return True
def create_request_form_from_nostr_event(self, event, client=None, dvm_config=None):
request_form = {"jobID": event.id().to_hex()}
@ -59,7 +57,6 @@ class TextExtractionPDF(DVMTaskInterface):
request_form["optStr"] = 'url=' + url
return request_form
def process(self, request_form):
options = DVMTaskInterface.setOptions(request_form)
from pypdf import PdfReader
@ -79,4 +76,4 @@ class TextExtractionPDF(DVMTaskInterface):
os.remove('temp.pdf')
return text
except Exception as e:
raise Exception(e)
raise Exception(e)

View File

@ -8,8 +8,8 @@ from utils.nostr_utils import get_referenced_event_by_id, get_event_by_id
class Translation(DVMTaskInterface):
TASK: str = "translation"
KIND: int = EventDefinitions.KIND_NIP90_TRANSLATE_TEXT
TASK: str = "translation"
COST: int = 0
def __init__(self, name, pk):
@ -34,19 +34,17 @@ class Translation(DVMTaskInterface):
def create_request_form_from_nostr_event(self, event, client=None, dvm_config=None):
request_form = {"jobID": event.id().to_hex()}
#default values
input_type = "event"
text = ""
translation_lang = "en"
for tag in event.tags():
if tag.as_vec()[0] == 'i':
input_type = tag.as_vec()[2]
elif tag.as_vec()[0] == 'param':
param = tag.as_vec()[1]
if param == "language": # check for paramtype
if param == "language": # check for param type
translation_lang = str(tag.as_vec()[2]).split('-')[0]
if input_type == "event":
@ -88,20 +86,20 @@ class Translation(DVMTaskInterface):
translated_text = ""
if length > 4999:
while step + 5000 < length:
textpart = options["text"][step:step + 5000]
text_part = options["text"][step:step + 5000]
step = step + 5000
try:
translated_text_part = str(gtranslate.translate(textpart, options["translation_lang"]))
translated_text_part = str(gtranslate.translate(text_part, options["translation_lang"]))
print("Translated Text part:\n\n " + translated_text_part)
except:
translated_text_part = "An error occured"
except Exception as e:
raise Exception(e)
translated_text = translated_text + translated_text_part
if step < length:
textpart = options["text"][step:length]
text_part = options["text"][step:length]
try:
translated_text_part = str(gtranslate.translate(textpart, options["translation_lang"]))
translated_text_part = str(gtranslate.translate(text_part, options["translation_lang"]))
print("Translated Text part:\n\n " + translated_text_part)
except Exception as e:
raise Exception(e)