pet-project / reader.py
Isabel Gwara
Update reader.py
cfe0b8d
raw
history blame
4.43 kB
import os
from yattag import Doc
## --------------------------------- ###
### reading: info.txt ###
### -------------------------------- ###
# placeholders in case info.txt does not exist
def get_article(acc, most_imp_feat):
filename = "info.txt"
placeholder = "please create an info.txt to customize this text"
note = "**Note that model accuracy and most important feature reflect assumptions made by the model about the world, and may be inaccurate. These can be helpful for understanding how the model works, but should not be considered absolute facts."
title = bkgd = data_collection = priv_cons = bias_cons = ident_cons = img_src = membs = description = placeholder
# check if info.txt is present
if os.path.isfile(filename):
# open info.txt in read mode
info = open(filename, "r")
# read each line to a string
description = "An AI project created by " + info.readline()
title = info.readline()
bkgd = info.readline()
data_collection = info.readline()
priv_cons = info.readline()
bias_cons = info.readline()
ident_cons = info.readline()
img_src = info.readline()
membs = info.readline()
# close file
info.close()
# use yattag library to generate html
doc, tag, text, line = Doc().ttl()
# create html based on info.txt
with tag('div'):
with tag('div', klass='box model-container'):
with tag('div', klass='spacer'):
with tag('div', klass='box model-div'):
line('h2', "Model Accuracy", klass='acc')
line('p', acc)
with tag('div', klass='box model-div'):
line('h2', "Most Important Feature", klass='feat')
line('p', most_imp_feat)
with tag('div', klass='spacer'):
line('p', note)
with tag('div', klass='box'):
line('h2', 'Problem Statement and Research Summary', klass='prj')
line('p', bkgd)
with tag('div', klass='box'):
line('h2', 'Data Collection Plan', klass='data')
line('p', data_collection)
with tag('div', klass='box'):
line('h2', 'Ethical Considerations', klass='ethics')
with tag('ul'):
line('li', priv_cons)
line('li', bias_cons)
line('li', ident_cons)
with tag('div', klass='box'):
line('h2', 'Our Team', klass='team')
line('p', membs)
doc.stag('img', src=img_src)
css = '''
.box {
border: 2px solid black;
text-align: center;
margin: 10px;
padding: 5%;
}
ul {
display: inline-block;
text-align: left;
}
img {
display: block;
margin: auto;
}
.description {
text-align: center;
}
.panel_button {
display: block !important;
width: 100% !important;
background-color: #00EACD !important;
color: #000;
transition: all .2s ease-out 0s !important;
box-shadow: 0 10px #00AEAB !important;
border-radius: 10px;
}
.panel_button:hover {
box-shadow: 0 5px #00AEAB;
transform: translateY(5px);
}
.submit {
color: black !important;
}
.selected {
background-color: #656bd6 !important;
}
.panel_header:hover {
color: #656bd6 !important;
}
.input_radio:hover {
color: #656bd6 !important;
}
.radio_item {
border-radius: 10px;
padding-left: 10px !important;
padding-right: 10px !important;
}
.title {
background-image: url(https://media.giphy.com/media/26BROrSHlmyzzHf3i/giphy.gif);
background-size: cover;
color: transparent;
-moz-background-clip: text;
-webkit-background-clip: text;
text-transform: uppercase;
font-size: 120px;
line-height: .75;
margin: 10px 0;
}
input {
background-color: #efeffa !important;
}
.acc, .feat {
background-color: #FF3399 !important
}
.prj {
background-color: #FFCE3B !important;
}
.data {
background-color: #ED6800 !important;
}
.ethics {
background-color: #3EE6F9 !important;
}
.team {
background-color: #9581EF !important;
}
.model-container {
display: flex;
flex-direction: column;
justify-content: center;
}
.spacer {
display: flex;
justify-content: center;
}
.model-div {
width: 45%;
}
@media screen and (max-width: 700px) {
.model-container {
flex-wrap: wrap;
}
}
'''
return {
'article': doc.getvalue(),
'css': css,
'title': title,
'description': description,
}