mirror of
https://github.com/ParisNeo/lollms.git
synced 2025-02-28 20:05:51 +00:00
upgraded luma aiu dream machine function call
This commit is contained in:
parent
9e30a6bedc
commit
5fa1f23d5d
@ -8,7 +8,7 @@ from pathlib import Path
|
||||
|
||||
# Import necessary libraries
|
||||
from functools import partial
|
||||
from typing import Dict
|
||||
from typing import Dict, Tuple
|
||||
from lollms.utilities import PackageManager
|
||||
from ascii_colors import trace_exception
|
||||
|
||||
@ -20,6 +20,38 @@ if not PackageManager.check_package_installed("pyautogui"):
|
||||
import pyautogui
|
||||
import webbrowser
|
||||
import time
|
||||
import numpy as np
|
||||
from lollms.utilities import PackageManager
|
||||
|
||||
if not PackageManager.check_package_installed("cv2"):
|
||||
PackageManager.install_package("opencv-python")
|
||||
import cv2
|
||||
from ascii_colors import ASCIIColors
|
||||
|
||||
def capture_screenshot() -> np.ndarray:
|
||||
"""Capture a screenshot of the current screen."""
|
||||
screenshot = pyautogui.screenshot()
|
||||
screenshot = cv2.cvtColor(np.array(screenshot), cv2.COLOR_RGB2BGR)
|
||||
return screenshot
|
||||
|
||||
def template_matching(screenshot: np.ndarray, template_path: str, threshold: float = 0.8) -> Tuple[int, int, int, int]:
|
||||
"""Perform template matching to find the object in the screenshot."""
|
||||
template = cv2.imread(str(template_path), cv2.IMREAD_COLOR)
|
||||
template_gray = cv2.cvtColor(template, cv2.COLOR_BGR2GRAY)
|
||||
screenshot_gray = cv2.cvtColor(screenshot, cv2.COLOR_BGR2GRAY)
|
||||
|
||||
result = cv2.matchTemplate(screenshot_gray, template_gray, cv2.TM_CCOEFF_NORMED)
|
||||
min_val, max_val, min_loc, max_loc = cv2.minMaxLoc(result)
|
||||
|
||||
ASCIIColors.blue(f"Searching results:{max_val}")
|
||||
|
||||
if max_val >= threshold:
|
||||
(startX, startY) = max_loc
|
||||
endX = startX + template.shape[1]
|
||||
endY = startY + template.shape[0]
|
||||
return (startX, startY, endX, endY)
|
||||
else:
|
||||
return None
|
||||
|
||||
def luma_ai_dream_machine_video_creator(prompt: str) -> str:
|
||||
"""
|
||||
@ -36,22 +68,30 @@ def luma_ai_dream_machine_video_creator(prompt: str) -> str:
|
||||
# Open the Luma AI Dream Machine webpage
|
||||
webbrowser.open("https://lumalabs.ai/dream-machine/creations")
|
||||
time.sleep(2) # Wait for the page to load
|
||||
|
||||
# Capture a screenshot of the browser window
|
||||
screenshot = capture_screenshot()
|
||||
# Locate the input section and type the prompt
|
||||
input_image_path = Path(__file__).parent/"input_section_image.png" # Replace with the actual path to your image
|
||||
if not input_image_path.exists():
|
||||
template_path = Path(__file__).parent/"input_section_image.png" # Replace with the actual path to your image
|
||||
if not template_path.exists():
|
||||
raise FileNotFoundError("Input section image not found")
|
||||
|
||||
input_location = pyautogui.locateOnScreen(str(input_image_path))
|
||||
# Perform template matching to find the object
|
||||
match = template_matching(screenshot, template_path)
|
||||
|
||||
if input_location:
|
||||
pyautogui.click(input_location)
|
||||
if match:
|
||||
startX, startY, endX, endY = match
|
||||
print(f"Object found at ({startX}, {startY}) with width {endX - startX} and height {endY - startY}")
|
||||
# Move the cursor to the center of the detected object
|
||||
pyautogui.moveTo(startX + (endX - startX) // 2, startY + (endY - startY) // 2)
|
||||
# Click the detected object
|
||||
pyautogui.click()
|
||||
# Type the specified text
|
||||
pyautogui.typewrite(prompt)
|
||||
pyautogui.press('enter')
|
||||
return "Video creation in progress!"
|
||||
return "Video generation process started. This may take some time"
|
||||
else:
|
||||
return "Please log in to Luma AI Dream Machine to create a video."
|
||||
except Exception as e:
|
||||
trace_exception(e)
|
||||
return "Please log in to Luma AI Dream Machine to create a video."
|
||||
|
||||
def luma_ai_dream_machine_video_creator_function() -> Dict:
|
||||
|
Loading…
x
Reference in New Issue
Block a user