From 79deb2495ca353c29969787b54652f0dc22f8b87 Mon Sep 17 00:00:00 2001 From: Believethehype Date: Sun, 17 Dec 2023 22:28:05 +0100 Subject: [PATCH] fixes related to creating folders --- nostr_dvm/tasks/texttospeech.py | 14 ++++++++------ nostr_dvm/utils/database_utils.py | 6 ++++-- setup.py | 2 +- tests/test_dvm_client.py | 4 ++-- 4 files changed, 15 insertions(+), 11 deletions(-) diff --git a/nostr_dvm/tasks/texttospeech.py b/nostr_dvm/tasks/texttospeech.py index 1e99d1ac..eca75234 100644 --- a/nostr_dvm/tasks/texttospeech.py +++ b/nostr_dvm/tasks/texttospeech.py @@ -2,6 +2,7 @@ import os os.environ["PYTORCH_ENABLE_MPS_FALLBACK"] = "1" from pathlib import Path +import urllib.request from nostr_dvm.interfaces.dvmtaskinterface import DVMTaskInterface from nostr_dvm.utils.admin_utils import AdminConfig @@ -21,7 +22,7 @@ class TextToSpeech(DVMTaskInterface): KIND: int = EventDefinitions.KIND_NIP90_TEXT_TO_SPEECH TASK: str = "text-to-speech" - FIX_COST: float = 0 + FIX_COST: float = 200 dependencies = [("nostr-dvm", "nostr-dvm"), ("TTS", "TTS==0.22.0")] @@ -46,10 +47,10 @@ def create_request_from_nostr_event(self, event, client=None, dvm_config=None): if self.options.get("input_file") and self.options.get("input_file") != "": input_file = self.options['input_file'] else: - input_file = "https://media.nostr.build/av/de104e3260be636533a56fd4468b905c1eb22b226143a997aa936b011122af8a.wav" - import urllib.request - if not Path.exists(Path(r'cache/input.wav')): - urllib.request.urlretrieve(input_file, "cache/input.wav") + if not Path.exists(Path('cache/input.wav')): + input_file_url = "https://media.nostr.build/av/de104e3260be636533a56fd4468b905c1eb22b226143a997aa936b011122af8a.wav" + urllib.request.urlretrieve(input_file_url, "cache/input.wav") + input_file = "cache/input.wav" language = "en" for tag in event.tags(): @@ -86,7 +87,7 @@ def process(self, request_form): tts.tts_to_file( text=options["prompt"], - speaker_wav="cache/input.wav", language=options["language"], file_path="outputs/output.wav") + speaker_wav=options["input_wav"], language=options["language"], file_path="outputs/output.wav") result = upload_media_to_hoster("outputs/output.wav") return result except Exception as e: @@ -101,6 +102,7 @@ def build_example(name, identifier, admin_config): dvm_config = build_default_config(identifier) admin_config.LUD16 = dvm_config.LN_ADDRESS + #use an alternative local wav file you want to use for cloning options = {'input_file': ""} nip89info = { diff --git a/nostr_dvm/utils/database_utils.py b/nostr_dvm/utils/database_utils.py index 32e44a1d..5180f369 100644 --- a/nostr_dvm/utils/database_utils.py +++ b/nostr_dvm/utils/database_utils.py @@ -26,8 +26,10 @@ class User: def create_sql_table(db): try: import os - if not os.path.exists(r'.\db'): - os.makedirs(r'.\db') + if not os.path.exists(r'db'): + os.makedirs(r'db') + if not os.path.exists(r'outputs'): + os.makedirs(r'outputs') con = sqlite3.connect(db) cur = con.cursor() cur.execute(""" CREATE TABLE IF NOT EXISTS users ( diff --git a/setup.py b/setup.py index 9d40f507..529b5d24 100644 --- a/setup.py +++ b/setup.py @@ -1,6 +1,6 @@ from setuptools import setup, find_packages -VERSION = '0.0.4' +VERSION = '0.0.5' DESCRIPTION = 'A framework to build and run NIP90 Data Vending Machines' LONG_DESCRIPTION = ('A framework to build and run NIP90 Data Vending Machines. ' 'This is an early stage release. Interfaces might change/brick') diff --git a/tests/test_dvm_client.py b/tests/test_dvm_client.py index c0e252f3..b47d4140 100644 --- a/tests/test_dvm_client.py +++ b/tests/test_dvm_client.py @@ -152,7 +152,7 @@ def nostr_client(): #nostr_client_test_translation("note1p8cx2dz5ss5gnk7c59zjydcncx6a754c0hsyakjvnw8xwlm5hymsnc23rs", "event", "es", 20,20) #nostr_client_test_translation("44a0a8b395ade39d46b9d20038b3f0c8a11168e67c442e3ece95e4a1703e2beb", "event", "zh", 20, 20) #nostr_client_test_image("a beautiful purple ostrich watching the sunset") - nostr_client_test_tts("Hello, this is a test. One two three.") + nostr_client_test_tts("Hello, this is a test. Mic check one, two.") #cashutoken = "cashuAeyJ0b2tlbiI6W3sicHJvb2ZzIjpbeyJpZCI6InZxc1VRSVorb0sxOSIsImFtb3VudCI6MSwiQyI6IjAyNWU3ODZhOGFkMmExYTg0N2YxMzNiNGRhM2VhMGIyYWRhZGFkOTRiYzA4M2E2NWJjYjFlOTgwYTE1NGIyMDA2NCIsInNlY3JldCI6InQ1WnphMTZKMGY4UElQZ2FKTEg4V3pPck5rUjhESWhGa291LzVzZFd4S0U9In0seyJpZCI6InZxc1VRSVorb0sxOSIsImFtb3VudCI6NCwiQyI6IjAyOTQxNmZmMTY2MzU5ZWY5ZDc3MDc2MGNjZmY0YzliNTMzMzVmZTA2ZGI5YjBiZDg2Njg5Y2ZiZTIzMjVhYWUwYiIsInNlY3JldCI6IlRPNHB5WE43WlZqaFRQbnBkQ1BldWhncm44UHdUdE5WRUNYWk9MTzZtQXM9In0seyJpZCI6InZxc1VRSVorb0sxOSIsImFtb3VudCI6MTYsIkMiOiIwMmRiZTA3ZjgwYmMzNzE0N2YyMDJkNTZiMGI3ZTIzZTdiNWNkYTBhNmI3Yjg3NDExZWYyOGRiZDg2NjAzNzBlMWIiLCJzZWNyZXQiOiJHYUNIdHhzeG9HM3J2WWNCc0N3V0YxbU1NVXczK0dDN1RKRnVwOHg1cURzPSJ9XSwibWludCI6Imh0dHBzOi8vbG5iaXRzLmJpdGNvaW5maXhlc3RoaXMub3JnL2Nhc2h1L2FwaS92MS9ScDlXZGdKZjlxck51a3M1eVQ2SG5rIn1dfQ==" @@ -162,7 +162,7 @@ def handle(self, relay_url, event): print(f"Received new event from {relay_url}: {event.as_json()}") if event.kind() == 7000: print("[Nostr Client]: " + event.as_json()) - elif event.kind() > 6000 and event.kind() < 6999: + elif 6000 < event.kind() < 6999: print("[Nostr Client]: " + event.as_json()) print("[Nostr Client]: " + event.content())