File size: 1,330 Bytes
2fe881c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
from CNN import CNN_model, test_image
from image_manipulation import resize
import discord
from discord.ext import commands
import uuid
import requests
import shutil
import os

intents = discord.Intents.default()
intents.message_content = True
client = commands.Bot(command_prefix= '.', intents = intents)

@client.event
async def on_ready():
    print("Bot is up and running!")
@client.command()
async def save(ctx):
    try:
        url = ctx.message.attachments[0].url
    except IndexError:
        print("Error: No attachments")
        await ctx.send("No attachments detected. Please try again.")
    else:
        if url[0:26] == "https://cdn.discordapp.com":
            r = requests.get(url, stream = True)
            imageName = str(uuid.uuid4()) + '.png'
            folder_path = "C:\Ryan\PersonalProject\\FriendRecog\\bot\images"
            full_path = os.path.join(folder_path, imageName)
            with open(full_path, 'wb') as file:
                print('Saving Image: ' + imageName)
                shutil.copyfileobj(r.raw, file)

            resize()
            model = CNN_model()
            predicted_class, confidence = test_image(model)
            await ctx.send("Prediction: "  + str(predicted_class) + " with a " + 100 * str(confidence) + "% confidence level.")