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 = sgd1 = sgd2 = td = limitation = con1 = con2 = con3 = con4 = mems = 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 = info.readline() | |
title = info.readline() | |
bkgd = info.readline() | |
sgd1 = info.readline() | |
sgd2 = info.readline() | |
td = info.readline() | |
limitation = info.readline() | |
con1 = info.readline() | |
con2 = info.readline() | |
con3 = info.readline() | |
con4 = info.readline() | |
mems = info.readline() | |
#mem2 = info.readline() | |
#mem3 = info.readline() | |
#mem4 = info.readline() | |
#mem5 = 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', sgd1) | |
with tag('div', klass='my-div'): | |
line('h2', 'Targeted SDGs and Potential Applications: ') | |
with tag('ul'): | |
line('li', sgd1) | |
line('li', sgd2) | |
with tag('div', klass='my-div'): | |
line('h2', 'Technical challenges faced during this project:') | |
line('p', td) | |
with tag('div', klass='my-div'): | |
line('h2', 'Limitations of this Project/Gradio Application:') | |
line('p', limitation) | |
with tag('div', klass='my-div'): | |
line('h2', 'Conclusion and Future Work:') | |
with tag('ul'): | |
line('li', con1) | |
line('li', con2) | |
line('li', con3) | |
line('li', con4) | |
with tag('div', klass='my-div'): | |
line('h2', 'Team Members:') | |
line('p', mems) | |
css = ''' | |
.my-div { | |
border: 2px solid black; | |
text-align: center; | |
margin: 10px; | |
padding: 5%; | |
} | |
ul { | |
display: inline-block; | |
text-align: left; | |
} | |
.description { | |
text-align: center; | |
} | |
''' | |
return { | |
'article': doc.getvalue(), | |
'css': css, | |
'title': title, | |
'description': description, | |
} |