Spaces:
Sleeping
Sleeping
Update 1_π_form.py
Browse files- 1_π_form.py +50 -50
1_π_form.py
CHANGED
|
@@ -288,70 +288,70 @@ def main_page():
|
|
| 288 |
if do_warn:
|
| 289 |
warning_placeholder.error(warning_msg)
|
| 290 |
|
| 291 |
-
|
| 292 |
|
| 293 |
-
|
| 294 |
-
|
| 295 |
-
|
| 296 |
-
|
| 297 |
|
| 298 |
-
|
| 299 |
|
| 300 |
-
|
| 301 |
-
|
| 302 |
-
|
| 303 |
|
| 304 |
-
|
| 305 |
-
|
| 306 |
|
| 307 |
-
|
| 308 |
|
| 309 |
-
|
| 310 |
-
|
| 311 |
-
|
| 312 |
-
|
| 313 |
-
|
| 314 |
|
| 315 |
-
|
| 316 |
|
| 317 |
-
|
| 318 |
|
| 319 |
-
|
| 320 |
-
|
| 321 |
-
|
| 322 |
-
|
| 323 |
-
|
| 324 |
-
|
| 325 |
-
|
| 326 |
-
|
| 327 |
-
|
| 328 |
-
|
| 329 |
-
|
| 330 |
-
|
| 331 |
-
|
| 332 |
-
|
| 333 |
-
|
| 334 |
-
|
| 335 |
-
|
| 336 |
-
|
| 337 |
-
|
| 338 |
-
|
| 339 |
|
| 340 |
|
| 341 |
-
|
| 342 |
-
|
| 343 |
-
|
| 344 |
|
| 345 |
|
| 346 |
-
|
| 347 |
|
| 348 |
-
|
| 349 |
-
|
| 350 |
-
|
| 351 |
-
|
| 352 |
-
|
| 353 |
-
|
| 354 |
-
|
| 355 |
|
| 356 |
|
| 357 |
def page_switcher(page):
|
|
|
|
| 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):
|