Various plugin updates. New plugin for stable diffusion
This commit is contained in:
parent
5962eb53ad
commit
542bb5d5cd
1
.gitignore
vendored
1
.gitignore
vendored
@ -9,3 +9,4 @@ simplematrixbotlib*/
|
||||
chromedriver
|
||||
store
|
||||
funguybot.service
|
||||
stats.db
|
@ -58,7 +58,9 @@ async def handle_command(room, message, bot, prefix, config):
|
||||
payload = response.json()
|
||||
new_text = payload['choices'][0]['text']
|
||||
new_text = markdown_to_html(new_text)
|
||||
if new_text.count('<p>') > 2: # Check if new_text has more than one paragraph
|
||||
print(new_text)
|
||||
|
||||
if new_text.count('<p>') > 1 or new_text.count('<li>') > 1: # Check if new_text has more than one paragraph
|
||||
#new_text = new_text.replace("\n", '<br>')
|
||||
#new_text = re.sub(r"\*\*(.*?)\*\*", r"<strong>\1</strong>", new_text)
|
||||
new_text = "<details><summary><strong>🎵Funguy Music GPT🎵<br>⤵︎Click Here To See Funguy's Response⤵︎</strong></summary>" + new_text + "</details>"
|
||||
|
@ -1,3 +1,6 @@
|
||||
"""
|
||||
Custom configuration class for the Funguy bot.
|
||||
"""
|
||||
# plugins/config.py
|
||||
|
||||
import os
|
||||
|
@ -1,3 +1,6 @@
|
||||
"""
|
||||
This plugin provides a command for the admin to load a plugin
|
||||
"""
|
||||
# plugins/load_plugin.py
|
||||
|
||||
import os
|
||||
|
@ -26,9 +26,9 @@ async def handle_command(room, message, bot, prefix, config):
|
||||
plugin_descriptions = get_plugin_descriptions()
|
||||
|
||||
# Prepend custom string before the output
|
||||
plugin_descriptions.insert(0, "<details><summary><strong>🔌Plugins List🔌<br>⤵︎Click Here to Expand⤵︎</strong></summary><br>")
|
||||
plugin_descriptions.insert(0, "<details><summary><strong>🔌Plugins List🔌<br>⤵︎Click Here to Expand⤵︎</strong></summary>")
|
||||
|
||||
plugins_message = "<br><br>".join(plugin_descriptions)
|
||||
plugins_message = "<br>".join(plugin_descriptions)
|
||||
plugins_message += "</details>"
|
||||
await bot.api.send_markdown_message(room.room_id, plugins_message)
|
||||
logging.info("Sent plugin list to the room")
|
||||
|
42
plugins/stable-diffusion.py
Normal file
42
plugins/stable-diffusion.py
Normal file
@ -0,0 +1,42 @@
|
||||
"""
|
||||
This plugin provides a command to generate images using self hosted Stable Diffusion and send to the room
|
||||
"""
|
||||
# plugins/stable-diffusion.py
|
||||
import requests
|
||||
import base64
|
||||
from asyncio import Queue
|
||||
import simplematrixbotlib as botlib
|
||||
|
||||
# Queue to store pending commands
|
||||
command_queue = Queue()
|
||||
|
||||
async def process_command(room, message, bot, prefix, config):
|
||||
match = botlib.MessageMatch(room, message, bot, prefix)
|
||||
if match.prefix() and match.command("sd"):
|
||||
if command_queue.empty():
|
||||
await handle_command(room, message, bot, prefix, config)
|
||||
else:
|
||||
await command_queue.put((room, message, bot, prefix, config))
|
||||
|
||||
async def handle_command(room, message, bot, prefix, config):
|
||||
match = botlib.MessageMatch(room, message, bot, prefix)
|
||||
if match.prefix() and match.command("sd"):
|
||||
prompt = message.body[len(prefix) + len("sd"):].strip() # Extract prompt from message body
|
||||
payload = {
|
||||
"prompt": prompt,
|
||||
"steps": 32
|
||||
}
|
||||
url = "http://127.0.0.1:7860/sdapi/v1/txt2img"
|
||||
try:
|
||||
response = requests.post(url=url, json=payload)
|
||||
r = response.json()
|
||||
with open("/tmp/output.png", 'wb') as f:
|
||||
f.write(base64.b64decode(r['images'][0]))
|
||||
await bot.api.send_image_message(room_id=room.room_id, image_filepath="/tmp/output.png") # Corrected argument name
|
||||
except Exception as e:
|
||||
await bot.api.send_text_message(room.room_id, f"Error processing the command: {str(e)}")
|
||||
finally:
|
||||
if not command_queue.empty():
|
||||
next_command = await command_queue.get()
|
||||
await handle_command(*next_command)
|
||||
|
@ -1,3 +1,6 @@
|
||||
"""
|
||||
This plugin provides a command to search for YouTube videos in the room
|
||||
"""
|
||||
# plugins/youtube_search.py
|
||||
|
||||
import logging
|
||||
|
@ -4,3 +4,5 @@ pytube
|
||||
duckduckgo_search
|
||||
nio
|
||||
markdown2
|
||||
watchdog
|
||||
emoji
|
||||
|
Loading…
Reference in New Issue
Block a user