mirror of
https://github.com/believethehype/nostrdvm.git
synced 2025-11-19 19:56:28 +01:00
some fixes for tts, adding experimental code for gallery lists
This commit is contained in:
@@ -125,15 +125,15 @@ class TextToSpeech(DVMTaskInterface):
|
|||||||
model = "tts_models/multilingual/multi-dataset/xtts_v2"
|
model = "tts_models/multilingual/multi-dataset/xtts_v2"
|
||||||
tts = TTS(model).to(device)
|
tts = TTS(model).to(device)
|
||||||
|
|
||||||
text = options["prompt"]
|
text = options["prompt"].replace("~", "around ").replace("#", "hashtag").replace(" LFG", " Let's fucking go")
|
||||||
text_clean = re.sub(
|
text_clean = re.sub(
|
||||||
r'''(?i)\b((?:https?://|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}/)(?:[^\s()<>]+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:'".,<>?«»“”‘’]))''',
|
r'''(?i)\b((?:https?://|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}/)(?:[^\s()<>]+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:'".,<>?«»“”‘’]))''',
|
||||||
" ", text)
|
" ", text)
|
||||||
|
|
||||||
tts.tts_to_file(
|
tts.tts_to_file(
|
||||||
text=text_clean,
|
text=text_clean,
|
||||||
speaker_wav=options["input_wav"], language=options["language"], file_path="outputs/output.wav")
|
speaker_wav=options["input_wav"], language=options["language"], file_path="outputs/output.mp3")
|
||||||
result = upload_media_to_hoster("outputs/output.wav")
|
result = upload_media_to_hoster("outputs/output.mp3")
|
||||||
print(result)
|
print(result)
|
||||||
return result
|
return result
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
|||||||
16
nostr_dvm/utils/gallery_utils.py
Normal file
16
nostr_dvm/utils/gallery_utils.py
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
from nostr_sdk import Tag, Keys, EventBuilder, Kind
|
||||||
|
|
||||||
|
from nostr_dvm.utils.definitions import EventDefinitions
|
||||||
|
from nostr_dvm.utils.nostr_utils import send_event
|
||||||
|
from nostr_dvm.utils.print import bcolors
|
||||||
|
|
||||||
|
|
||||||
|
async def gallery_announce_list(tags, dvm_config, client):
|
||||||
|
|
||||||
|
|
||||||
|
keys = Keys.parse(dvm_config.NIP89.PK)
|
||||||
|
content = ""
|
||||||
|
event = EventBuilder(Kind(10011), content, tags).to_event(keys)
|
||||||
|
eventid = await send_event(event, client=client, dvm_config=dvm_config, blastr=True)
|
||||||
|
|
||||||
|
print(bcolors.BLUE + "[" + dvm_config.NIP89.NAME + "] Announced Gallery for " + dvm_config.NIP89.NAME +" (EventID: " + str(eventid.to_hex()) +")" + bcolors.ENDC)
|
||||||
@@ -154,33 +154,25 @@ def upload_media_to_hoster(filepath: str):
|
|||||||
sizeinmb = file_stats.st_size / (1024 * 1024)
|
sizeinmb = file_stats.st_size / (1024 * 1024)
|
||||||
print("Filesize of Uploaded media: " + str(sizeinmb) + " Mb.")
|
print("Filesize of Uploaded media: " + str(sizeinmb) + " Mb.")
|
||||||
if sizeinmb > 25:
|
if sizeinmb > 25:
|
||||||
|
print("Filesize over Nostr.build limited, using catbox")
|
||||||
uploader = CatboxUploader(filepath)
|
uploader = CatboxUploader(filepath)
|
||||||
result = uploader.execute()
|
result = uploader.execute()
|
||||||
return result
|
return result
|
||||||
else:
|
else:
|
||||||
url = 'https://nostr.build/api/v2/upload/files'
|
url = 'https://nostr.build/api/v2/upload/files'
|
||||||
response = requests.post(url, files=files)
|
response = requests.post(url, files=files)
|
||||||
|
print(response.text)
|
||||||
json_object = json.loads(response.text)
|
json_object = json.loads(response.text)
|
||||||
result = json_object["data"][0]["url"]
|
result = json_object["data"][0]["url"]
|
||||||
return result
|
return result
|
||||||
except:
|
except Exception as e:
|
||||||
try:
|
try:
|
||||||
file = {'file': open(filepath, 'rb')}
|
uploader = CatboxUploader(filepath)
|
||||||
url = 'https://nostrfiles.dev/upload_image'
|
result = uploader.execute()
|
||||||
response = requests.post(url, files=file)
|
print(result)
|
||||||
json_object = json.loads(response.text)
|
return result
|
||||||
print(json_object["url"])
|
|
||||||
return json_object["url"]
|
|
||||||
# fallback filehoster
|
|
||||||
except:
|
except:
|
||||||
|
raise Exception("Upload not possible, all hosters didn't work or couldn't generate output")
|
||||||
try:
|
|
||||||
uploader = CatboxUploader(filepath)
|
|
||||||
result = uploader.execute()
|
|
||||||
print(result)
|
|
||||||
return result
|
|
||||||
except:
|
|
||||||
raise Exception("Upload not possible, all hosters didn't work or couldn't generate output")
|
|
||||||
|
|
||||||
|
|
||||||
def build_status_reaction(status, task, amount, content, dvm_config):
|
def build_status_reaction(status, task, amount, content, dvm_config):
|
||||||
|
|||||||
2
setup.py
2
setup.py
@@ -1,6 +1,6 @@
|
|||||||
from setuptools import setup, find_packages
|
from setuptools import setup, find_packages
|
||||||
|
|
||||||
VERSION = '0.6.27'
|
VERSION = '0.6.28'
|
||||||
DESCRIPTION = 'A framework to build and run Nostr NIP90 Data Vending Machines'
|
DESCRIPTION = 'A framework to build and run Nostr NIP90 Data Vending Machines'
|
||||||
LONG_DESCRIPTION = ('A framework to build and run Nostr NIP90 Data Vending Machines. See the github repository for more information')
|
LONG_DESCRIPTION = ('A framework to build and run Nostr NIP90 Data Vending Machines. See the github repository for more information')
|
||||||
|
|
||||||
|
|||||||
BIN
tests/output.wav
Normal file
BIN
tests/output.wav
Normal file
Binary file not shown.
@@ -7,6 +7,9 @@ from nostr_sdk import Keys, Client, Tag, EventBuilder, Filter, HandleNotificatio
|
|||||||
nip04_encrypt, EventId, Options, PublicKey, Event, NostrSigner, Nip19Event
|
nip04_encrypt, EventId, Options, PublicKey, Event, NostrSigner, Nip19Event
|
||||||
|
|
||||||
from nostr_dvm.utils import definitions, dvmconfig
|
from nostr_dvm.utils import definitions, dvmconfig
|
||||||
|
from nostr_dvm.utils.dvmconfig import DVMConfig
|
||||||
|
from nostr_dvm.utils.gallery_utils import gallery_announce_list
|
||||||
|
from nostr_dvm.utils.nip89_utils import NIP89Config
|
||||||
from nostr_dvm.utils.nostr_utils import check_and_set_private_key
|
from nostr_dvm.utils.nostr_utils import check_and_set_private_key
|
||||||
|
|
||||||
|
|
||||||
@@ -25,7 +28,7 @@ async def test():
|
|||||||
|
|
||||||
for relay in relay_list:
|
for relay in relay_list:
|
||||||
await client.add_relay(relay)
|
await client.add_relay(relay)
|
||||||
client.connect()
|
await client.connect()
|
||||||
|
|
||||||
await test_referred_events(client,"c70fbd4dbaad22c427d4359981d3bdddd3971ed1a38227ca2f8e5e760f58103c",
|
await test_referred_events(client,"c70fbd4dbaad22c427d4359981d3bdddd3971ed1a38227ca2f8e5e760f58103c",
|
||||||
definitions.EventDefinitions.ANY_RESULT)
|
definitions.EventDefinitions.ANY_RESULT)
|
||||||
@@ -69,6 +72,31 @@ async def test_referred_events(client, event_id, kinds=None):
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
async def test_gallery():
|
||||||
|
relay_list = dvmconfig.DVMConfig.RELAY_LIST
|
||||||
|
keys = Keys.parse(check_and_set_private_key("test_client"))
|
||||||
|
wait_for_send = False
|
||||||
|
skip_disconnected_relays = True
|
||||||
|
opts = (Options().wait_for_send(wait_for_send).send_timeout(timedelta(seconds=5))
|
||||||
|
.skip_disconnected_relays(skip_disconnected_relays))
|
||||||
|
|
||||||
|
signer = NostrSigner.keys(keys)
|
||||||
|
client = Client.with_opts(signer, opts)
|
||||||
|
|
||||||
|
for relay in relay_list:
|
||||||
|
await client.add_relay(relay)
|
||||||
|
await client.connect()
|
||||||
|
dvm_config = DVMConfig()
|
||||||
|
dvm_config.NIP89 = NIP89Config()
|
||||||
|
dvm_config.NIP89.PK = Keys.parse("nsec...").secret_key().to_hex()
|
||||||
|
|
||||||
|
tags = [Tag.parse(["d", "gallery"]),
|
||||||
|
Tag.parse(["image", "https://i.nostr.build/7G2G2.jpg"]),
|
||||||
|
Tag.parse(["image", "https://i.nostr.build/XVLkd.jpg"])]
|
||||||
|
|
||||||
|
await gallery_announce_list(tags, dvm_config, client)
|
||||||
|
|
||||||
async def test_search_by_user_since_days(client, pubkey, days, prompt):
|
async def test_search_by_user_since_days(client, pubkey, days, prompt):
|
||||||
since_seconds = int(days) * 24 * 60 * 60
|
since_seconds = int(days) * 24 * 60 * 60
|
||||||
dif = Timestamp.now().as_secs() - since_seconds
|
dif = Timestamp.now().as_secs() - since_seconds
|
||||||
@@ -95,7 +123,7 @@ if __name__ == '__main__':
|
|||||||
else:
|
else:
|
||||||
raise FileNotFoundError(f'.env file not found at {env_path} ')
|
raise FileNotFoundError(f'.env file not found at {env_path} ')
|
||||||
|
|
||||||
asyncio.run(test())
|
asyncio.run(test_gallery())
|
||||||
|
|
||||||
# works
|
# works
|
||||||
|
|
||||||
|
|||||||
3
tests/upload_hoster.py
Normal file
3
tests/upload_hoster.py
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
from nostr_dvm.utils.output_utils import upload_media_to_hoster
|
||||||
|
|
||||||
|
upload_media_to_hoster("tests/output.wav")
|
||||||
Reference in New Issue
Block a user