fix(.gitignore): add 'settings.yaml' to the list of ignored files

fix(main.py): remove unused import statements and update function name to check_license_agreement
fix(main.py): remove unnecessary comments and sleep statements
feat(main.py): add check_license_agreement function to prompt user to accept license agreement
fix(requirements.txt): add 'watchdog' package to the list of requirements
feat(utils/settings.py): create Settings class to handle loading and updating settings from settings.yaml file
This commit is contained in:
Paillat
2023-07-13 20:01:06 +02:00
parent 116788ba07
commit de2f482de2
5 changed files with 126 additions and 14 deletions

3
.gitignore vendored
View File

@@ -155,7 +155,7 @@ cython_debug/
#Venv directory #Venv directory
youtuber/ youtuber/
#results #custom
videos/ videos/
test/ test/
ideas/ ideas/
@@ -163,3 +163,4 @@ montageTEMP_MPY_wvf_snd.mp3
marp.exe marp.exe
channels/ channels/
bark_cache/ bark_cache/
settings.yaml

View File

@@ -1,5 +1,6 @@
---CLAUSE--- ---CLAUSE---
The Software is provided to you by the Licensor under the Licence, as defined below, subject to the following condition. This clause is based on the “Commons Clause” License Condition v1.0 (https://commonsclause.com). In case of any ambiguity or doubt, this clause will OVERRIDE the Licence and dictate the terms of use. The Software is provided to you by the Licensor under the Licence, as defined below, subject to the following condition. This clause is based on the “Commons Clause” License Condition v1.0 (https://commonsclause.com), but is not identical to it. The Licensor reserves the right to modify this clause at any time, and any such modifications will be effective immediately upon posting of the modified clause. You are advised to regularly check the clause for any updates. Your continued use of the Software after any such modifications constitutes your acceptance of the modified clause. If you do not agree to the modified clause, you must immediately cease using the Software.
. In case of any ambiguity or doubt, this clause will OVERRIDE the Licence and dictate the terms of use.
This Licence and the associated clause do NOT apply to the content contained within the "/music" and "/audio_prompts" directories of this Software. The content within these specific directories may have distinct licensing terms and conditions, which must be referred to and complied with separately. Users are urged to check the respective licenses in these directories to understand their obligations and rights pertaining to the use of the content uniquely contained within these directories. Any ambiguity, conflict, or discrepancy between the Licence and the specific licensing terms of these directories shall be resolved in favor of the specific licenses for those directories. This Licence and the associated clause do NOT apply to the content contained within the "/music" and "/audio_prompts" directories of this Software. The content within these specific directories may have distinct licensing terms and conditions, which must be referred to and complied with separately. Users are urged to check the respective licenses in these directories to understand their obligations and rights pertaining to the use of the content uniquely contained within these directories. Any ambiguity, conflict, or discrepancy between the Licence and the specific licensing terms of these directories shall be resolved in favor of the specific licenses for those directories.
@@ -648,3 +649,4 @@ may consider it more useful to permit linking proprietary applications with
the library. If this is what you want to do, use the GNU Lesser General the library. If this is what you want to do, use the GNU Lesser General
Public License instead of this License. But first, please read Public License instead of this License. But first, please read
<https://www.gnu.org/licenses/why-not-lgpl.html>. <https://www.gnu.org/licenses/why-not-lgpl.html>.

62
main.py
View File

@@ -2,7 +2,11 @@ import os
import asyncio import asyncio
import logging import logging
import yaml import yaml
import hashlib
from pydoc import pager
from sys import platform
from utils.settings import settings
from classes.channel import Channel from classes.channel import Channel
from utils.config import loadingmessage, bcolors from utils.config import loadingmessage, bcolors
from utils.misc import clear_screen, printm, getenv from utils.misc import clear_screen, printm, getenv
@@ -10,13 +14,56 @@ from utils.openaicaller import openai
logging.basicConfig(level=logging.INFO) logging.basicConfig(level=logging.INFO)
async def check_license_agreement():
h = hashlib.sha256()
with open('LICENSE', 'rb') as file:
chunk = file.read(1024)
while chunk:
h.update(chunk)
chunk = file.read(1024)
license_hash = h.hexdigest()
if settings.license_agreement_accepted == False or settings.license_agreement_accepted == None:
printm("You have to accept the license agreement before using this program.")
elif settings.license_agreement_accepted == True:
if settings.license_agreement_hash != license_hash:
printm("The license agreement has been updated since you last accepted it. Please accept it again.")
else:
return True
else:
printm("There was an error with the license agreement. Please accept it again.")
while True:
printm('\n\n')
inp = input("Type p to print the license agreement, a to accept it, q to quit the program or o to open the LICENSE in your default text editor: ")
if inp == "p":
input('You can use the "Enter" key to scroll down and the "q" key to quit the license agreement. Press "Enter" to continue.')
with open('LICENSE', 'r', encoding='utf-8') as f:
pager(f.read())
elif inp == "a":
settings.set_setting('license_agreement_accepted', True)
settings.set_setting('license_agreement_hash', license_hash)
if os.path.exists('LICENSE.txt'):
os.remove('LICENSE.txt')
printm("License agreement accepted.")
return True
elif inp == "q":
printm("Quitting the program...")
raise KeyboardInterrupt
elif inp == "o":
dict_os_commands = {
"linux": "xdg-open",
"win32": "start",
"darwin": "open"
}
#copy the license file to a temporary txt file
with open('LICENSE', 'r', encoding='utf-8') as f:
with open('LICENSE.txt', 'w', encoding='utf-8') as f2:
f2.write(f.read())
os.system(f"{dict_os_commands[platform]} LICENSE.txt")
async def main(): async def main():
#printm("Loading...") clear_screen()
#await asyncio.sleep(1) await check_license_agreement()
#clear_screen()
printm(loadingmessage) printm(loadingmessage)
#await asyncio.sleep(4)
#clear_screen()
await asyncio.sleep(0.5) await asyncio.sleep(0.5)
printm("Welcome in FABLE, the Film and Artistic Bot for Lively Entertainment!") printm("Welcome in FABLE, the Film and Artistic Bot for Lively Entertainment!")
await asyncio.sleep(0.5) await asyncio.sleep(0.5)
@@ -25,11 +72,8 @@ async def main():
printm("It looks like you don't have an OpenAI API key yet. Please paste it here:") printm("It looks like you don't have an OpenAI API key yet. Please paste it here:")
openai_api_key = input("Paste the key here: ") openai_api_key = input("Paste the key here: ")
openai.set_api_key(openai_api_key) openai.set_api_key(openai_api_key)
printm("Please also paste your unsplash access key here:")
unsplash_access_key = input("Paste the key here: ")
env_file = { env_file = {
"openai_api_key": openai_api_key, "openai_api_key": openai_api_key
"unsplash_access_key": unsplash_access_key
} }
with open('env.yaml', 'w') as f: with open('env.yaml', 'w') as f:
yaml.dump(env_file, f) yaml.dump(env_file, f)

View File

@@ -8,3 +8,4 @@ python-dotenv
google-api-python-client google-api-python-client
git+https://github.com/suno-ai/bark.git git+https://github.com/suno-ai/bark.git
noisereduce noisereduce
watchdog

64
utils/settings.py Normal file
View File

@@ -0,0 +1,64 @@
import yaml
import os
import inspect
from os import getcwd
from os.path import abspath, join, exists
class Settings:
def __init__(self):
self.forbidden = ['path', 'settings', 'last_modified', 'load_settings', 'create_settings', 'update_settings', 'set_setting']
self.path = abspath(join(getcwd(), 'settings.yaml'))
self.last_modified = os.path.getmtime(self.path)
self.settings = self.load_settings()
self._updating = False
def load_settings(self):
settings = {}
if exists(self.path):
with open(self.path, 'r', encoding='utf-8') as f:
settings = yaml.safe_load(f) or {}
else:
self.create_settings()
for key, value in settings.items():
if key not in self.forbidden:
self.__dict__[key] = value
return settings
def create_settings(self):
with open(self.path, 'w', encoding='utf-8') as f:
f.write("")
def update_settings(self):
self.settings = self.load_settings()
def __getattribute__ (self, name):
try:
# Try the default behaviour first
return super().__getattribute__(name)
except AttributeError:
# If an AttributeError was raised, return None
return None
def set_setting(self, key, value):
if key in self.forbidden:
raise ValueError(f'Key "{key}" is forbidden.')
self.settings[key] = value
with open(self.path, 'w', encoding='utf-8') as f:
f.write(yaml.dump(self.settings))
self.update_settings()
settings = Settings()
if __name__ == '__main__':
#do some testing
print(settings.settings)
print(settings.path)
print(settings.test)
print(settings.eee)
settings.set_setting('test', 'uu')
print(settings.test)
settings.set_setting('path', 'AAAAAAAAAAA')