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 = membs = 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() | |
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', sgd1) | |
with tag('div', klass='my-div'): | |
line('h2', 'Targeted SGDs 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', 'Limitation 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) | |
with tag('div', klass='my-div'): | |
line('h2', 'Team Members') | |
line('p', membs) | |
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, | |
} |