File size: 8,171 Bytes
2d5ffb9 b2c7a50 2d5ffb9 b2c7a50 2d5ffb9 e1f97c2 2d5ffb9 b2c7a50 e1f97c2 2d5ffb9 |
1 2 3 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 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 |
import streamlit as st
from persist import persist, load_widget_state
#from pages.viewCardProgress import get_card
from modelcards import CardData, ModelCard
from markdownTagExtract import tag_checker,listToString,to_markdown
#from specific_extraction import extract_it
from modelcards import CardData, ModelCard
from jinja2 import Environment, FileSystemLoader
def is_float(value):
try:
float(value)
return True
except:
return False
## Handles parsing jinja variable templates
def parse_into_jinja_markdown():
env = Environment(loader=FileSystemLoader('.'), autoescape=True)
temp = env.get_template(st.session_state.markdown_upload)
# to add:
# - parent model
# to fix:
# citation on form: check box for bibtex or apa: then parse
return (temp.render(model_id = st.session_state["model_name"],
language = st.session_state["languages"],
the_model_description = st.session_state["model_description"],developers=st.session_state["Model_developers"],shared_by = st.session_state["shared_by"],license = st.session_state['license'],
direct_use = st.session_state["Direct_Use"], downstream_use = st.session_state["Downstream_Use"],out_of_scope_use = st.session_state["Out-of-Scope_Use"],
bias_risks_limitations = st.session_state["Model_Limits_n_Risks"], bias_recommendations = st.session_state['Recommendations'],
model_examination = st.session_state['Model_examin'],
speeds_sizes_times = st.session_state['Speeds_Sizes_Times'],
hardware= st.session_state['Model_hardware'], hours_used = st.session_state['hours_used'], cloud_provider = st.session_state['Model_cloud_provider'], cloud_region = st.session_state['Model_cloud_region'], co2_emitted = st.session_state['Model_c02_emitted'],
citation_bibtex= st.session_state["APA_citation"], citation_apa = st.session_state['bibtex_citation'],
training_data = st.session_state['training_data'], preprocessing =st.session_state['preprocessing'], speeds_sizes_times = st.session_state['Speeds_Sizes_Times'],
model_specs = st.session_state['Model_specs'], compute_infrastructure = st.session_state['compute_infrastructure'],software = st.session_state['technical_specs_software'],
glossary = st.session_state['Glossary'],
more_information = st.session_state['More_info'],
model_card_authors = st.session_state['the_authors'],
model_card_contact = st.session_state['Model_card_contact'],
get_started_code =st.session_state["Model_how_to"],
repo_link = st.session_state["github_url"],
paper_link = st.session_state["paper_url"],
blog_link = st.session_state["blog_url"],
testing_data = st.session_state["testing_data"],
testing_factor = st.session_state["testing_factor"],
results = st.session_state["results"],
testing_metrics = st.session_state["testing_metrics"]
))
################################################################
################################################################
################################################################
################## Below CURRENTLY Deprecated ##################
################################################################
################################################################
################################################################
def get_card():
languages=st.session_state.languages or None
license=st.session_state.license or None
library_name = st.session_state.library_name or None
tags= [x.strip() for x in st.session_state.tags.split(',') if x.strip()]
tags.append("autogenerated-modelcard")
datasets= [x.strip() for x in st.session_state.datasets.split(',') if x.strip()] or None
metrics=st.session_state.metrics or None
model_name = st.session_state.model_name or None
model_description = st.session_state.model_description or None
authors = st.session_state.Model_card_authors or None
paper_url = st.session_state.paper_url or None
github_url = st.session_state.github_url or None
bibtex_citations = st.session_state.bibtex_citations or None
emissions = float(st.session_state.Model_c02_emitted) if is_float(st.session_state.Model_c02_emitted) else None # BUG
# Handle any warnings...
do_warn = False
warning_msg = "Warning: The following fields are required but have not been filled in: "
if not languages:
warning_msg += "\n- Languages"
do_warn = True
if not license:
warning_msg += "\n- License"
do_warn = True
if do_warn:
st.error(warning_msg)
st.stop()
# Generate and display card
card_data = CardData(
language=languages,
license=license,
library_name=library_name,
tags=tags,
datasets=datasets,
metrics=metrics,
)
if emissions:
card_data.co2_eq_emissions = {'emissions': emissions}
card = ModelCard.from_template(
card_data,
template_path='template.md',
model_id=model_name,
# Template kwargs:
model_description=model_description,
license=license,
authors=authors,
paper_url=paper_url,
github_url=github_url,
bibtex_citations=bibtex_citations,
emissions=emissions
)
return card
def apply_view(page_state, not_code_pull,text_passed):
not_important_section = True
if st.session_state.legal_view == True:
#user_view = 'legal_view'
user_view_collapse={'Model_details_text','Model_uses','Model_Eval','Model_carbon','Model_cite', 'Glossary','Model_card_authors'}
elif st.session_state.researcher_view == True:
#user_view = 'researcher_view'
user_view_collapse={'Model_details_text','Model_how_to','Model_training','Model_Limits_n_Risks', 'Glossary', 'Model_card_contact', 'Citation'}
else:
#user_view = 'beginner_technical_view'
user_view_collapse={'Model_details_text','Model_how_to','Model_Eval','Model_uses', 'Glossary'} # Add Techical Spec
for value in user_view_collapse:
if value == page_state:
not_important_section = False
if not_important_section == True: #and st.session_state[user_view]:
#st.markdown("here")
text_return = out_text_out(not_code_pull,page_state,text_passed)
out_text = "<details> <summary> Click to expand </summary>" +text_return + "</details>"
return (out_text)
#out_text = "<details>" + out_text + "</details>"
else:
text_return = out_text_out(not_code_pull,page_state,text_passed)
out_text = text_return
return (out_text)
def out_text_out(not_code_pull,page_state,out_text):
if not_code_pull == True:
out_text = extract_it(page_state)
return(out_text)
else:
out_text = out_text
return(out_text)
def writingPrompt(page_state, help_text, out_text):
#st.session_state.check_box = False
#extracted_how_to= tag_checker(markdown,start_tag,end_tag)
#see_suggestion = column.checkbox("See Writing Prompt")
st.session_state.check_box = True
variable_output_prompt = st.text_area("Enter some text",height = 500, value =out_text, key=persist(out_text),
help=help_text)
st.session_state.page_state = persist(variable_output_prompt)
#out_text = extract_it(page_state)
#else:
#st.session_state.check_box = True
##st.session_state.check_box = False
#variable_output_prompt = st.text_area("Enter Text",value = ' ',key=persist(page_state),height = 500,help =help_text)
return variable_output_prompt
def extract_section(current_template, start_tag, end_tag):
current_Card_markdown= current_template
extracted_how_to= tag_checker(current_Card_markdown,start_tag,end_tag)
out_text = ' '.join(extracted_how_to)
return out_text
def main():
#card.save('current_card.md')
return |