markdown generated well. still panding loading state
Browse files- markdownGenerator.py +84 -64
- sdc_view.py +9 -10
markdownGenerator.py
CHANGED
|
@@ -1,68 +1,88 @@
|
|
| 1 |
-
def generate_markdown(
|
| 2 |
-
|
| 3 |
html_str= f"""
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
<td>-</td>
|
| 62 |
-
<td>Luxembourg</td>
|
| 63 |
-
</tr>
|
| 64 |
-
</table>
|
| 65 |
|
| 66 |
-
|
| 67 |
-
"""
|
| 68 |
return html_str
|
|
|
|
| 1 |
+
def generate_markdown(state):
|
| 2 |
+
print(state)
|
| 3 |
html_str= f"""
|
| 4 |
+
# The Software diversity card of {state["master"]["title"]}
|
| 5 |
+
{state["master"]["desc"]}
|
| 6 |
+
## 🏢 Teams Summary
|
| 7 |
+
|
| 8 |
+
<table>
|
| 9 |
+
<tr>
|
| 10 |
+
<th>Name</th>
|
| 11 |
+
<th>Description</th>
|
| 12 |
+
<th>Type</th>
|
| 13 |
+
<th>Age Range</th>
|
| 14 |
+
<th>Ethnicities</th>
|
| 15 |
+
<th>Genders</th>
|
| 16 |
+
<th>Team Size</th>
|
| 17 |
+
<th>Location</th>
|
| 18 |
+
</tr>"""
|
| 19 |
+
## If development team addit
|
| 20 |
+
if 'participants' in state:
|
| 21 |
+
for key, participant in state['participants'].items():
|
| 22 |
+
if participant['name']:
|
| 23 |
+
html_str = html_str + f"""
|
| 24 |
+
<tr>
|
| 25 |
+
<td><strong>{participant['name']}</strong></td>
|
| 26 |
+
<td>{participant['description'].replace('\n', '')}</td>
|
| 27 |
+
"""
|
| 28 |
+
if 'type' in body:
|
| 29 |
+
html_str = html_str + f"""<td>{body['type'][0]}</td>"""
|
| 30 |
+
else:
|
| 31 |
+
html_str = html_str + f"""<td> </td>"""
|
| 32 |
|
| 33 |
+
html_str = html_str + f"""
|
| 34 |
+
<td>{participant['age'][0]}-{participant['age'][1]}</td>
|
| 35 |
+
<td>{participant['ethnicities']}</td>
|
| 36 |
+
<td>{participant['genders']}</td>
|
| 37 |
+
<td>{participant['size']}</td>
|
| 38 |
+
<td>{participant['location']}</td>
|
| 39 |
+
</tr>"""
|
| 40 |
+
## If target Communities add it
|
| 41 |
+
if state['socialContext']['targetCommunity']['name']:
|
| 42 |
+
html_str = html_str + f"""
|
| 43 |
+
<tr>
|
| 44 |
+
<td><strong>{state['socialContext']['targetCommunity']['name']}</strong></td>
|
| 45 |
+
<td>{state['socialContext']['targetCommunity']['description'].replace('\n', '')}</td>
|
| 46 |
+
<td> Targeted Community </td>
|
| 47 |
+
<td>{state['socialContext']['targetCommunity']['age'][0]}-{state['socialContext']['targetCommunity']['age'][1]}</td>
|
| 48 |
+
<td>{state['socialContext']['targetCommunity']['ethnicities']}</td>
|
| 49 |
+
<td>{state['socialContext']['targetCommunity']['genders']}</td>
|
| 50 |
+
<td> many </td>
|
| 51 |
+
<td>{state['socialContext']['targetCommunity']['location']}</td>
|
| 52 |
+
</tr>"""
|
| 53 |
+
## If bodies add
|
| 54 |
+
if 'governance' in state:
|
| 55 |
+
if 'bodies' in state['governance']:
|
| 56 |
+
for key, body in state['governance']["bodies"].items():
|
| 57 |
+
if body['name']:
|
| 58 |
+
html_str = html_str + f"""
|
| 59 |
+
<tr>
|
| 60 |
+
<td><strong>{body['name'].replace('\n', '')}</strong></td>
|
| 61 |
+
<td>{body['description'].replace('\n', '')}</td>"""
|
| 62 |
+
if 'type' in body:
|
| 63 |
+
html_str = html_str + f"""<td>{body['type'][0]}</td>"""
|
| 64 |
+
else:
|
| 65 |
+
html_str = html_str + f"""<td> </td>"""
|
| 66 |
+
if body['organization']['name']:
|
| 67 |
+
html_str = html_str + f"""
|
| 68 |
+
<td>{body['organization']['age'][0]}-{body['organization']['age'][1]}</td>
|
| 69 |
+
<td>{body['organization']['ethnicities']}</td>
|
| 70 |
+
<td>{body['organization']['genders']}</td>
|
| 71 |
+
<td> - </td>
|
| 72 |
+
<td>{body['organization']['location']}</td>
|
| 73 |
+
</tr>"""
|
| 74 |
+
|
| 75 |
+
if body['participant']['name']:
|
| 76 |
+
html_str = html_str + f"""
|
| 77 |
+
<td>45</td>
|
| 78 |
+
<td>{body['participant']['ethincity']}</td>
|
| 79 |
+
<td>{body['participant']['gender']}</td>
|
| 80 |
+
<td> - </td>
|
| 81 |
+
<td>{body['participant']['location']}</td>
|
| 82 |
+
</tr>"""
|
| 83 |
+
|
| 84 |
+
## End summary
|
| 85 |
+
html_str = html_str + f" </table>"
|
|
|
|
|
|
|
|
|
|
|
|
|
| 86 |
|
| 87 |
+
|
|
|
|
| 88 |
return html_str
|
sdc_view.py
CHANGED
|
@@ -41,9 +41,9 @@ def render_sdc():
|
|
| 41 |
st.error(f"Error saving state: {e}")
|
| 42 |
|
| 43 |
# Run this only once on first load.
|
| 44 |
-
if "loaded" not in st.session_state:
|
| 45 |
-
|
| 46 |
-
|
| 47 |
|
| 48 |
|
| 49 |
# Example of how to filter and serialize session state
|
|
@@ -315,8 +315,8 @@ def render_sdc():
|
|
| 315 |
Welcome to the Software Diversity Card Generator—a form-based application designed to empower you to highlight and promote diversity in software projects. Our innovative tool helps you generate comprehensive diversity cards in both JSON and Markdown formats, offering a transparent overview of the varied teams involved in development and governance, the user groups engaged in testing, and the tailored software adaptations for different social groups. By providing a structured model, an extended JSON syntax, and a toolkit backed by real-world examples, our platform aims to foster inclusive practices that can be embraced by open-source communities, academic journals, and forward-thinking businesses alike.
|
| 316 |
""")
|
| 317 |
|
| 318 |
-
|
| 319 |
-
|
| 320 |
##
|
| 321 |
## Master info
|
| 322 |
##
|
|
@@ -443,17 +443,18 @@ def render_sdc():
|
|
| 443 |
st.divider()
|
| 444 |
st.subheader("The generated card")
|
| 445 |
markDownTab, jsonTab = st.tabs(["**Compiled card in markdown**", "**Generated JSON**" ])
|
|
|
|
| 446 |
with markDownTab:
|
| 447 |
|
| 448 |
# Provide a download button
|
| 449 |
st.download_button(
|
| 450 |
label="Download Markdown",
|
| 451 |
-
data=generate_markdown(
|
| 452 |
file_name="SoftareDiveristyCard.md",
|
| 453 |
mime="text/markdown"
|
| 454 |
)
|
| 455 |
st.text("Preview:")
|
| 456 |
-
st.markdown(generate_markdown(
|
| 457 |
with jsonTab:
|
| 458 |
|
| 459 |
# Convert the session state to a JSON string
|
|
@@ -465,8 +466,6 @@ def render_sdc():
|
|
| 465 |
mime="application/json"
|
| 466 |
)
|
| 467 |
# Display the session state as pretty JSON
|
| 468 |
-
#st.json(serialize_session_state())
|
| 469 |
-
final = unflatten(st.session_state["form_data"])
|
| 470 |
st.text("Preview:")
|
| 471 |
-
st.json(
|
| 472 |
|
|
|
|
| 41 |
st.error(f"Error saving state: {e}")
|
| 42 |
|
| 43 |
# Run this only once on first load.
|
| 44 |
+
#if "loaded" not in st.session_state:
|
| 45 |
+
# load_state()
|
| 46 |
+
# st.session_state["loaded"] = True
|
| 47 |
|
| 48 |
|
| 49 |
# Example of how to filter and serialize session state
|
|
|
|
| 315 |
Welcome to the Software Diversity Card Generator—a form-based application designed to empower you to highlight and promote diversity in software projects. Our innovative tool helps you generate comprehensive diversity cards in both JSON and Markdown formats, offering a transparent overview of the varied teams involved in development and governance, the user groups engaged in testing, and the tailored software adaptations for different social groups. By providing a structured model, an extended JSON syntax, and a toolkit backed by real-world examples, our platform aims to foster inclusive practices that can be embraced by open-source communities, academic journals, and forward-thinking businesses alike.
|
| 316 |
""")
|
| 317 |
|
| 318 |
+
if st.button("Load the Besser's Software Diversity Card example", type="secondary"):
|
| 319 |
+
load_state()
|
| 320 |
##
|
| 321 |
## Master info
|
| 322 |
##
|
|
|
|
| 443 |
st.divider()
|
| 444 |
st.subheader("The generated card")
|
| 445 |
markDownTab, jsonTab = st.tabs(["**Compiled card in markdown**", "**Generated JSON**" ])
|
| 446 |
+
unflattenedJson = unflatten(st.session_state["form_data"])
|
| 447 |
with markDownTab:
|
| 448 |
|
| 449 |
# Provide a download button
|
| 450 |
st.download_button(
|
| 451 |
label="Download Markdown",
|
| 452 |
+
data=generate_markdown(unflattenedJson),
|
| 453 |
file_name="SoftareDiveristyCard.md",
|
| 454 |
mime="text/markdown"
|
| 455 |
)
|
| 456 |
st.text("Preview:")
|
| 457 |
+
st.markdown(generate_markdown(unflattenedJson), unsafe_allow_html=True)
|
| 458 |
with jsonTab:
|
| 459 |
|
| 460 |
# Convert the session state to a JSON string
|
|
|
|
| 466 |
mime="application/json"
|
| 467 |
)
|
| 468 |
# Display the session state as pretty JSON
|
|
|
|
|
|
|
| 469 |
st.text("Preview:")
|
| 470 |
+
st.json(unflattenedJson)
|
| 471 |
|