Spaces:
Sleeping
Sleeping
Update 1_π_form.py
Browse files- 1_π_form.py +140 -73
1_π_form.py
CHANGED
@@ -1,4 +1,4 @@
|
|
1 |
-
from yaml import load
|
2 |
from persist import persist, load_widget_state
|
3 |
import streamlit as st
|
4 |
from io import StringIO
|
@@ -11,16 +11,54 @@ from huggingface_hub import create_repo
|
|
11 |
import os
|
12 |
from middleMan import parse_into_jinja_markdown as pj
|
13 |
|
|
|
14 |
|
15 |
-
|
16 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
17 |
def get_cached_data():
|
18 |
languages_df = pd.read_html("https://hf.co/languages")[0]
|
19 |
languages_map = pd.Series(languages_df["Language"].values, index=languages_df["ISO code"]).to_dict()
|
20 |
|
21 |
license_df = pd.read_html("https://huggingface.co/docs/hub/repositories-licenses")[0]
|
22 |
-
print("license_df.keys()",license_df.keys())
|
23 |
-
print(license_df["License identifier (to use in repo card)"])
|
24 |
license_map = pd.Series(
|
25 |
license_df["License identifier (to use in repo card)"].values, index=license_df.Fullname
|
26 |
).to_dict()
|
@@ -31,7 +69,10 @@ def get_cached_data():
|
|
31 |
tags_data = r.json()
|
32 |
libraries = [x['id'] for x in tags_data['library']]
|
33 |
tasks = [x['id'] for x in tags_data['pipeline_tag']]
|
34 |
-
|
|
|
|
|
|
|
35 |
|
36 |
|
37 |
def card_upload(card_info,repo_id,token):
|
@@ -100,9 +141,8 @@ def save_uploadedfile(uploadedfile):
|
|
100 |
|
101 |
|
102 |
def main_page():
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
if "model_name" not in st.session_state:
|
107 |
# Initialize session state.
|
108 |
st.session_state.update({
|
@@ -175,31 +215,58 @@ def main_page():
|
|
175 |
"markdown_state":"",
|
176 |
})
|
177 |
## getting cache for each warnings
|
178 |
-
languages_map, license_map, available_metrics, libraries, tasks = get_cached_data()
|
179 |
|
180 |
## form UI setting
|
181 |
-
st.header("Model
|
182 |
|
183 |
warning_placeholder = st.empty()
|
184 |
|
185 |
st.text_input("Model Name", key=persist("model_name"))
|
186 |
-
st.
|
187 |
-
st.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
188 |
st.selectbox("License", [""] + list(license_map.values()), help="The license associated with this model.", key=persist("license"))
|
189 |
-
st.
|
190 |
-
st.text_input("Parent Model (URL)", help="If this model has another model as its base, please provide the URL link to the parent model", key=persist("Parent_Model_name"))
|
191 |
-
st.text_input("Datasets (comma separated)", help="The dataset(s) used to train this model. Use dataset id from https://hf.co/datasets.", key=persist("datasets"))
|
192 |
-
st.multiselect("Metrics", available_metrics, help="Metrics used in the training/evaluation of this model. Use metric id from https://hf.co/metrics.", key=persist("metrics"))
|
193 |
-
st.selectbox("Task", [""] + tasks, help="What task does this model aim to solve?", key=persist('task'))
|
194 |
-
st.text_input("Tags (comma separated)", help="Additional tags to add which will be filterable on https://hf.co/models. (Ex. image-classification, vision, resnet)", key=persist("tags"))
|
195 |
-
st.text_input("Author(s) (comma separated)", help="The authors who developed this model. If you trained this model, the author is you.", key=persist("the_authors"))
|
196 |
st.text_input("Related Research Paper", help="Research paper related to this model.", key=persist("paper_url"))
|
197 |
st.text_input("Related GitHub Repository", help="Link to a GitHub repository used in the development of this model", key=persist("github_url"))
|
198 |
st.text_area("Bibtex Citation", help="Bibtex citations for related work", key=persist("bibtex_citations"))
|
199 |
-
st.
|
200 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
201 |
|
202 |
-
|
|
|
|
|
|
|
|
|
203 |
# warnings setting
|
204 |
languages=st.session_state.languages or None
|
205 |
license=st.session_state.license or None
|
@@ -221,70 +288,70 @@ def main_page():
|
|
221 |
if do_warn:
|
222 |
warning_placeholder.error(warning_msg)
|
223 |
|
224 |
-
with st.sidebar:
|
225 |
|
226 |
-
|
227 |
-
|
228 |
-
|
229 |
-
|
230 |
|
231 |
-
|
232 |
|
233 |
-
|
234 |
-
|
235 |
-
|
236 |
|
237 |
-
|
238 |
-
|
239 |
|
240 |
-
|
241 |
|
242 |
-
|
243 |
-
|
244 |
-
|
245 |
-
|
246 |
-
|
247 |
|
248 |
-
|
249 |
|
250 |
-
|
251 |
|
252 |
-
|
253 |
-
|
254 |
-
|
255 |
-
|
256 |
-
|
257 |
-
|
258 |
-
|
259 |
-
|
260 |
-
|
261 |
-
|
262 |
-
|
263 |
-
|
264 |
-
|
265 |
-
|
266 |
-
|
267 |
-
|
268 |
-
|
269 |
-
|
270 |
-
|
271 |
-
|
272 |
|
273 |
|
274 |
-
|
275 |
-
|
276 |
-
|
277 |
|
278 |
|
279 |
-
|
280 |
|
281 |
-
|
282 |
-
|
283 |
-
|
284 |
-
|
285 |
-
|
286 |
-
|
287 |
-
|
288 |
|
289 |
|
290 |
def page_switcher(page):
|
|
|
1 |
+
# from yaml import load
|
2 |
from persist import persist, load_widget_state
|
3 |
import streamlit as st
|
4 |
from io import StringIO
|
|
|
11 |
import os
|
12 |
from middleMan import parse_into_jinja_markdown as pj
|
13 |
|
14 |
+
import requests
|
15 |
|
16 |
+
# @st.cache
|
17 |
+
def get_icd():
|
18 |
+
# Get ICD10 list
|
19 |
+
token_endpoint = 'https://icdaccessmanagement.who.int/connect/token'
|
20 |
+
client_id = '3bc9c811-7f2e-4dab-a2dc-940e47a38fef_a6108252-4503-4ff7-90ab-300fd27392aa'
|
21 |
+
client_secret = 'xPj7mleWf1Bilu9f7P10UQmBPvL5F6Wgd8/rJhO1T04='
|
22 |
+
scope = 'icdapi_access'
|
23 |
+
grant_type = 'client_credentials'
|
24 |
+
# set data to post
|
25 |
+
payload = {'client_id': client_id,
|
26 |
+
'client_secret': client_secret,
|
27 |
+
'scope': scope,
|
28 |
+
'grant_type': grant_type}
|
29 |
+
# make request
|
30 |
+
r = requests.post(token_endpoint, data=payload, verify=False).json()
|
31 |
+
token = r['access_token']
|
32 |
+
# access ICD API
|
33 |
+
uri = 'https://id.who.int/icd/release/10/2019/C00-C75'
|
34 |
+
# HTTP header fields to set
|
35 |
+
headers = {'Authorization': 'Bearer '+token,
|
36 |
+
'Accept': 'application/json',
|
37 |
+
'Accept-Language': 'en',
|
38 |
+
'API-Version': 'v2'}
|
39 |
+
# make request
|
40 |
+
r = requests.get(uri, headers=headers, verify=False)
|
41 |
+
print("icd",r.json())
|
42 |
+
icd_map =[]
|
43 |
+
for child in r.json()['child']:
|
44 |
+
r_child = requests.get(child, headers=headers,verify=False).json()
|
45 |
+
icd_map.append(r_child["code"]+" "+r_child["title"]["@value"])
|
46 |
+
return icd_map
|
47 |
+
|
48 |
+
# @st.cache
|
49 |
+
def get_treatment_mod():
|
50 |
+
url = "https://clinicaltables.nlm.nih.gov/loinc_answers?loinc_num=21964-2"
|
51 |
+
r = requests.get(url).json()
|
52 |
+
treatment_mod = [treatment['DisplayText'] for treatment in r]
|
53 |
+
return treatment_mod
|
54 |
+
|
55 |
+
|
56 |
+
# @st.cache _data or _resource
|
57 |
def get_cached_data():
|
58 |
languages_df = pd.read_html("https://hf.co/languages")[0]
|
59 |
languages_map = pd.Series(languages_df["Language"].values, index=languages_df["ISO code"]).to_dict()
|
60 |
|
61 |
license_df = pd.read_html("https://huggingface.co/docs/hub/repositories-licenses")[0]
|
|
|
|
|
62 |
license_map = pd.Series(
|
63 |
license_df["License identifier (to use in repo card)"].values, index=license_df.Fullname
|
64 |
).to_dict()
|
|
|
69 |
tags_data = r.json()
|
70 |
libraries = [x['id'] for x in tags_data['library']]
|
71 |
tasks = [x['id'] for x in tags_data['pipeline_tag']]
|
72 |
+
|
73 |
+
icd_map = get_icd()
|
74 |
+
treatment_mod = get_treatment_mod()
|
75 |
+
return languages_map, license_map, available_metrics, libraries, tasks, icd_map, treatment_mod
|
76 |
|
77 |
|
78 |
def card_upload(card_info,repo_id,token):
|
|
|
141 |
|
142 |
|
143 |
def main_page():
|
144 |
+
|
145 |
+
|
|
|
146 |
if "model_name" not in st.session_state:
|
147 |
# Initialize session state.
|
148 |
st.session_state.update({
|
|
|
215 |
"markdown_state":"",
|
216 |
})
|
217 |
## getting cache for each warnings
|
218 |
+
languages_map, license_map, available_metrics, libraries, tasks, icd_map, treatment_mod = get_cached_data()
|
219 |
|
220 |
## form UI setting
|
221 |
+
st.header("Model basic information (Dose prediction)")
|
222 |
|
223 |
warning_placeholder = st.empty()
|
224 |
|
225 |
st.text_input("Model Name", key=persist("model_name"))
|
226 |
+
st.number_input("Version",key=persist("version"),step=0.1)
|
227 |
+
st.text("Intended use:")
|
228 |
+
left, right = st.columns([4,2])
|
229 |
+
left.multiselect("Treatment site ICD10",list(icd_map), help="Reference ICD10 WHO: https://icd.who.int/icdapi")
|
230 |
+
right.multiselect("Treatment modality", list(treatment_mod), help="Reference LOINC Modality Radiation treatment: https://loinc.org/21964-2" )
|
231 |
+
left, right = st.columns(2)
|
232 |
+
nlines = left.number_input("Number of prescription levels", 0, 20, 1)
|
233 |
+
# cols = st.columns(ncol)
|
234 |
+
for i in range(nlines):
|
235 |
+
right.number_input(f"Prescription [Gy] # {i}", key=i)
|
236 |
+
st.text_area("Additional information", placeholder = "Bilateral cases only", help="E.g. Bilateral cases only", key=persist('additional_information'))
|
237 |
+
st.text_area("Motivation for development", key=persist('motivation'))
|
238 |
+
st.text_area("Class", placeholder="RULE 11, FROM MDCG 2021-24", key=persist('class'))
|
239 |
+
st.date_input("Creation date", key=persist('creation_date'))
|
240 |
+
st.text_area("Type of architecture",value="UNet", key=persist('architecture'))
|
241 |
+
|
242 |
+
st.text("Developed by:")
|
243 |
+
left, middle, right = st.columns(3)
|
244 |
+
left.text_input("Name", key=persist('dev_name'))
|
245 |
+
middle.text_input("Institution", placeholder = "University/clinic/company", key=persist('dev_institution'))
|
246 |
+
right.text_input("Email", key=persist('dev_email'))
|
247 |
+
|
248 |
+
st.text_area("Funded by", key=persist('fund'))
|
249 |
+
st.text_area("Shared by", key=persist('shared'))
|
250 |
st.selectbox("License", [""] + list(license_map.values()), help="The license associated with this model.", key=persist("license"))
|
251 |
+
st.text_area("Fine tuned from model", key=persist('fine_tuned_from'))
|
|
|
|
|
|
|
|
|
|
|
|
|
252 |
st.text_input("Related Research Paper", help="Research paper related to this model.", key=persist("paper_url"))
|
253 |
st.text_input("Related GitHub Repository", help="Link to a GitHub repository used in the development of this model", key=persist("github_url"))
|
254 |
st.text_area("Bibtex Citation", help="Bibtex citations for related work", key=persist("bibtex_citations"))
|
255 |
+
# st.selectbox("Library Name", [""] + libraries, help="The name of the library this model came from (Ex. pytorch, timm, spacy, keras, etc.). This is usually automatically detected in model repos, so it is not required.", key=persist('library_name'))
|
256 |
+
# st.text_input("Parent Model (URL)", help="If this model has another model as its base, please provide the URL link to the parent model", key=persist("Parent_Model_name"))
|
257 |
+
# st.text_input("Datasets (comma separated)", help="The dataset(s) used to train this model. Use dataset id from https://hf.co/datasets.", key=persist("datasets"))
|
258 |
+
# st.multiselect("Metrics", available_metrics, help="Metrics used in the training/evaluation of this model. Use metric id from https://hf.co/metrics.", key=persist("metrics"))
|
259 |
+
# st.selectbox("Task", [""] + tasks, help="What task does this model aim to solve?", key=persist('task'))
|
260 |
+
# st.text_input("Tags (comma separated)", help="Additional tags to add which will be filterable on https://hf.co/models. (Ex. image-classification, vision, resnet)", key=persist("tags"))
|
261 |
+
# st.text_input("Author(s) (comma separated)", help="The authors who developed this model. If you trained this model, the author is you.", key=persist("the_authors"))
|
262 |
+
# s
|
263 |
+
# st.text_input("Carbon Emitted:", help="You can estimate carbon emissions using the [Machine Learning Impact calculator](https://mlco2.github.io/impact#compute) presented in [Lacoste et al. (2019)](https://arxiv.org/abs/1910.09700)", key=persist("Model_c02_emitted"))
|
264 |
|
265 |
+
# st.header("Technical specifications")
|
266 |
+
# st.header("Training data, methodology, and results")
|
267 |
+
# st.header("Evaluation data, methodology, and results / commissioning")
|
268 |
+
# st.header("Ethical use considerations")
|
269 |
+
|
270 |
# warnings setting
|
271 |
languages=st.session_state.languages or None
|
272 |
license=st.session_state.license or None
|
|
|
288 |
if do_warn:
|
289 |
warning_placeholder.error(warning_msg)
|
290 |
|
291 |
+
# with st.sidebar:
|
292 |
|
293 |
+
# ######################################################
|
294 |
+
# ### Uploading a model card from local drive
|
295 |
+
# ######################################################
|
296 |
+
# st.markdown("## Upload Model Card")
|
297 |
|
298 |
+
# st.markdown("#### Model Card must be in markdown (.md) format.")
|
299 |
|
300 |
+
# # Read a single file
|
301 |
+
# uploaded_file = st.file_uploader("Choose a file", type = ['md'], help = 'Please choose a markdown (.md) file type to upload')
|
302 |
+
# if uploaded_file is not None:
|
303 |
|
304 |
+
# file_details = {"FileName":uploaded_file.name,"FileType":uploaded_file.type}
|
305 |
+
# name_of_uploaded_file = save_uploadedfile(uploaded_file)
|
306 |
|
307 |
+
# st.session_state.markdown_upload = name_of_uploaded_file ## uploaded model card
|
308 |
|
309 |
+
# elif st.session_state.task =='fill-mask' or 'translation' or 'token-classification' or ' sentence-similarity' or 'summarization' or 'question-answering' or 'text2text-generation' or 'text-classification' or 'text-generation' or 'conversational':
|
310 |
+
# #st.session_state.markdown_upload = open(
|
311 |
+
# # "language_model_template1.md", "r+"
|
312 |
+
# #).read()
|
313 |
+
# st.session_state.markdown_upload = "language_model_template1.md" ## language model template
|
314 |
|
315 |
+
# elif st.session_state.task:
|
316 |
|
317 |
+
# st.session_state.markdown_upload = "current_card.md" ## default non language model template
|
318 |
|
319 |
+
# #########################################
|
320 |
+
# ### Uploading model card to HUB
|
321 |
+
# #########################################
|
322 |
+
# out_markdown =open( st.session_state.markdown_upload, "r+"
|
323 |
+
# ).read()
|
324 |
+
# print_out_final = f"{out_markdown}"
|
325 |
+
# st.markdown("## Export Loaded Model Card to Hub")
|
326 |
+
# with st.form("Upload to π€ Hub"):
|
327 |
+
# st.markdown("Use a token with write access from [here](https://hf.co/settings/tokens)")
|
328 |
+
# token = st.text_input("Token", type='password')
|
329 |
+
# repo_id = st.text_input("Repo ID")
|
330 |
+
# submit = st.form_submit_button('Upload to π€ Hub', help='The current model card will be uploaded to a branch in the supplied repo ')
|
331 |
+
|
332 |
+
# if submit:
|
333 |
+
# if len(repo_id.split('/')) == 2:
|
334 |
+
# repo_url = create_repo(repo_id, exist_ok=True, token=token)
|
335 |
+
# new_url = card_upload(pj(),repo_id, token=token)
|
336 |
+
# st.success(f"Pushed the card to the repo [here]({new_url})!") # note: was repo_url
|
337 |
+
# else:
|
338 |
+
# st.error("Repo ID invalid. It should be username/repo-name. For example: nateraw/food")
|
339 |
|
340 |
|
341 |
+
# #########################################
|
342 |
+
# ### Download model card
|
343 |
+
# #########################################
|
344 |
|
345 |
|
346 |
+
# st.markdown("## Download current Model Card")
|
347 |
|
348 |
+
# if st.session_state.model_name is None or st.session_state.model_name== ' ':
|
349 |
+
# downloaded_file_name = 'current_model_card.md'
|
350 |
+
# else:
|
351 |
+
# downloaded_file_name = st.session_state.model_name+'_'+'model_card.md'
|
352 |
+
# download_status = st.download_button(label = 'Download Model Card', data = pj(), file_name = downloaded_file_name, help = "The current model card will be downloaded as a markdown (.md) file")
|
353 |
+
# if download_status == True:
|
354 |
+
# st.success("Your current model card, successfully downloaded π€")
|
355 |
|
356 |
|
357 |
def page_switcher(page):
|