Last active
October 9, 2022 13:36
-
-
Save camenduru/125b2992422ca294d15a392ad0e35d7d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import math | |
import os | |
import sys | |
import traceback | |
import requests | |
from modules import images | |
import modules.scripts as scripts | |
import gradio as gr | |
from modules.processing import Processed, process_images | |
class Script(scripts.Script): | |
def title(self): | |
return "Post to Discord" | |
def ui(self, is_img2img): | |
n = gr.Textbox(label="n") | |
token = gr.Textbox(label="discord bot token") | |
channel_id = gr.Textbox(label="channel id") | |
return [n, token, channel_id] | |
def run(self, p, n, token, channel_id): | |
for x in range(int(n)): | |
p.seed = -1 | |
proc = process_images(p) | |
image = proc.images | |
files = {f"{proc.fullfn[0]}" : open(f"{proc.fullfn[0]}", "rb").read()} | |
payload = {"content":f"{proc.info}"} | |
header = {"authorization": f"Bot {token}"} | |
requests.post(f"https://discord.com/api/v9/channels/{channel_id}/messages", data=payload, headers=header, files=files).text | |
return Processed(p, image, p.seed, proc.info) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment