mirror of
https://github.com/Paillat-dev/viralfactory.git
synced 2026-01-02 01:06:19 +00:00
Add Scientific facts script & open folder button
This commit is contained in:
@@ -100,6 +100,7 @@ class GenerationContext:
|
|||||||
self.index_7 = []
|
self.index_7 = []
|
||||||
self.index_8 = []
|
self.index_8 = []
|
||||||
self.index_9 = []
|
self.index_9 = []
|
||||||
|
self.credits = "Generated by AI"
|
||||||
|
|
||||||
self.progress(0.1, "Loading settings...")
|
self.progress(0.1, "Loading settings...")
|
||||||
self.setup_dir()
|
self.setup_dir()
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ class VideoBackgroundEngine(BaseBackgroundEngine):
|
|||||||
|
|
||||||
def __init__(self, options: list[str]):
|
def __init__(self, options: list[str]):
|
||||||
assets = self.get_assets(type="bcg_video")
|
assets = self.get_assets(type="bcg_video")
|
||||||
self.background_video = [asset.data["path"] for asset in assets if asset.data["name"] == options[0]][0]
|
self.background_video = [asset for asset in assets if asset.data["name"] == options[0]][0]
|
||||||
super().__init__()
|
super().__init__()
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
@@ -39,7 +39,7 @@ class VideoBackgroundEngine(BaseBackgroundEngine):
|
|||||||
]
|
]
|
||||||
|
|
||||||
def get_background(self):
|
def get_background(self):
|
||||||
background = mp.VideoFileClip(f"{self.background_video}", audio=False)
|
background = mp.VideoFileClip(f"{self.background_video.path}", audio=False)
|
||||||
background_max_start = background.duration - self.ctx.duration
|
background_max_start = background.duration - self.ctx.duration
|
||||||
if background_max_start < 0:
|
if background_max_start < 0:
|
||||||
raise ValueError(
|
raise ValueError(
|
||||||
@@ -48,6 +48,7 @@ class VideoBackgroundEngine(BaseBackgroundEngine):
|
|||||||
start = random.uniform(0, background_max_start)
|
start = random.uniform(0, background_max_start)
|
||||||
clip = background.subclip(start, start + self.ctx.duration)
|
clip = background.subclip(start, start + self.ctx.duration)
|
||||||
w, h = clip.size
|
w, h = clip.size
|
||||||
|
self.ctx.credits += f"\n{self.background_video.data['credits']}"
|
||||||
self.ctx.index_0.append(
|
self.ctx.index_0.append(
|
||||||
crop(
|
crop(
|
||||||
clip,
|
clip,
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
from .BaseScriptEngine import BaseScriptEngine
|
from .BaseScriptEngine import BaseScriptEngine
|
||||||
from .CustomScriptEngine import CustomScriptEngine
|
from .CustomScriptEngine import CustomScriptEngine
|
||||||
from .ShowerThoughtsScriptEngine import ShowerThoughtsScriptEngine
|
from .ShowerThoughtsScriptEngine import ShowerThoughtsScriptEngine
|
||||||
|
from .ScientificFactsScriptEngine import ScientificFactsScriptEngine
|
||||||
@@ -28,6 +28,7 @@ ENGINES: dict[str, dict[str, bool | list[BaseEngine]]] = {
|
|||||||
"classes": [
|
"classes": [
|
||||||
ScriptEngine.ShowerThoughtsScriptEngine,
|
ScriptEngine.ShowerThoughtsScriptEngine,
|
||||||
ScriptEngine.CustomScriptEngine,
|
ScriptEngine.CustomScriptEngine,
|
||||||
|
ScriptEngine.ScientificFactsScriptEngine,
|
||||||
],
|
],
|
||||||
"multiple": False,
|
"multiple": False,
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
import os
|
||||||
|
|
||||||
import gradio as gr
|
import gradio as gr
|
||||||
import orjson
|
import orjson
|
||||||
|
|
||||||
@@ -169,22 +171,34 @@ class GenerateUI:
|
|||||||
load_preset = self.get_preset_func()
|
load_preset = self.get_preset_func()
|
||||||
preset_button.click(load_preset, inputs=[preset_dropdown, *inputs],
|
preset_button.click(load_preset, inputs=[preset_dropdown, *inputs],
|
||||||
outputs=[preset_dropdown, *inputs])
|
outputs=[preset_dropdown, *inputs])
|
||||||
output_gallery = gr.Markdown("aaa", render=False)
|
output_title = gr.Markdown(visible=True, render=False)
|
||||||
|
output_description = gr.Markdown(visible=True, render=False)
|
||||||
|
output_video = gr.Video(visible=True, render=False)
|
||||||
|
open_folder = gr.Button("📁", size="sm", variant="secondary", render=False)
|
||||||
|
output_path = gr.State(value=None)
|
||||||
button.click(
|
button.click(
|
||||||
self.run_generate_interface,
|
self.run_generate_interface,
|
||||||
inputs=inputs,
|
inputs=inputs,
|
||||||
outputs=output_gallery,
|
outputs=[output_video, output_title, output_description, output_path, open_folder],
|
||||||
)
|
)
|
||||||
output_gallery.render()
|
with gr.Row():
|
||||||
|
with gr.Column():
|
||||||
|
output_title.render()
|
||||||
|
output_description.render()
|
||||||
|
open_folder.render()
|
||||||
|
open_folder.click(lambda x: os.system(f"open {os.path.abspath(x)}") if os.name == "posix" else os.system(f"explorer {os.abspath(x)}"), inputs=output_path)
|
||||||
|
with gr.Column():
|
||||||
|
output_video.render()
|
||||||
|
|
||||||
return interface
|
return interface
|
||||||
|
|
||||||
def run_generate_interface(self, progress=gr.Progress(), *args) -> gr.update:
|
def run_generate_interface(self, progress=gr.Progress(), *args) -> list[gr.update]:
|
||||||
progress(0, desc="Loading engines... 🚀")
|
progress(0, desc="Loading engines... 🚀")
|
||||||
options = self.repack_options(*args)
|
options = self.repack_options(*args)
|
||||||
arguments = {name.lower(): options[name] for name in ENGINES.keys()}
|
arguments = {name.lower(): options[name] for name in ENGINES.keys()}
|
||||||
ctx = GenerationContext(**arguments, progress=progress)
|
ctx = GenerationContext(**arguments, progress=progress)
|
||||||
ctx.process() # Here we go ! 🚀
|
ctx.process() # Here we go ! 🚀
|
||||||
return gr.update(value=ctx.get_file_path("final.mp4"))
|
return [gr.update(value=ctx.get_file_path("final.mp4"), visible=True), gr.update(value=ctx.title, visible=True), gr.update(value=ctx.description, visible=True), gr.update(value=ctx.dir), gr.update(visible=True)]
|
||||||
|
|
||||||
def repack_options(self, *args) -> dict[str, list[BaseEngine]]:
|
def repack_options(self, *args) -> dict[str, list[BaseEngine]]:
|
||||||
"""
|
"""
|
||||||
|
|||||||
Reference in New Issue
Block a user