Spaces:
Sleeping
Sleeping
File size: 2,238 Bytes
05f9833 714cc17 05f9833 8dd7af4 9eb5891 0b16722 9eb5891 ca76df5 0b16722 8dd7af4 294b9f5 8dd7af4 1a4eae2 |
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 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
import gradio as gr
import torch
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('SamDaaLamb/ValorantTracker', 'srdetect', 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(share=True) |