text
stringlengths
1
93.6k
assert isinstance(query, str)
if os.path.isfile(query):
with open(query) as f:
data = eval(f.read())
else:
req = requests.get(query)
try:
data = requests.json()
except Exception:
data = req.content.decode()
assert data is not None, "could not connect"
try:
data = eval(data)
except Exception:
data = data.split("\n")
req.close()
return data
def get_image_from_url(url):
response = requests.get(url)
img = np.array(Image.open(BytesIO(response.content)))
return img
# to load legace frcnn checkpoint from detectron
def load_frcnn_pkl_from_url(url):
fn = url.split("/")[-1]
if fn not in os.listdir(os.getcwd()):
wget.download(url)
with open(fn, "rb") as stream:
weights = pkl.load(stream)
model = weights.pop("model")
new = {}
for k, v in model.items():
new[k] = torch.from_numpy(v)
if "running_var" in k:
zero = torch.Tensor([0])
k2 = k.replace("running_var", "num_batches_tracked")
new[k2] = zero
return new
def get_demo_path():
print(f"{os.path.abspath(os.path.join(PATH, os.pardir))}/demo.ipynb")
def img_tensorize(im, input_format="RGB"):
assert isinstance(im, str)
if os.path.isfile(im):
img = cv2.imread(im)
else:
img = get_image_from_url(im)
assert img is not None, f"could not connect to: {im}"
img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB) # 8333 comment this out or indent
# print("trec")
if input_format == "RGB":
img = img[:, :, ::-1]
return img
def chunk(images, batch=1):
return (images[i : i + batch] for i in range(0, len(images), batch))
# <FILESEP>
import re, logging
from os import environ
from Script import script
def is_enabled(type, value):
data = environ.get(type, str(value))
if data.lower() in ["true", "yes", "1", "enable", "y"]:
return True
elif data.lower() in ["false", "no", "0", "disable", "n"]:
return False
else:
print(f'Error - {type} is invalid, exiting now')
exit()
def is_valid_ip(ip):
ip_pattern = r'\b(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\b'
return re.match(ip_pattern, ip) is not None
# Bot information
API_ID = environ.get('API_ID', '') #api id of your telegram id
if len(API_ID) == 0:
print('Error - API_ID is missing, exiting now')
exit()
else:
API_ID = int(API_ID)
API_HASH = environ.get('API_HASH', '') #api hash of your telegram id
if len(API_HASH) == 0:
print('Error - API_HASH is missing, exiting now')
exit()
BOT_TOKEN = environ.get('BOT_TOKEN', '') #bot token from botfather
if len(BOT_TOKEN) == 0:
print('Error - BOT_TOKEN is missing, exiting now')
exit()
PORT = int(environ.get('PORT', '80')) #don't change anything