mirror of
https://github.com/aljazceru/nostrdvm.git
synced 2026-02-07 07:14:20 +01:00
refactor / cleanup
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
# NostrAI Data Vending Machine Tasks
|
||||
|
||||
Here Tasks can be defined. Tasks need to follow the DVMTaskInterface as defined in interfaces.
|
||||
Here Tasks can be defined. Tasks need to follow the DVMTaskInterface as defined in interfaces.
|
||||
Tasks can either happen locally (especially if they are fast) or they can call an alternative backend.
|
||||
Reusable backend functions can be defined in backends (e.g. API calls)
|
||||
|
||||
@@ -42,4 +42,5 @@ Current List of Tasks:
|
||||
| **Subscriptions** | 5906 | Manage Subscriptions for other DVMS | local |
|
||||
|
||||
Kinds with (inoff) are suggestions and not merged yet and might change in the future.
|
||||
Backends might require to add an API key to the .env file or run an external server/framework the dvm will communicate with.
|
||||
Backends might require to add an API key to the .env file or run an external server/framework the dvm will communicate
|
||||
with.
|
||||
@@ -1,15 +1,13 @@
|
||||
import json
|
||||
import os
|
||||
from datetime import timedelta
|
||||
from nostr_sdk import Client, Timestamp, PublicKey, Tag, Keys, Options, SecretKey, NostrSigner, Kind, RelayOptions
|
||||
|
||||
from nostr_sdk import Kind
|
||||
|
||||
from nostr_dvm.interfaces.dvmtaskinterface import DVMTaskInterface, process_venv
|
||||
from nostr_dvm.utils.admin_utils import AdminConfig
|
||||
from nostr_dvm.utils.definitions import EventDefinitions
|
||||
from nostr_dvm.utils.dvmconfig import DVMConfig, build_default_config
|
||||
from nostr_dvm.utils.nip88_utils import NIP88Config
|
||||
from nostr_dvm.utils.nip89_utils import NIP89Config, check_and_set_d_tag
|
||||
from nostr_dvm.utils.output_utils import post_process_list_to_events
|
||||
|
||||
"""
|
||||
This File contains a Generic DVM that can be overwritten by the user
|
||||
@@ -71,8 +69,7 @@ class GenericDVM(DVMTaskInterface):
|
||||
# We build an example here that we can call by either calling this file directly from the main directory,
|
||||
# or by adding it to our playground. You can call the example and adjust it to your needs or redefine it in the
|
||||
# playground or elsewhere
|
||||
def build_example(name, identifier, admin_config, announce = False):
|
||||
|
||||
def build_example(name, identifier, admin_config, announce=False):
|
||||
admin_config = AdminConfig()
|
||||
admin_config.REBROADCAST_NIP89 = announce
|
||||
admin_config.REBROADCAST_NIP65_RELAY_LIST = announce
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import json
|
||||
import os
|
||||
import time
|
||||
from io import BytesIO
|
||||
|
||||
import requests
|
||||
@@ -120,6 +119,7 @@ class ImageGenerationDALLE(DVMTaskInterface):
|
||||
raise Exception('Your request was rejected as a result of OpenAI´s safety system. Your prompt may '
|
||||
'contain text that is not allowed by their safety system.')
|
||||
|
||||
|
||||
# We build an example here that we can call by either calling this file directly from the main directory,
|
||||
# or by adding it to our playground. You can call the example and adjust it to your needs or redefine it in the
|
||||
# playground or elsewhere
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import json
|
||||
import os
|
||||
|
||||
from PIL import Image
|
||||
from nostr_sdk import Kind
|
||||
from tqdm import tqdm
|
||||
|
||||
@@ -7,10 +7,10 @@ from nostr_sdk import Kind
|
||||
from nostr_dvm.backends.nova_server.utils import check_server_status, send_request_to_server
|
||||
from nostr_dvm.interfaces.dvmtaskinterface import DVMTaskInterface, process_venv
|
||||
from nostr_dvm.utils.admin_utils import AdminConfig
|
||||
from nostr_dvm.utils.definitions import EventDefinitions
|
||||
from nostr_dvm.utils.dvmconfig import DVMConfig, build_default_config
|
||||
from nostr_dvm.utils.nip88_utils import NIP88Config
|
||||
from nostr_dvm.utils.nip89_utils import NIP89Config, check_and_set_d_tag
|
||||
from nostr_dvm.utils.definitions import EventDefinitions
|
||||
|
||||
"""
|
||||
This File contains a module to transform Text input on n-server and receive results back.
|
||||
|
||||
@@ -7,10 +7,10 @@ from nostr_sdk import Kind
|
||||
from nostr_dvm.backends.nova_server.utils import check_server_status, send_request_to_server
|
||||
from nostr_dvm.interfaces.dvmtaskinterface import DVMTaskInterface, process_venv
|
||||
from nostr_dvm.utils.admin_utils import AdminConfig
|
||||
from nostr_dvm.utils.definitions import EventDefinitions
|
||||
from nostr_dvm.utils.dvmconfig import DVMConfig, build_default_config
|
||||
from nostr_dvm.utils.nip88_utils import NIP88Config
|
||||
from nostr_dvm.utils.nip89_utils import NIP89Config, check_and_set_d_tag
|
||||
from nostr_dvm.utils.definitions import EventDefinitions
|
||||
|
||||
"""
|
||||
This File contains a Module to transform Image (and Text) input on N-server and receive results back.
|
||||
|
||||
@@ -7,10 +7,10 @@ from nostr_sdk import Kind
|
||||
from nostr_dvm.backends.nova_server.utils import check_server_status, send_request_to_server
|
||||
from nostr_dvm.interfaces.dvmtaskinterface import DVMTaskInterface, process_venv
|
||||
from nostr_dvm.utils.admin_utils import AdminConfig
|
||||
from nostr_dvm.utils.definitions import EventDefinitions
|
||||
from nostr_dvm.utils.dvmconfig import DVMConfig, build_default_config
|
||||
from nostr_dvm.utils.nip88_utils import NIP88Config
|
||||
from nostr_dvm.utils.nip89_utils import NIP89Config, check_and_set_d_tag
|
||||
from nostr_dvm.utils.definitions import EventDefinitions
|
||||
|
||||
"""
|
||||
This File contains a Module to extract a prompt from an image from an url.
|
||||
|
||||
@@ -7,10 +7,10 @@ from nostr_sdk import Kind
|
||||
from nostr_dvm.backends.nova_server.utils import check_server_status, send_request_to_server
|
||||
from nostr_dvm.interfaces.dvmtaskinterface import DVMTaskInterface, process_venv
|
||||
from nostr_dvm.utils.admin_utils import AdminConfig
|
||||
from nostr_dvm.utils.definitions import EventDefinitions
|
||||
from nostr_dvm.utils.dvmconfig import DVMConfig, build_default_config
|
||||
from nostr_dvm.utils.nip88_utils import NIP88Config
|
||||
from nostr_dvm.utils.nip89_utils import NIP89Config, check_and_set_d_tag
|
||||
from nostr_dvm.utils.definitions import EventDefinitions
|
||||
|
||||
"""
|
||||
This File contains a Module to upscale an image from an url by factor 2-4
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import asyncio
|
||||
import csv
|
||||
import json
|
||||
import os
|
||||
@@ -6,21 +5,35 @@ import time
|
||||
from datetime import timedelta
|
||||
|
||||
import networkx as nx
|
||||
import pandas as pd
|
||||
from nostr_sdk import Client, Timestamp, PublicKey, Tag, Keys, Options, SecretKey, NostrSigner, NostrDatabase, \
|
||||
ClientBuilder, Filter, NegentropyOptions, NegentropyDirection, init_logger, LogLevel, Event, EventId, Kind, \
|
||||
RelayOptions
|
||||
from nostr_sdk import Timestamp, PublicKey, Tag, Keys, Options, SecretKey, NostrSigner, NostrDatabase, \
|
||||
ClientBuilder, Filter, NegentropyOptions, NegentropyDirection, init_logger, LogLevel, Kind
|
||||
|
||||
from nostr_dvm.interfaces.dvmtaskinterface import DVMTaskInterface, process_venv
|
||||
from nostr_dvm.utils import definitions
|
||||
from nostr_dvm.utils.admin_utils import AdminConfig
|
||||
from nostr_dvm.utils.definitions import EventDefinitions
|
||||
from nostr_dvm.utils.dvmconfig import DVMConfig, build_default_config
|
||||
from nostr_dvm.utils.nip88_utils import NIP88Config, check_and_set_d_tag_nip88, check_and_set_tiereventid_nip88
|
||||
from nostr_dvm.utils.nip89_utils import NIP89Config, check_and_set_d_tag, create_amount_tag
|
||||
from nostr_dvm.utils.output_utils import post_process_list_to_events, post_process_list_to_users
|
||||
from nostr_dvm.utils.wot_utils import build_wot_network, save_network, load_network, print_results, \
|
||||
convert_index_to_hex
|
||||
from nostr_dvm.utils.output_utils import post_process_list_to_users
|
||||
from nostr_dvm.utils.wot_utils import build_wot_network, save_network, load_network, convert_index_to_hex
|
||||
import csv
|
||||
import json
|
||||
import os
|
||||
import time
|
||||
from datetime import timedelta
|
||||
|
||||
import networkx as nx
|
||||
from nostr_sdk import Timestamp, PublicKey, Tag, Keys, Options, SecretKey, NostrSigner, NostrDatabase, \
|
||||
ClientBuilder, Filter, NegentropyOptions, NegentropyDirection, init_logger, LogLevel, Kind
|
||||
|
||||
from nostr_dvm.interfaces.dvmtaskinterface import DVMTaskInterface, process_venv
|
||||
from nostr_dvm.utils.admin_utils import AdminConfig
|
||||
from nostr_dvm.utils.definitions import EventDefinitions
|
||||
from nostr_dvm.utils.dvmconfig import DVMConfig, build_default_config
|
||||
from nostr_dvm.utils.nip88_utils import NIP88Config, check_and_set_d_tag_nip88, check_and_set_tiereventid_nip88
|
||||
from nostr_dvm.utils.nip89_utils import NIP89Config, check_and_set_d_tag, create_amount_tag
|
||||
from nostr_dvm.utils.output_utils import post_process_list_to_users
|
||||
from nostr_dvm.utils.wot_utils import build_wot_network, save_network, load_network, convert_index_to_hex
|
||||
|
||||
"""
|
||||
This File contains a Module to discover users followed by users you follow, based on WOT
|
||||
@@ -123,7 +136,6 @@ class DiscoverPeopleMyWOT(DVMTaskInterface):
|
||||
else:
|
||||
return self.result
|
||||
|
||||
|
||||
async def calculate_result(self, request_form):
|
||||
from types import SimpleNamespace
|
||||
ns = SimpleNamespace()
|
||||
@@ -137,11 +149,11 @@ class DiscoverPeopleMyWOT(DVMTaskInterface):
|
||||
print("Creating new file")
|
||||
# sync the database, this might take a while if it's empty or hasn't been updated in a long time
|
||||
|
||||
|
||||
#hop1
|
||||
# hop1
|
||||
user_id = PublicKey.parse(options["user"]).to_hex()
|
||||
|
||||
index_map, G = await build_wot_network(options["user"], depth=int(options["hops"]), max_batch=500, max_time_request=10)
|
||||
index_map, G = await build_wot_network(options["user"], depth=int(options["hops"]), max_batch=500,
|
||||
max_time_request=10)
|
||||
if use_files:
|
||||
save_network(index_map, G, options["user"])
|
||||
|
||||
@@ -161,17 +173,13 @@ class DiscoverPeopleMyWOT(DVMTaskInterface):
|
||||
|
||||
pr = nx.pagerank(G, tol=1e-12)
|
||||
|
||||
#await print_results(pr, index_map, int(options["max_results"]), getmetadata=False)
|
||||
# await print_results(pr, index_map, int(options["max_results"]), getmetadata=False)
|
||||
result = await convert_index_to_hex(pr, index_map, int(options["max_results"]))
|
||||
print(result)
|
||||
toc = time.time()
|
||||
print(f'finished in {toc - tic} seconds')
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#sorted_nodes = sorted([(node, pagerank) for node, pagerank in result.items()],
|
||||
# sorted_nodes = sorted([(node, pagerank) for node, pagerank in result.items()],
|
||||
# key=lambda x: pr[x[1]],
|
||||
# reverse=True)[:int(options["max_results"])]
|
||||
for node in result.items():
|
||||
@@ -270,7 +278,8 @@ async def analyse_users(user_ids=None, dunbar=100000000):
|
||||
frens.append(tag.as_vec()[1])
|
||||
allfriends.append(Friend(follower.author().to_hex(), frens))
|
||||
else:
|
||||
print("Skipping friend: " + follower.author().to_hex() + "Following: " + str(len(follower.tags())) + " npubs")
|
||||
print("Skipping friend: " + follower.author().to_hex() + "Following: " + str(
|
||||
len(follower.tags())) + " npubs")
|
||||
|
||||
return allfriends
|
||||
else:
|
||||
@@ -343,7 +352,7 @@ def build_example(name, identifier, admin_config, options, cost=0, update_rate=1
|
||||
# admin_config.REBROADCAST_NIP89 = False
|
||||
|
||||
return DiscoverPeopleWOT(name=name, dvm_config=dvm_config, nip89config=nip89config,
|
||||
admin_config=admin_config, options=options)
|
||||
admin_config=admin_config, options=options)
|
||||
|
||||
|
||||
def build_example_subscription(name, identifier, admin_config, options, update_rate=180, processing_msg=None,
|
||||
@@ -406,8 +415,8 @@ def build_example_subscription(name, identifier, admin_config, options, update_r
|
||||
# admin_config.PRIVKEY = dvm_config.PRIVATE_KEY
|
||||
|
||||
return DiscoverPeopleMyWOT(name=name, dvm_config=dvm_config, nip89config=nip89config,
|
||||
nip88config=nip88config, options=options,
|
||||
admin_config=admin_config)
|
||||
nip88config=nip88config, options=options,
|
||||
admin_config=admin_config)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import asyncio
|
||||
import csv
|
||||
import csv
|
||||
import json
|
||||
import os
|
||||
@@ -6,18 +6,16 @@ from datetime import timedelta
|
||||
|
||||
import networkx as nx
|
||||
import pandas as pd
|
||||
from nostr_sdk import Client, Timestamp, PublicKey, Tag, Keys, Options, SecretKey, NostrSigner, NostrDatabase, \
|
||||
ClientBuilder, Filter, NegentropyOptions, NegentropyDirection, init_logger, LogLevel, Event, EventId, Kind, \
|
||||
RelayOptions
|
||||
from nostr_sdk import Timestamp, PublicKey, Tag, Keys, Options, SecretKey, NostrSigner, NostrDatabase, \
|
||||
ClientBuilder, Filter, NegentropyOptions, NegentropyDirection, init_logger, LogLevel, Kind
|
||||
|
||||
from nostr_dvm.interfaces.dvmtaskinterface import DVMTaskInterface, process_venv
|
||||
from nostr_dvm.utils import definitions
|
||||
from nostr_dvm.utils.admin_utils import AdminConfig
|
||||
from nostr_dvm.utils.definitions import EventDefinitions
|
||||
from nostr_dvm.utils.dvmconfig import DVMConfig, build_default_config
|
||||
from nostr_dvm.utils.nip88_utils import NIP88Config, check_and_set_d_tag_nip88, check_and_set_tiereventid_nip88
|
||||
from nostr_dvm.utils.nip89_utils import NIP89Config, check_and_set_d_tag, create_amount_tag
|
||||
from nostr_dvm.utils.output_utils import post_process_list_to_events, post_process_list_to_users
|
||||
from nostr_dvm.utils.output_utils import post_process_list_to_users
|
||||
|
||||
"""
|
||||
This File contains a Module to discover users followed by users you follow, based on WOT
|
||||
@@ -145,12 +143,11 @@ class DiscoverPeopleWOT(DVMTaskInterface):
|
||||
print("Creating new file")
|
||||
# sync the database, this might take a while if it's empty or hasn't been updated in a long time
|
||||
|
||||
|
||||
#hop1
|
||||
# hop1
|
||||
user_id = PublicKey.parse(options["user"]).to_hex()
|
||||
|
||||
|
||||
user_friends_level1 = await analyse_users([user_id]) # for the first user, ignore dunbar, thats the user after all.
|
||||
user_friends_level1 = await analyse_users(
|
||||
[user_id]) # for the first user, ignore dunbar, thats the user after all.
|
||||
friendlist = []
|
||||
for npub in user_friends_level1[0].friends:
|
||||
friendlist.append(npub)
|
||||
@@ -268,7 +265,8 @@ async def analyse_users(user_ids=None, dunbar=100000000):
|
||||
frens.append(tag.as_vec()[1])
|
||||
allfriends.append(Friend(follower.author().to_hex(), frens))
|
||||
else:
|
||||
print("Skipping friend: " + follower.author().to_hex() + "Following: " + str(len(follower.tags())) + " npubs")
|
||||
print("Skipping friend: " + follower.author().to_hex() + "Following: " + str(
|
||||
len(follower.tags())) + " npubs")
|
||||
|
||||
return allfriends
|
||||
else:
|
||||
@@ -341,7 +339,7 @@ def build_example(name, identifier, admin_config, options, cost=0, update_rate=1
|
||||
# admin_config.REBROADCAST_NIP89 = False
|
||||
|
||||
return DiscoverPeopleWOT(name=name, dvm_config=dvm_config, nip89config=nip89config,
|
||||
admin_config=admin_config, options=options)
|
||||
admin_config=admin_config, options=options)
|
||||
|
||||
|
||||
def build_example_subscription(name, identifier, admin_config, options, update_rate=180, processing_msg=None,
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
import json
|
||||
import os
|
||||
from datetime import timedelta
|
||||
from nostr_sdk import Client, Timestamp, PublicKey, Tag, Keys, Options, SecretKey, NostrSigner, NostrDatabase, \
|
||||
ClientBuilder, Filter, NegentropyOptions, NegentropyDirection, init_logger, LogLevel, Kind
|
||||
|
||||
from nostr_sdk import Timestamp, Tag, Keys, Options, SecretKey, NostrSigner, NostrDatabase, \
|
||||
ClientBuilder, Filter, NegentropyOptions, NegentropyDirection, Kind
|
||||
|
||||
from nostr_dvm.interfaces.dvmtaskinterface import DVMTaskInterface, process_venv
|
||||
from nostr_dvm.utils.admin_utils import AdminConfig
|
||||
@@ -10,7 +11,7 @@ from nostr_dvm.utils.definitions import EventDefinitions
|
||||
from nostr_dvm.utils.dvmconfig import DVMConfig, build_default_config
|
||||
from nostr_dvm.utils.nip88_utils import NIP88Config
|
||||
from nostr_dvm.utils.nip89_utils import NIP89Config, check_and_set_d_tag
|
||||
from nostr_dvm.utils.output_utils import post_process_list_to_events, post_process_list_to_users
|
||||
from nostr_dvm.utils.output_utils import post_process_list_to_users
|
||||
|
||||
"""
|
||||
This File contains a Module to search for notes
|
||||
@@ -29,8 +30,6 @@ class SearchUser(DVMTaskInterface):
|
||||
db_name = "db/nostr_profiles.db"
|
||||
relay = "wss://profiles.nostr1.com"
|
||||
|
||||
|
||||
|
||||
async def init_dvm(self, name, dvm_config: DVMConfig, nip89config: NIP89Config, nip88config: NIP88Config = None,
|
||||
admin_config: AdminConfig = None, options=None):
|
||||
dvm_config.SCRIPT = os.path.abspath(__file__)
|
||||
|
||||
@@ -3,6 +3,7 @@ import os
|
||||
import re
|
||||
|
||||
from nostr_sdk import Tag, Kind
|
||||
|
||||
from nostr_dvm.interfaces.dvmtaskinterface import DVMTaskInterface, process_venv
|
||||
from nostr_dvm.utils.admin_utils import AdminConfig
|
||||
from nostr_dvm.utils.definitions import EventDefinitions
|
||||
@@ -58,11 +59,11 @@ class SummarizationDuckDuck(DVMTaskInterface):
|
||||
# prompt += evt.content() + "\n"
|
||||
elif input_type == "job":
|
||||
evt = await get_referenced_event_by_id(event_id=tag.as_vec()[1], client=client,
|
||||
kinds=[EventDefinitions.KIND_NIP90_RESULT_EXTRACT_TEXT,
|
||||
EventDefinitions.KIND_NIP90_RESULT_SUMMARIZE_TEXT,
|
||||
EventDefinitions.KIND_NIP90_RESULT_TRANSLATE_TEXT,
|
||||
EventDefinitions.KIND_NIP90_RESULT_CONTENT_DISCOVERY],
|
||||
dvm_config=dvm_config)
|
||||
kinds=[EventDefinitions.KIND_NIP90_RESULT_EXTRACT_TEXT,
|
||||
EventDefinitions.KIND_NIP90_RESULT_SUMMARIZE_TEXT,
|
||||
EventDefinitions.KIND_NIP90_RESULT_TRANSLATE_TEXT,
|
||||
EventDefinitions.KIND_NIP90_RESULT_CONTENT_DISCOVERY],
|
||||
dvm_config=dvm_config)
|
||||
if evt is None:
|
||||
print("Event not found")
|
||||
raise Exception
|
||||
@@ -109,7 +110,6 @@ class SummarizationDuckDuck(DVMTaskInterface):
|
||||
raise Exception(e)
|
||||
|
||||
|
||||
|
||||
# We build an example here that we can call by either calling this file directly from the main directory,
|
||||
# or by adding it to our playground. You can call the example and adjust it to your needs or redefine it in the
|
||||
# playground or elsewhere
|
||||
@@ -134,7 +134,7 @@ def build_example(name, identifier, admin_config):
|
||||
admin_config2.REBROADCAST_NIP89 = False
|
||||
|
||||
return SummarizationDuckDuck(name=name, dvm_config=dvm_config, nip89config=nip89config,
|
||||
admin_config=admin_config2)
|
||||
admin_config=admin_config2)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
@@ -2,6 +2,8 @@ import json
|
||||
import os
|
||||
import re
|
||||
|
||||
from nostr_sdk import Tag, Kind
|
||||
|
||||
from nostr_dvm.interfaces.dvmtaskinterface import DVMTaskInterface, process_venv
|
||||
from nostr_dvm.utils.admin_utils import AdminConfig
|
||||
from nostr_dvm.utils.definitions import EventDefinitions
|
||||
@@ -9,7 +11,6 @@ from nostr_dvm.utils.dvmconfig import DVMConfig, build_default_config
|
||||
from nostr_dvm.utils.nip88_utils import NIP88Config
|
||||
from nostr_dvm.utils.nip89_utils import NIP89Config, check_and_set_d_tag
|
||||
from nostr_dvm.utils.nostr_utils import get_referenced_event_by_id, get_event_by_id, get_events_by_ids
|
||||
from nostr_sdk import Tag, Kind
|
||||
|
||||
"""
|
||||
This File contains a Module to summarize Text, based on a prompt using a the HuggingChat LLM on Huggingface
|
||||
@@ -26,7 +27,6 @@ class TextSummarizationHuggingChat(DVMTaskInterface):
|
||||
dependencies = [("nostr-dvm", "nostr-dvm"),
|
||||
("hugchat", "hugchat")]
|
||||
|
||||
|
||||
async def init_dvm(self, name, dvm_config: DVMConfig, nip89config: NIP89Config, nip88config: NIP88Config = None,
|
||||
admin_config: AdminConfig = None, options=None):
|
||||
dvm_config.SCRIPT = os.path.abspath(__file__)
|
||||
@@ -57,11 +57,11 @@ class TextSummarizationHuggingChat(DVMTaskInterface):
|
||||
# prompt += evt.content() + "\n"
|
||||
elif input_type == "job":
|
||||
evt = await get_referenced_event_by_id(event_id=tag.as_vec()[1], client=client,
|
||||
kinds=[EventDefinitions.KIND_NIP90_RESULT_EXTRACT_TEXT,
|
||||
EventDefinitions.KIND_NIP90_RESULT_SUMMARIZE_TEXT,
|
||||
EventDefinitions.KIND_NIP90_RESULT_TRANSLATE_TEXT,
|
||||
EventDefinitions.KIND_NIP90_RESULT_CONTENT_DISCOVERY],
|
||||
dvm_config=dvm_config)
|
||||
kinds=[EventDefinitions.KIND_NIP90_RESULT_EXTRACT_TEXT,
|
||||
EventDefinitions.KIND_NIP90_RESULT_SUMMARIZE_TEXT,
|
||||
EventDefinitions.KIND_NIP90_RESULT_TRANSLATE_TEXT,
|
||||
EventDefinitions.KIND_NIP90_RESULT_CONTENT_DISCOVERY],
|
||||
dvm_config=dvm_config)
|
||||
if evt is None:
|
||||
print("Event not found")
|
||||
raise Exception
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
import json
|
||||
import os
|
||||
import re
|
||||
|
||||
from nostr_sdk import Tag, Kind
|
||||
|
||||
from nostr_dvm.interfaces.dvmtaskinterface import DVMTaskInterface, process_venv
|
||||
from nostr_dvm.utils.admin_utils import AdminConfig
|
||||
from nostr_dvm.utils.definitions import EventDefinitions
|
||||
@@ -57,11 +59,11 @@ class SummarizationUnleashedChat(DVMTaskInterface):
|
||||
# prompt += evt.content() + "\n"
|
||||
elif input_type == "job":
|
||||
evt = await get_referenced_event_by_id(event_id=tag.as_vec()[1], client=client,
|
||||
kinds=[EventDefinitions.KIND_NIP90_RESULT_EXTRACT_TEXT,
|
||||
EventDefinitions.KIND_NIP90_RESULT_SUMMARIZE_TEXT,
|
||||
EventDefinitions.KIND_NIP90_RESULT_TRANSLATE_TEXT,
|
||||
EventDefinitions.KIND_NIP90_RESULT_CONTENT_DISCOVERY],
|
||||
dvm_config=dvm_config)
|
||||
kinds=[EventDefinitions.KIND_NIP90_RESULT_EXTRACT_TEXT,
|
||||
EventDefinitions.KIND_NIP90_RESULT_SUMMARIZE_TEXT,
|
||||
EventDefinitions.KIND_NIP90_RESULT_TRANSLATE_TEXT,
|
||||
EventDefinitions.KIND_NIP90_RESULT_CONTENT_DISCOVERY],
|
||||
dvm_config=dvm_config)
|
||||
if evt is None:
|
||||
print("Event not found")
|
||||
raise Exception
|
||||
|
||||
@@ -6,11 +6,11 @@ from nostr_sdk import Kind
|
||||
|
||||
from nostr_dvm.interfaces.dvmtaskinterface import DVMTaskInterface, process_venv
|
||||
from nostr_dvm.utils.admin_utils import AdminConfig
|
||||
from nostr_dvm.utils.definitions import EventDefinitions
|
||||
from nostr_dvm.utils.dvmconfig import DVMConfig, build_default_config
|
||||
from nostr_dvm.utils.mediasource_utils import organize_input_media_data
|
||||
from nostr_dvm.utils.nip88_utils import NIP88Config
|
||||
from nostr_dvm.utils.nip89_utils import NIP89Config, check_and_set_d_tag
|
||||
from nostr_dvm.utils.definitions import EventDefinitions
|
||||
|
||||
"""
|
||||
This File contains a Module to extract text form a media file input on Google Cloud
|
||||
@@ -33,7 +33,6 @@ class SpeechToTextGoogle(DVMTaskInterface):
|
||||
admin_config: AdminConfig = None, options=None):
|
||||
dvm_config.SCRIPT = os.path.abspath(__file__)
|
||||
|
||||
|
||||
async def is_input_supported(self, tags, client=None, dvm_config=None):
|
||||
for tag in tags:
|
||||
if tag.as_vec()[0] == 'i':
|
||||
@@ -95,7 +94,7 @@ class SpeechToTextGoogle(DVMTaskInterface):
|
||||
end_time = float(tag.as_vec()[3])
|
||||
|
||||
filepath = await organize_input_media_data(url, input_type, start_time, end_time, dvm_config, client, True,
|
||||
media_format)
|
||||
media_format)
|
||||
options = {
|
||||
"filepath": filepath,
|
||||
"language": language,
|
||||
|
||||
@@ -8,11 +8,11 @@ from nostr_sdk import Kind
|
||||
from nostr_dvm.backends.nova_server.utils import check_server_status, send_request_to_server, send_file_to_server
|
||||
from nostr_dvm.interfaces.dvmtaskinterface import DVMTaskInterface, process_venv
|
||||
from nostr_dvm.utils.admin_utils import AdminConfig
|
||||
from nostr_dvm.utils.definitions import EventDefinitions
|
||||
from nostr_dvm.utils.dvmconfig import DVMConfig, build_default_config
|
||||
from nostr_dvm.utils.mediasource_utils import organize_input_media_data
|
||||
from nostr_dvm.utils.nip88_utils import NIP88Config
|
||||
from nostr_dvm.utils.nip89_utils import NIP89Config, check_and_set_d_tag
|
||||
from nostr_dvm.utils.definitions import EventDefinitions
|
||||
|
||||
"""
|
||||
This File contains a Module to transform A media file input on n-server and receive results back.
|
||||
@@ -105,7 +105,7 @@ class SpeechToTextWhisperX(DVMTaskInterface):
|
||||
end_time = float(tag.as_vec()[3])
|
||||
|
||||
filepath = await organize_input_media_data(url, input_type, start_time, end_time, dvm_config, client, True,
|
||||
media_format)
|
||||
media_format)
|
||||
path_on_server = send_file_to_server(os.path.realpath(filepath), self.options['server'])
|
||||
|
||||
io_input = {
|
||||
|
||||
@@ -68,7 +68,6 @@ class TextGenerationHuggingChat(DVMTaskInterface):
|
||||
cookies = sign.login()
|
||||
sign.saveCookiesToDir(cookie_path_dir)
|
||||
|
||||
|
||||
options = self.set_options(request_form)
|
||||
|
||||
try:
|
||||
|
||||
@@ -42,7 +42,7 @@ class TextGenerationUnleashedChat(DVMTaskInterface):
|
||||
async def create_request_from_nostr_event(self, event, client=None, dvm_config=None):
|
||||
request_form = {"jobID": event.id().to_hex() + "_" + self.NAME.replace(" ", "")}
|
||||
prompt = ""
|
||||
nostr_mode= True
|
||||
nostr_mode = True
|
||||
|
||||
for tag in event.tags():
|
||||
if tag.as_vec()[0] == 'i':
|
||||
@@ -111,7 +111,6 @@ def build_example(name, identifier, admin_config):
|
||||
dvm_config.SEND_FEEDBACK_EVENTS = False
|
||||
admin_config.LUD16 = dvm_config.LN_ADDRESS
|
||||
|
||||
|
||||
nip89info = {
|
||||
"name": name,
|
||||
"image": "https://unleashed.chat/_app/immutable/assets/hero.pehsu4x_.jpeg",
|
||||
@@ -125,7 +124,8 @@ def build_example(name, identifier, admin_config):
|
||||
nip89config.DTAG = check_and_set_d_tag(identifier, name, dvm_config.PRIVATE_KEY, nip89info["image"])
|
||||
nip89config.CONTENT = json.dumps(nip89info)
|
||||
|
||||
return TextGenerationUnleashedChat(name=name, dvm_config=dvm_config, nip89config=nip89config, admin_config=admin_config, )
|
||||
return TextGenerationUnleashedChat(name=name, dvm_config=dvm_config, nip89config=nip89config,
|
||||
admin_config=admin_config, )
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
@@ -4,7 +4,6 @@ import os
|
||||
import ffmpegio
|
||||
from nostr_sdk import Kind
|
||||
|
||||
from nostr_dvm.utils.mediasource_utils import organize_input_media_data
|
||||
from nostr_dvm.utils.nip88_utils import NIP88Config
|
||||
|
||||
os.environ["PYTORCH_ENABLE_MPS_FALLBACK"] = "1"
|
||||
@@ -19,7 +18,6 @@ from nostr_dvm.utils.nip89_utils import NIP89Config, check_and_set_d_tag
|
||||
from nostr_dvm.utils.output_utils import upload_media_to_hoster
|
||||
from nostr_dvm.utils.nostr_utils import get_event_by_id, get_referenced_event_by_id
|
||||
|
||||
|
||||
"""
|
||||
This File contains a Module to generate Audio based on an input and a voice
|
||||
|
||||
@@ -48,11 +46,11 @@ class TextToSpeech(DVMTaskInterface):
|
||||
input_type = tag.as_vec()[2]
|
||||
if input_type != "event" and input_type != "job" and input_type != "text":
|
||||
return False
|
||||
#if input_type == "text" and len(input_value) > 250:
|
||||
# if input_type == "text" and len(input_value) > 250:
|
||||
# return False
|
||||
if input_type == "event":
|
||||
evt = await get_event_by_id(tag.as_vec()[1], client=client, config=dvm_config)
|
||||
#if len(evt.content()) > 250:
|
||||
# if len(evt.content()) > 250:
|
||||
# return False
|
||||
elif tag.as_vec()[0] == 'param':
|
||||
param = tag.as_vec()[1]
|
||||
@@ -90,10 +88,10 @@ class TextToSpeech(DVMTaskInterface):
|
||||
elif input_type == "job":
|
||||
|
||||
evt = await get_referenced_event_by_id(event_id=tag.as_vec()[1], client=client,
|
||||
kinds=[EventDefinitions.KIND_NIP90_RESULT_EXTRACT_TEXT,
|
||||
EventDefinitions.KIND_NIP90_RESULT_SUMMARIZE_TEXT,
|
||||
EventDefinitions.KIND_NIP90_RESULT_TRANSLATE_TEXT],
|
||||
dvm_config=dvm_config)
|
||||
kinds=[EventDefinitions.KIND_NIP90_RESULT_EXTRACT_TEXT,
|
||||
EventDefinitions.KIND_NIP90_RESULT_SUMMARIZE_TEXT,
|
||||
EventDefinitions.KIND_NIP90_RESULT_TRANSLATE_TEXT],
|
||||
dvm_config=dvm_config)
|
||||
prompt = evt.content()
|
||||
if input_type == "url":
|
||||
input_file = tag.as_vec()[1]
|
||||
@@ -125,7 +123,7 @@ class TextToSpeech(DVMTaskInterface):
|
||||
|
||||
options = self.set_options(request_form)
|
||||
device = "cuda" if torch.cuda.is_available() else "cpu"
|
||||
#else "mps" if torch.backends.mps.is_available()
|
||||
# else "mps" if torch.backends.mps.is_available()
|
||||
print(device)
|
||||
|
||||
print(TTS().list_models().list_tts_models())
|
||||
|
||||
@@ -57,10 +57,10 @@ class TranslationGoogle(DVMTaskInterface):
|
||||
text = tag.as_vec()[1]
|
||||
elif input_type == "job":
|
||||
evt = await get_referenced_event_by_id(event_id=tag.as_vec()[1], client=client,
|
||||
kinds=[EventDefinitions.KIND_NIP90_RESULT_EXTRACT_TEXT,
|
||||
EventDefinitions.KIND_NIP90_RESULT_SUMMARIZE_TEXT,
|
||||
EventDefinitions.KIND_NIP90_RESULT_TRANSLATE_TEXT],
|
||||
dvm_config=dvm_config)
|
||||
kinds=[EventDefinitions.KIND_NIP90_RESULT_EXTRACT_TEXT,
|
||||
EventDefinitions.KIND_NIP90_RESULT_SUMMARIZE_TEXT,
|
||||
EventDefinitions.KIND_NIP90_RESULT_TRANSLATE_TEXT],
|
||||
dvm_config=dvm_config)
|
||||
text = evt.content()
|
||||
|
||||
elif tag.as_vec()[0] == 'param':
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import json
|
||||
import os
|
||||
|
||||
import requests
|
||||
from nostr_sdk import Kind
|
||||
|
||||
@@ -57,10 +58,10 @@ class TranslationLibre(DVMTaskInterface):
|
||||
text = tag.as_vec()[1]
|
||||
elif input_type == "job":
|
||||
evt = await get_referenced_event_by_id(event_id=tag.as_vec()[1], client=client,
|
||||
kinds=[EventDefinitions.KIND_NIP90_RESULT_EXTRACT_TEXT,
|
||||
EventDefinitions.KIND_NIP90_RESULT_SUMMARIZE_TEXT,
|
||||
EventDefinitions.KIND_NIP90_RESULT_TRANSLATE_TEXT],
|
||||
dvm_config=dvm_config)
|
||||
kinds=[EventDefinitions.KIND_NIP90_RESULT_EXTRACT_TEXT,
|
||||
EventDefinitions.KIND_NIP90_RESULT_SUMMARIZE_TEXT,
|
||||
EventDefinitions.KIND_NIP90_RESULT_TRANSLATE_TEXT],
|
||||
dvm_config=dvm_config)
|
||||
text = evt.content()
|
||||
|
||||
elif tag.as_vec()[0] == 'param':
|
||||
@@ -147,6 +148,5 @@ def build_example(name, identifier, admin_config):
|
||||
admin_config=admin_config, options=options)
|
||||
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
process_venv(TranslationLibre)
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
import json
|
||||
import os
|
||||
from io import BytesIO
|
||||
import requests
|
||||
import urllib.request
|
||||
from io import BytesIO
|
||||
|
||||
import requests
|
||||
from PIL import Image
|
||||
from nostr_sdk import Kind
|
||||
|
||||
|
||||
@@ -7,10 +7,10 @@ from nostr_sdk import Kind
|
||||
from nostr_dvm.backends.nova_server.utils import check_server_status, send_request_to_server
|
||||
from nostr_dvm.interfaces.dvmtaskinterface import DVMTaskInterface, process_venv
|
||||
from nostr_dvm.utils.admin_utils import AdminConfig
|
||||
from nostr_dvm.utils.definitions import EventDefinitions
|
||||
from nostr_dvm.utils.dvmconfig import DVMConfig, build_default_config
|
||||
from nostr_dvm.utils.nip88_utils import NIP88Config
|
||||
from nostr_dvm.utils.nip89_utils import NIP89Config, check_and_set_d_tag
|
||||
from nostr_dvm.utils.definitions import EventDefinitions
|
||||
|
||||
"""
|
||||
This File contains a module to transform an Image to a short Video Clip on n-server and receive results back.
|
||||
@@ -45,8 +45,7 @@ class VideoGenerationSVD(DVMTaskInterface):
|
||||
|
||||
url = ""
|
||||
frames = 7 # 25
|
||||
model = "stabilityai/stable-video-diffusion-img2vid-xt" #,stabilityai/stable-video-diffusion-img2vid
|
||||
|
||||
model = "stabilityai/stable-video-diffusion-img2vid-xt" # ,stabilityai/stable-video-diffusion-img2vid
|
||||
|
||||
for tag in event.tags():
|
||||
if tag.as_vec()[0] == 'i':
|
||||
@@ -120,7 +119,7 @@ def build_example(name, identifier, admin_config, server_address):
|
||||
nip89config.CONTENT = json.dumps(nip89info)
|
||||
|
||||
return VideoGenerationSVD(name=name, dvm_config=dvm_config, nip89config=nip89config,
|
||||
admin_config=admin_config, options=options)
|
||||
admin_config=admin_config, options=options)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
Reference in New Issue
Block a user