Spaces:
Runtime error
Runtime error
Upload reader.py
Browse files
reader.py
ADDED
@@ -0,0 +1,76 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
from yattag import Doc
|
3 |
+
## --------------------------------- ###
|
4 |
+
### reading: info.txt ###
|
5 |
+
### -------------------------------- ###
|
6 |
+
# placeholders in case info.txt does not exist
|
7 |
+
def get_article():
|
8 |
+
filename = "info.txt"
|
9 |
+
placeholder = "please create an info.txt to customize this text"
|
10 |
+
|
11 |
+
title = bkgd = data_collection = priv_cons = bias_cons = ident_cons = img_src = membs = description = placeholder
|
12 |
+
# check if info.txt is present
|
13 |
+
if os.path.isfile(filename):
|
14 |
+
# open info.txt in read mode
|
15 |
+
info = open(filename, "r")
|
16 |
+
|
17 |
+
# read each line to a string
|
18 |
+
description = "An AI project created by " + info.readline()
|
19 |
+
title = info.readline()
|
20 |
+
bkgd = info.readline()
|
21 |
+
data_collection = info.readline()
|
22 |
+
priv_cons = info.readline()
|
23 |
+
bias_cons = info.readline()
|
24 |
+
ident_cons = info.readline()
|
25 |
+
img_src = info.readline()
|
26 |
+
membs = info.readline()
|
27 |
+
|
28 |
+
# close file
|
29 |
+
info.close()
|
30 |
+
|
31 |
+
# use yattag library to generate html
|
32 |
+
doc, tag, text, line = Doc().ttl()
|
33 |
+
# create html based on info.txt
|
34 |
+
with tag('div'):
|
35 |
+
with tag('div', klass='my-div'):
|
36 |
+
line('h2', 'Project Background')
|
37 |
+
line('p', bkgd)
|
38 |
+
with tag('div', klass='my-div'):
|
39 |
+
line('h2', 'Data Collection')
|
40 |
+
line('p', data_collection)
|
41 |
+
with tag('div', klass='my-div'):
|
42 |
+
line('h2', 'Ethical Considerations')
|
43 |
+
with tag('ul'):
|
44 |
+
line('li', priv_cons)
|
45 |
+
line('li', bias_cons)
|
46 |
+
line('li', ident_cons)
|
47 |
+
with tag('div', klass='my-div'):
|
48 |
+
line('h2', 'Our Team')
|
49 |
+
line('p', membs)
|
50 |
+
doc.stag('img', src=img_src)
|
51 |
+
|
52 |
+
css = '''
|
53 |
+
.my-div {
|
54 |
+
border: 2px solid black;
|
55 |
+
text-align: center;
|
56 |
+
margin: 10px;
|
57 |
+
padding: 5%;
|
58 |
+
}
|
59 |
+
ul {
|
60 |
+
display: inline-block;
|
61 |
+
text-align: left;
|
62 |
+
}
|
63 |
+
img {
|
64 |
+
display: block;
|
65 |
+
margin: auto;
|
66 |
+
}
|
67 |
+
.description {
|
68 |
+
text-align: center;
|
69 |
+
}
|
70 |
+
'''
|
71 |
+
return {
|
72 |
+
'article': doc.getvalue(),
|
73 |
+
'css': css,
|
74 |
+
'title': title,
|
75 |
+
'description': description,
|
76 |
+
}
|