Example #1
0
InstanceID = subprocess.getoutput("curl -s http://169.254.169.254/latest/meta-data/instance-id").replace(" ","")

PublicIP = subprocess.getoutput("curl -s http://169.254.169.254/latest/meta-data/public-ipv4").replace(" ","")
if PublicIP == "":
    PublicIP = "N/A"

PrivateIP = subprocess.getoutput("curl -s http://169.254.169.254/latest/meta-data/local-ipv4").replace(" ","")

AZ = subprocess.getoutput("curl -s http://169.254.169.254/latest/meta-data/placement/availability-zone/").replace(" ","")

print ("<br />")
print ("<br />")
print ("<br />")
print ("<br />")

homer=center(img(src="https://github.com/ezzobad/ted/raw/master/woohoo.jpg",align="middle",style="width:250;height:200;"))
print (homer)
print ("<br />")
print ('<html>')
print ('<head> <style> table, th, td { border: 1px solid brown; } </style> </head>')
print ('<body> <div align="center"> <table bgcolor="#e6ffcc" cellpadding="5" cellspacing="0">')

print ('<tr> <th bgcolor= #ffd1b3><font size="5" color="black">Instance ID</font></th>')
print ('<th bgcolor= #ffd1b3><font size="5" color="black">Public IP</font></th>')
print ('<th bgcolor= #ffd1b3><font size="5" color="black">Private IP</font></th>')
print ('<th bgcolor= #ffd1b3><font size="5" color="black">Availability Zone</font></th>')
print ('<tr color="#804000" align="center">')
print ('<td><font size="5">'+InstanceID+'</font></td>')
print ('<td><font size="5">'+PublicIP+'</font></td>')
print ('<td><font size="5">'+PrivateIP+'</font></td>')
print ('<td> <font size="5">'+AZ+'</font></td>')
Example #2
0
PrivateIP = subprocess.getoutput(
    "curl -s http://169.254.169.254/latest/meta-data/local-ipv4").replace(
        " ", "")

AZ = subprocess.getoutput(
    "curl -s http://169.254.169.254/latest/meta-data/placement/availability-zone/"
).replace(" ", "")

print("<br />")
print("<br />")
print("<br />")
print("<br />")

homer = center(
    img(src="https://github.com/ezzobad/ted/raw/master/woohoo.jpg",
        align="middle",
        style="width:250;height:200;"))
print(homer)
print("<br />")
print('<html>')
print(
    '<head> <style> table, th, td { border: 1px solid brown; } </style> </head>'
)
print(
    '<body> <div align="center"> <table bgcolor="#e6ffcc" cellpadding="5" cellspacing="0">'
)

