Spaces:
Runtime error
Runtime error
| import os | |
| from yattag import Doc | |
| ## --------------------------------- ### | |
| ### reading: info.txt ### | |
| ### -------------------------------- ### | |
| # placeholders in case info.txt does not exist | |
| def get_article(): | |
| filename = "info.txt" | |
| placeholder = "please create an info.txt to customize this text" | |
| 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='my-div'): | |
| line('h2', 'Project Background') | |
| line('p', bkgd) | |
| with tag('div', klass='my-div'): | |
| line('h2', 'Data Collection') | |
| line('p', data_collection) | |
| with tag('div', klass='my-div'): | |
| line('h2', 'Ethical Considerations') | |
| with tag('ul'): | |
| line('li', priv_cons) | |
| line('li', bias_cons) | |
| line('li', ident_cons) | |
| with tag('div', klass='my-div'): | |
| line('h2', 'Our Team') | |
| line('p', membs) | |
| doc.stag('img', src=img_src) | |
| css = ''' | |
| .my-div { | |
| 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; | |
| } | |
| ''' | |
| return { | |
| 'article': doc.getvalue(), | |
| 'css': css, | |
| 'title': title, | |
| 'description': description, | |
| } |