mirror of
https://github.com/believethehype/nostrdvm.git
synced 2025-11-18 17:57:57 +01:00
add stable video diffusion, gif conversion
This commit is contained in:
@@ -69,9 +69,9 @@ def get_task(event, client, dvm_config):
|
||||
print("found image tag")
|
||||
elif tag.as_vec()[2] == "job":
|
||||
evt = get_referenced_event_by_id(event_id=tag.as_vec()[1], kinds=
|
||||
[EventDefinitions.KIND_NIP90_RESULT_EXTRACT_TEXT,
|
||||
EventDefinitions.KIND_NIP90_RESULT_TRANSLATE_TEXT,
|
||||
EventDefinitions.KIND_NIP90_RESULT_SUMMARIZE_TEXT],
|
||||
[EventDefinitions.KIND_NIP90_RESULT_EXTRACT_TEXT,
|
||||
EventDefinitions.KIND_NIP90_RESULT_TRANSLATE_TEXT,
|
||||
EventDefinitions.KIND_NIP90_RESULT_SUMMARIZE_TEXT],
|
||||
client=client,
|
||||
dvm_config=dvm_config)
|
||||
if evt is not None:
|
||||
@@ -88,7 +88,6 @@ def get_task(event, client, dvm_config):
|
||||
# TODO if a task can consist of multiple inputs add them here
|
||||
# This is not ideal. Maybe such events should have their own kind
|
||||
|
||||
|
||||
# else if kind is supported, simply return task
|
||||
else:
|
||||
|
||||
@@ -102,6 +101,7 @@ def get_task(event, client, dvm_config):
|
||||
|
||||
|
||||
def is_input_supported_generic(tags, client, dvm_config) -> bool:
|
||||
# Handle malformed tags, missing events etc here.
|
||||
try:
|
||||
for tag in tags:
|
||||
if tag.as_vec()[0] == 'i':
|
||||
@@ -129,17 +129,19 @@ def is_input_supported_generic(tags, client, dvm_config) -> bool:
|
||||
def check_task_is_supported(event: Event, client, config=None):
|
||||
try:
|
||||
dvm_config = config
|
||||
# Check for generic issues, event maformed, referenced event not found etc..
|
||||
if not is_input_supported_generic(event.tags(), client, dvm_config):
|
||||
return False, ""
|
||||
|
||||
# See if current dvm supports the task
|
||||
task = get_task(event, client=client, dvm_config=dvm_config)
|
||||
if task not in (x.TASK for x in dvm_config.SUPPORTED_DVMS):
|
||||
return False, task
|
||||
|
||||
if not is_input_supported_generic(event.tags(), client, dvm_config):
|
||||
return False, ""
|
||||
# See if current dvm can handle input for given task
|
||||
for dvm in dvm_config.SUPPORTED_DVMS:
|
||||
if dvm.TASK == task:
|
||||
if not dvm.is_input_supported(event.tags()):
|
||||
return False, task
|
||||
|
||||
return True, task
|
||||
|
||||
|
||||
@@ -158,14 +160,17 @@ def check_url_is_readable(url):
|
||||
# If link is comaptible with one of these file formats, move on.
|
||||
req = requests.get(url)
|
||||
content_type = req.headers['content-type']
|
||||
if content_type == 'audio/x-wav' or str(url).endswith(".wav") or content_type == 'audio/mpeg' or str(url).endswith(
|
||||
if content_type == 'audio/x-wav' or str(url).endswith(".wav") or content_type == 'audio/mpeg' or str(
|
||||
url).endswith(
|
||||
".mp3") or content_type == 'audio/ogg' or str(url).endswith(".ogg"):
|
||||
return "audio"
|
||||
elif (content_type == 'image/png' or str(url).endswith(".png") or content_type == 'image/jpg' or str(url).endswith(
|
||||
elif (content_type == 'image/png' or str(url).endswith(".png") or content_type == 'image/jpg' or str(
|
||||
url).endswith(
|
||||
".jpg") or content_type == 'image/jpeg' or str(url).endswith(".jpeg") or content_type == 'image/png' or
|
||||
str(url).endswith(".png")):
|
||||
return "image"
|
||||
elif content_type == 'video/mp4' or str(url).endswith(".mp4") or content_type == 'video/avi' or str(url).endswith(
|
||||
elif content_type == 'video/mp4' or str(url).endswith(".mp4") or content_type == 'video/avi' or str(
|
||||
url).endswith(
|
||||
".avi") or content_type == 'video/mov' or str(url).endswith(".mov"):
|
||||
return "video"
|
||||
elif (str(url)).endswith(".pdf"):
|
||||
@@ -189,7 +194,6 @@ def get_amount_per_task(task, dvm_config, duration=1):
|
||||
return None
|
||||
|
||||
|
||||
|
||||
def keep_alive():
|
||||
try:
|
||||
while True:
|
||||
@@ -197,5 +201,3 @@ def keep_alive():
|
||||
except KeyboardInterrupt:
|
||||
os.kill(os.getpid(), signal.SIGKILL)
|
||||
exit(1)
|
||||
|
||||
|
||||
|
||||
@@ -20,6 +20,8 @@ class EventDefinitions:
|
||||
KIND_NIP90_RESULT_GENERATE_IMAGE = 6100
|
||||
KIND_NIP90_CONVERT_VIDEO = 5200
|
||||
KIND_NIP90_RESULT_CONVERT_VIDEO = 6200
|
||||
KIND_NIP90_GENERATE_VIDEO = 5202
|
||||
KIND_NIP90_RESULT_GENERATE_VIDEO = 6202
|
||||
KIND_NIP90_CONTENT_DISCOVERY = 5300
|
||||
KIND_NIP90_RESULT_CONTENT_DISCOVERY = 6300
|
||||
KIND_NIP90_PEOPLE_DISCOVERY = 5301
|
||||
@@ -38,6 +40,7 @@ class EventDefinitions:
|
||||
KIND_NIP90_RESULT_CONVERT_VIDEO,
|
||||
KIND_NIP90_RESULT_CONTENT_DISCOVERY,
|
||||
KIND_NIP90_RESULT_PEOPLE_DISCOVERY,
|
||||
KIND_NIP90_RESULT_GENERATE_VIDEO,
|
||||
KIND_NIP90_RESULT_GENERIC]
|
||||
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@ import urllib
|
||||
from datetime import time
|
||||
from urllib.parse import urlparse
|
||||
import ffmpegio
|
||||
from decord import AudioReader, cpu
|
||||
from decord import AudioReader, VideoReader, cpu
|
||||
import requests
|
||||
from utils.nostr_utils import get_event_by_id
|
||||
|
||||
@@ -74,7 +74,13 @@ def organize_input_media_data(input_value, input_type, start, end, dvm_config, c
|
||||
duration = float(file_reader.duration())
|
||||
except Exception as e:
|
||||
print(e)
|
||||
return ""
|
||||
try:
|
||||
from moviepy.editor import VideoFileClip
|
||||
clip = VideoFileClip(filename)
|
||||
duration = clip.duration
|
||||
except Exception as e:
|
||||
print(e)
|
||||
return ""
|
||||
|
||||
print("Original Duration of the Media file: " + str(duration))
|
||||
start_time, end_time, new_duration = (
|
||||
@@ -95,6 +101,11 @@ def organize_input_media_data(input_value, input_type, start, end, dvm_config, c
|
||||
elif media_format.split('/')[0] == "video":
|
||||
print("Converting Video from " + str(start_time) + " until " + str(end_time))
|
||||
ffmpegio.transcode(filename, final_filename, overwrite=True, show_log=True)
|
||||
elif media_format.split('/')[1] == "gif":
|
||||
from moviepy.editor import VideoFileClip
|
||||
print("Converting Video from " + str(start_time) + " until " + str(end_time))
|
||||
videoClip = VideoFileClip(filename)
|
||||
videoClip.write_gif(final_filename, program="ffmpeg")
|
||||
print(final_filename)
|
||||
return final_filename
|
||||
else:
|
||||
|
||||
Reference in New Issue
Block a user