ValorantTracker / app.py
SamDaLamb's picture
Update app.py
fd70a94 verified
raw
history blame
2.21 kB
import gradio as gr
def greet(name):
return "Hello " + name + "!!"
demo = gr.Interface(fn=greet, inputs="text", outputs="text")
from urllib.request import urlretrieve
# get image examples from github
urlretrieve("https://github.com/SamDaaLamb/ValorantTracker/blob/main/clip2_-1450-_jpg.jpg?raw=true", "clip2_-1450-_jpg.jpg") # make sure to use "copy image address when copying image from Github"
urlretrieve("https://github.com/SamDaaLamb/ValorantTracker/blob/main/clip2_-539-_jpg.jpg?raw=true", "clip2_-539-_jpg.jpg")
examples = [ # need to manually delete cache everytime new examples are added
["clip2_-1450-_jpg.jpg"],
["clip2_-539-_jpg.jpg"]]
def speclab(img):
# initialize the model
model = torch.hub.load('SamDaLamb/ValorantTracker', 'best.pt', force_reload=True) # for some reasons loads the model in src rather than demo
model.eval()
# preprocess image to be used as input
transforms = A.Compose([
A.Normalize(mean=(0.5, 0.5, 0.5), std=(0.5, 0.5, 0.5)),
ToTensorV2()
])
input = transforms(image=img)['image']
input = input.unsqueeze(0)
# model prediction
output = model(input)
# overlay output onto original image
img[output==255] = [0, 255, 0]
return img
# define app features and run
title = "SpecLab Demo"
description = "<p style='text-align: center'>Gradio demo for an ASPP model architecture trained on the SpecLab dataset. To use it, simply add your image, or click one of the examples to load them. Since this demo is run on CPU only, please allow additional time for processing. </p>"
article = "<p style='text-align: center'><a href='https://github.com/Nano1337/SpecLab'>Github Repo</a></p>"
css = "#0 {object-fit: contain;} #1 {object-fit: contain;}"
demo = gr.Interface(fn=speclab,
title=title,
description=description,
article=article,
inputs=gr.Image(elem_id=0, show_label=False),
outputs=gr.Image(elem_id=1, show_label=False),
css=css,
examples=examples,
cache_examples=True,
allow_flagging='never')
demo.launch()