File size: 824 Bytes
06088b6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import random
import torch
from PIL import Image
import requests

def classify(model, imgPath, trans=None, classes=[], device=torch.device("cpu")):
    
    try:
        model = model.eval()
        img = imgPath
        img = img.convert("RGB")
        img = trans(img)
        img = img.unsqueeze(0)
        img = img.to(device)

        output = model(img)
        _, pred = torch.max(output, 1)
        procent = torch.sigmoid(output)
        
        return f"It {classes[pred.item()]} i'm {procent[0][pred[0]]*100:.2f}% sure"
    except Exception:
        return "Something went wrong😕, please notify the developer with the following message: " + str(Exception)


def get_random_quote():
    with open("quotes.txt", "r") as file:
        quotes = file.readlines()
    return quotes[random.randint(0, len(quotes)-1)]