test dfif
Browse files
app.py
CHANGED
@@ -5,6 +5,17 @@ import gradio as gr
|
|
5 |
import os
|
6 |
import threading
|
7 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
8 |
#todos
|
9 |
#alert
|
10 |
|
@@ -12,10 +23,18 @@ import threading
|
|
12 |
jojogan = gradio_client.Client("akhaliq/JoJoGAN")
|
13 |
|
14 |
#new
|
|
|
15 |
deepfloydif = gradio_client.Client("DeepFloyd/IF")
|
16 |
client = Client("DeepFloyd/IF")
|
17 |
client.view_api()
|
18 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
19 |
# Set up discord bot
|
20 |
class MyClient(discord.Client):
|
21 |
async def on_ready(self):
|
@@ -60,6 +79,12 @@ class MyClient(discord.Client):
|
|
60 |
if style:
|
61 |
if message.attachments:
|
62 |
attachment = message.attachments[0]
|
|
|
|
|
|
|
|
|
|
|
|
|
63 |
im = jojogan.predict(attachment.url, style)
|
64 |
await message.reply(f'Here is the {style} version of it', file=discord.File(im))
|
65 |
else:
|
@@ -67,6 +92,7 @@ class MyClient(discord.Client):
|
|
67 |
|
68 |
#new
|
69 |
#deepfloydif
|
|
|
70 |
if message.content.startswith('!deepfloydif'):
|
71 |
text_input = message.content[12:].strip()
|
72 |
if text_input:
|
@@ -76,9 +102,40 @@ class MyClient(discord.Client):
|
|
76 |
im_bytes.seek(0)
|
77 |
await message.reply(f'Here is the image generated for the input "{text_input}"', file=discord.File(im_bytes, 'output.png'))
|
78 |
else:
|
79 |
-
await message.channel.send("No text input provided. Please provide some text after the !deepfloydif command.")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
80 |
|
81 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
82 |
|
83 |
DISCORD_TOKEN = os.environ.get("GRADIOTEST_TOKEN", None)
|
84 |
intents = discord.Intents.default()
|
|
|
5 |
import os
|
6 |
import threading
|
7 |
|
8 |
+
#for deepfloydif
|
9 |
+
import requests
|
10 |
+
import json
|
11 |
+
import random
|
12 |
+
from PIL import Image
|
13 |
+
import matplotlib.pyplot as plt
|
14 |
+
import matplotlib.image as mpimg
|
15 |
+
|
16 |
+
|
17 |
+
|
18 |
+
|
19 |
#todos
|
20 |
#alert
|
21 |
|
|
|
23 |
jojogan = gradio_client.Client("akhaliq/JoJoGAN")
|
24 |
|
25 |
#new
|
26 |
+
'''
|
27 |
deepfloydif = gradio_client.Client("DeepFloyd/IF")
|
28 |
client = Client("DeepFloyd/IF")
|
29 |
client.view_api()
|
30 |
|
31 |
+
'''
|
32 |
+
|
33 |
+
|
34 |
+
df = Client("DeepFloyd/IF")
|
35 |
+
|
36 |
+
|
37 |
+
|
38 |
# Set up discord bot
|
39 |
class MyClient(discord.Client):
|
40 |
async def on_ready(self):
|
|
|
79 |
if style:
|
80 |
if message.attachments:
|
81 |
attachment = message.attachments[0]
|
82 |
+
|
83 |
+
# jojogan = gradio_client.Client("akhaliq/JoJoGAN")
|
84 |
+
# predict(img, model, api_name="/predict") -> output
|
85 |
+
# im = jojogan.predict(img, model) -> output
|
86 |
+
# im = jojogan.predict(attachment.url, style) -> output
|
87 |
+
|
88 |
im = jojogan.predict(attachment.url, style)
|
89 |
await message.reply(f'Here is the {style} version of it', file=discord.File(im))
|
90 |
else:
|
|
|
92 |
|
93 |
#new
|
94 |
#deepfloydif
|
95 |
+
'''
|
96 |
if message.content.startswith('!deepfloydif'):
|
97 |
text_input = message.content[12:].strip()
|
98 |
if text_input:
|
|
|
102 |
im_bytes.seek(0)
|
103 |
await message.reply(f'Here is the image generated for the input "{text_input}"', file=discord.File(im_bytes, 'output.png'))
|
104 |
else:
|
105 |
+
await message.channel.send("No text input provided. Please provide some text after the !deepfloydif command.")
|
106 |
+
|
107 |
+
'''
|
108 |
+
#deepfloydif
|
109 |
+
# start with preset values for now
|
110 |
+
if message.content.startswith('!deepfloydif'):
|
111 |
+
# stage 1
|
112 |
+
prompt = "llama"
|
113 |
+
negative_prompt = "blue"
|
114 |
+
seed = random.randint(0, 2**32 - 1) # maybe random seed each time? seed = 7
|
115 |
+
number_of_images = 4
|
116 |
+
guidance_scale = 7
|
117 |
+
custom_timesteps_1 = 'smart100'
|
118 |
+
number_of_inference_steps = 100
|
119 |
+
|
120 |
+
stage_1_results, stage_1_param_path, stage_1_result_path = df.predict(prompt, negative_prompt, seed, number_of_images, guidance_scale, custom_timesteps_1, number_of_inference_steps, api_name="/generate64")
|
121 |
+
|
122 |
+
# stage 2
|
123 |
+
selected_index_for_stage_2 = -1
|
124 |
+
custom_timesteps_2 = 'smart100' # could reset to smart50 if index was the issue
|
125 |
+
seed = random.randint(0, 2**32 - 1) # again, could randomize this seed = 362572064
|
126 |
+
|
127 |
+
# predict(stage_1_result_path, selected_index_for_stage_2, seed, guidance_scale, custom_timesteps_2, number_of_inference_steps, api_name="/upscale256") -> result
|
128 |
+
|
129 |
+
img = df.predict(stage_1_result_path, selected_index_for_stage_2, seed, guidance_scale, custom_timesteps_2, number_of_inference_steps, api_name="/upscale256")
|
130 |
|
131 |
+
# Save the generated image to a file
|
132 |
+
img_path = "/tmp/generated_image.png"
|
133 |
+
img.save(img_path)
|
134 |
+
|
135 |
+
# Send the image file as a Discord attachment
|
136 |
+
with open(img_path, 'rb') as f:
|
137 |
+
await message.reply(f'Here is the generated image', file=discord.File(f, 'generated_image.png'))
|
138 |
+
|
139 |
|
140 |
DISCORD_TOKEN = os.environ.get("GRADIOTEST_TOKEN", None)
|
141 |
intents = discord.Intents.default()
|