print(
    '<tr> <th bgcolor= #ffd1b3><font size="5" color="black">Instance ID</font></th>'
)
print(
Example #3
0
else:
    PublicIP = "N/A"

PrivateIP = subprocess.getoutput(
    "curl -s http://169.254.169.254/latest/meta-data/local-ipv4").replace(
        " ", "")

AZ = subprocess.getoutput(
    "curl -s http://169.254.169.254/latest/meta-data/placement/availability-zone/"
).replace(" ", "")

print("<br />")

homer = center(
    img(src=
        "https://raw.githubusercontent.com/awsengineer/CFN/master/Nested/v1.3Show_RDS_data_in_Apache/woohoo.jpg",
        align="middle",
        style="width:250;height:200;"))
print(homer)
print('<html>')
print('<div align="center"><font size="6">' +
      "Details of this HTTP Server (behind ELB):" + '</font>')
print(
    '<head> <style> table, th, td { border: 1px solid brown; } </style> </head>'
)
print(
    '<body> <div align="center"> <table bgcolor="#e6ffcc" cellpadding="5" cellspacing="0">'
)

print(
    '<tr> <th bgcolor= #ffd1b3><font size="5" color="black">Instance ID</font></th>'
)
def generateMTurkFile(startGID,endGID,outFile,prodFileWrite = False):
    imageID = genImageID(startGID,endGID)
    links = ["http://pachy.cs.uic.edu:5000/api/image/src/"+str(i)+"/?resize_pix_w=500" for i in imageID[0:maxImgs]]
    imgTags = []
    radioShare = HT.input
    for url in links:
        imgTags.append(HT.img(src = url,alt = "Unavailable"))

    # logic to create the radio buttons and the hidden form fields
    shareRadio = []
    notShareRadio = []
    hiddenField = []
    for i in range(maxImgs):
        hiddenField.append(HT.input(type='hidden',name=imageID[i],value=imageID[i]))
        shareRadio.append(HT.input(type='radio',value='share',name=imageID[i]) + "Share")
        notShareRadio.append(HT.input(type='radio',value='noShare',name=imageID[i]) + "Do Not Share")

    tdTags = []
    for i in range(maxImgs):
        tdTags.append(HT.td(HT.center(HT.HTML(hiddenField[i]),HT.HTML(shareRadio[i]),HT.HTML(notShareRadio[i])),HT.HTML(imgTags[i])))

    trTags = []
    for i in range(0,maxImgs,2):
        trTags.append(HT.tr(HT.HTML(tdTags[i]),HT.HTML(tdTags[i+1])))

    bodyTxt = HT.table(HT.HTML('\n'.join(trTags)),border="1")

    headFile = open("files/header.txt","r")
    tailFile = open("files/tail.txt","r")
    outFileDev = outFile + ".question"
    outputFile = open(outFileDev,"w")

    for line in headFile:
        outputFile.write(line)
        
    outputFile.write(bodyTxt)

    for line in tailFile:
        outputFile.write(line)

    headFile.close()
    tailFile.close()
    outputFile.close()

    if prodFileWrite:
        headFile = open("files/header_prod.txt","r")
        tailFile = open("files/tail_prod.txt","r")
        outFileProd = outFile + "_prod.question"
        outputFile = open(outFileProd,"w")
        for line in headFile:
            outputFile.write(line)
        
        outputFile.write(bodyTxt)

        for line in tailFile:   
            outputFile.write(line)

        headFile.close()
        tailFile.close()
        outputFile.close()

    return imageID
def vis():
    def to_str(x):
        return '{:.2f}'.format(x.item())

    assert FLAGS.dataset == 'mimic-cxr'

    phase = Phase.test
    dataset = test_dataset
    data_loader = test_loader

    if FLAGS.ckpt_path:
        logger.info(f'Loading model from {FLAGS.ckpt_path}')
        load_state_dict(model, torch.load(FLAGS.ckpt_path))

    log = Log()
    converter = SentIndex2Report(index_to_word=Dataset.index_to_word)
    chexpert = CheXpert()

    working_dir = os.path.join(FLAGS.working_dir, 'vis', datetime.datetime.now().strftime('%Y-%m-%d-%H%M%S-%f'))
    image_dir = os.path.join(working_dir, 'imgs')
    os.makedirs(image_dir)

    reports = []
    prog = tqdm.tqdm(enumerate(data_loader), total=len(data_loader))
    for (num_batch, batch) in prog:
        for (key, value) in batch.items():
            batch[key] = value.to(FLAGS.device)

        losses = {}
        metrics = {}

        with torch.no_grad():
            batch = model(batch, phase=Phase.test, beam_size=FLAGS.beam_size)

        _log = {**losses, **metrics}
        log.update(_log)

        prog.set_description(', '.join(
            [f'[{phase:5s}]'] +
            [f'{key:s}: {log[key]:8.2e}' for key in sorted(losses.keys())]
        ))

        item_index = to_numpy(batch['item_index'])
        _text_length = batch['_text_length']  # (num_reports,)
        (
            _stop,                 # (num_reports, max_num_sentences, 1)
            _temp,                 # (num_reports, max_num_sentences, 1)
            _attention,            # (num_repoers, max_num_sentences, beam_size, max_num_words, 65)
            _score,                # (num_reports, max_num_sentences, beam_size)
            _sum_log_probability,  # (num_reports, max_num_sentences, beam_size)
            _text,                 # (num_reports, max_num_sentences, beam_size, max_num_words)
            _sent_length,          # (num_reports, max_num_sentences, beam_size)
        ) = [
            pad_packed_sequence(batch[key], length=_text_length)
            for key in ['_stop', '_temp', '_attention', '_score', '_sum_log_probability', '_text', '_sent_length']
        ]

        (fig, ax) = plot.subplots(1, figsize=(6, 6), gridspec_kw={'left': 0, 'right': 1, 'bottom': 0, 'top': 1})
        for num_report in range(len(_text_length)):
            num = num_batch * FLAGS.batch_size + num_report

            item = dataset.df.iloc[int(item_index[num_report])]
            image_path = mimic_cxr.image_path(dicom_id=item.dicom_id)

            sentences = []
            for num_sentence in range(_text_length[num_report]):
                beams = []
                for num_beam in range(FLAGS.beam_size):
                    num_words = _sent_length[num_report, num_sentence, num_beam]
                    _sentence = _text[num_report, num_sentence, num_beam]
                    _words = Dataset.index_to_word[to_numpy(_sentence[:num_words])]

                    texts = []
                    for num_word in range(num_words):
                        _attention_path = os.path.join(image_dir, f'{num}-{num_sentence}-{num_beam}-{num_word}.png')
                        print(_attention_path)

                        # texts.append(span(_words[num_word]))
                        _a = _attention[num_report, num_sentence, num_beam, num_word, :FLAGS.image_size * FLAGS.image_size]
                        _a_sum = _a.sum()
                        _a = _a - _a.min()
                        _a = _a / _a.max()
                        _a = _a.reshape(FLAGS.image_size, FLAGS.image_size)
                        _a = F.interpolate(_a[None, None, :], scale_factor=(32, 32), mode='bilinear', align_corners=False)[0, 0]

                        '''
                        ax.contourf(to_numpy(_a), cmap='gray')
                        ax.set_axis_off()

                        fig.savefig(_attention_path, bbox_inches=0)
                        ax.cla()
                        '''
                        _a = 255 * to_numpy(_a)
                        PIL.Image.fromarray(_a.astype(np.uint8)).save(_attention_path)

                        texts.append(span(_words[num_word], **{
                            'data-toggle': 'tooltip',
                            'title': (
                                p('Total attention: ' + to_str(_a_sum)) +
                                img(src=f'http://monday.csail.mit.edu/xiuming{_attention_path}', width='128', height='128')
                            ).replace('"', '\''),
                        }))

                    beams.append({
                        'score': to_str(_score[num_report, num_sentence, num_beam]),
                        'log_prob': to_str(_sum_log_probability[num_report, num_sentence, num_beam]),
                        'text': str('\n'.join(texts)),
                    })

                sentence = {}

                if mode & Mode.use_label_ce:
                    sentence.update({
                        'stop': to_str(_stop[num_report, num_sentence]),
                        'temp': to_str(_temp[num_report, num_sentence]),
                        'labels': [{
                            'label': label_col,
                            'prob': to_str(_l),
                        } for (label_col, _l) in zip(Dataset.label_columns, _label[num_report, num_sentence])],
                    })

                if mode & Mode.gen_text:
                    sentence.update({
                        'beams': beams,
                    })

                sentences.append(sentence)

            reports.append({
                'rad_id': str(dataset.df.rad_id.iloc[item_index[num_report]]),
                'dicom_id': str(dataset.df.dicom_id.iloc[item_index[num_report]]),
                'image': str(img(src=f'http://monday.csail.mit.edu/xiuming{image_path}', width='256')),
                'generated text': sentences,
                'ground truth text': converter(batch['text'][num_report], batch['sent_length'][num_report], batch['text_length'][num_report], is_eos=False)[0],
            })

        if num_batch == 0:
            break

    s = json2html.convert(json=reports, table_attributes='class="table table-striped"', escape=False)
    s = (
        head([
            link(rel='stylesheet', href='https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css'),
            script(src='https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js'),
            script(src='https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js'),
            script('$(function () { $(\'[data-toggle="tooltip"]\').tooltip({placement: "bottom", html: true}); })', type="text/javascript"),
        ]) +
        body(div(div(div(HTML(s), _class='panel-body'), _class='panel panel-default'), _class='container-fluid'))
    )

    with open(os.path.join(working_dir, 'index.html'), 'w') as f:
        f.write(s)
Example #6
0
InstanceID = subprocess.getoutput("curl -s http://169.254.169.254/latest/meta-data/instance-id").replace(" ","")

temp = subprocess.getoutput("curl -s http://169.254.169.254/latest/meta-data/public-ipv4").replace(" ","")
if len(re.findall('404-NotFound',temp)) == 0:
    PublicIP=temp
else:
    PublicIP="N/A"

PrivateIP = subprocess.getoutput("curl -s http://169.254.169.254/latest/meta-data/local-ipv4").replace(" ","")

AZ = subprocess.getoutput("curl -s http://169.254.169.254/latest/meta-data/placement/availability-zone/").replace(" ","")

print ("<br />")

homer=center(img(src="https://raw.githubusercontent.com/awsengineer/CFN/master/Nested/v1.3Show_RDS_data_in_Apache/woohoo.jpg",align="middle",style="width:250;height:200;"))
print (homer)
print ('<html>')
print ('<div align="center"><font size="6">'+"Details of this HTTP Server (behind ELB):"+'</font>')
print ('<head> <style> table, th, td { border: 1px solid brown; } </style> </head>')
print ('<body> <div align="center"> <table bgcolor="#e6ffcc" cellpadding="5" cellspacing="0">')

print ('<tr> <th bgcolor= #ffd1b3><font size="5" color="black">Instance ID</font></th>')
print ('<th bgcolor= #ffd1b3><font size="5" color="black">Public IP</font></th>')
print ('<th bgcolor= #ffd1b3><font size="5" color="black">Private IP</font></th>')
print ('<th bgcolor= #ffd1b3><font size="5" color="black">Availability Zone</font></th>')
print ('<tr color="#804000" align="center">')
print ('<td><font size="5">'+InstanceID+'</font></td>')
print ('<td><font size="5">'+PublicIP+'</font></td>')
print ('<td><font size="5">'+PrivateIP+'</font></td>')
print ('<td> <font size="5">'+AZ+'</font></td>')
Example #7
0
def tagFastqc(img):
    name = os.path.basename(img).split(".")[0]
    altText = " ".join(name.split("_"))
    return htmltag.img(src=img, alt=altText, _class="fastqc")