lunarflu HF Staff commited on
Commit
5546580
·
1 Parent(s): 8806815

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +55 -0
app.py ADDED
@@ -0,0 +1,55 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import discord
2
+ import gradio_client
3
+ import gradio as gr
4
+ import os
5
+ import threading
6
+
7
+ # Get Gradio client
8
+ jojogan = gradio_client.Client("akhaliq/JoJoGAN")
9
+
10
+ # Set up discord bot
11
+ class MyClient(discord.Client):
12
+ async def on_ready(self):
13
+ print('Logged on as', self.user)
14
+
15
+ async def on_message(self, message):
16
+ # don't respond to ourselves
17
+ if message.author == self.user:
18
+ return
19
+
20
+ if message.content.find("!help") != -1:
21
+ await message.reply("Use !jojo !disney !spidey or !sketch. Have fun!", mention_author=True)
22
+
23
+ style = None
24
+ if message.content.startswith('!jojo'):
25
+ style = 'JoJo'
26
+ if message.content.startswith('!disney'):
27
+ style = 'Disney'
28
+ if message.content.startswith('!spidey'):
29
+ style = 'Spider-Verse'
30
+ if message.content.startswith('!sketch'):
31
+ style = 'sketch'
32
+
33
+ if style:
34
+ if message.attachments:
35
+ attachment = message.attachments[0]
36
+ im = jojogan.predict(attachment.url, style)
37
+ await message.reply(f'Here is the {style} version of it', file=discord.File(im))
38
+ else:
39
+ await message.channel.send("No attachments to be found...Can't animify dat! Try sending me an image 😉")
40
+
41
+ DISCORD_TOKEN = os.environ.get("DISCORD_PAINTER_TOKEN", None)
42
+ intents = discord.Intents.default()
43
+ intents.message_content = True
44
+ client = MyClient(intents=intents)
45
+
46
+ def run_bot():
47
+ client.run(DISCORD_TOKEN)
48
+
49
+ threading.Thread(target=run_bot).start()
50
+
51
+ def greet(name):
52
+ return "Hello " + name + "!"
53
+
54
+ demo = gr.Interface(fn=greet, inputs="text", outputs="text")
55
+ demo.launch()