Skip to content

Instantly share code, notes, and snippets.

@MrSedan
Last active August 25, 2024 15:36
Show Gist options
  • Save MrSedan/5f8dca97844d8d57a421893a4eea71fd to your computer and use it in GitHub Desktop.
Save MrSedan/5f8dca97844d8d57a421893a4eea71fd to your computer and use it in GitHub Desktop.
NAI (NovelAI) prompt to WebUI prompt converter

NAI to WebUI prompt converter

Running

You just need to have python installed on your system and run:

python3 nai_to_webui.py '{{some word}} some prompt...'

Or (not on Windows):

chmod +x nai_to_webui.py
./nai_to_webui.py '{{some word}} some prompt...'

The output will look like this:

Here is your WebUi prompt:
(some word:1.1025) some prompt...

So you can just copy the output and paste it in your webui!

#!/usr/bin/python3
__author__ = 'MrSedan'
import sys, re
def convert(s: str):
new_s = s
words = re.findall(r'\{+[a-zA-Z0-9\ \,]+\}+', s)
for word in words:
count = word.count('{')
new_word = f'({word[count:len(word)-count]}:{round(1.05**count,6)})'
new_s = new_s.replace(word, new_word)
words = re.findall(r'\(+[a-zA-Z0-9\ \,]+\)+', new_s)
for word in words:
count = word.count('(')
new_word = f'({word[count:len(word)-count]}:{round(1.1**count,6)})'
new_s = new_s.replace(word, new_word)
return new_s
def main():
if len(sys.argv)!=2:
print('You should use this script with "./nai_to_webui.py \'nai text with {}\'"')
return
s = sys.argv[1]
print('Here is your WebUi prompt:')
print(convert(s))
if __name__=='__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment