Spaces:
				
			
			
	
			
			
		Runtime error
		
	
	
	
			
			
	
	
	
	
		
		
		Runtime error
		
	
		Benjamin Bossan
		
	commited on
		
		
					Commit 
							
							·
						
						41e8f46
	
1
								Parent(s):
							
							dd68837
								
Fix bug when loading model card with imgs
Browse files
    	
        start.py
    CHANGED
    
    | @@ -21,7 +21,7 @@ from tempfile import mkdtemp | |
| 21 | 
             
            import pandas as pd
         | 
| 22 | 
             
            import sklearn
         | 
| 23 | 
             
            import streamlit as st
         | 
| 24 | 
            -
            from huggingface_hub import  | 
| 25 | 
             
            from huggingface_hub.utils import HFValidationError, RepositoryNotFoundError
         | 
| 26 | 
             
            from sklearn.base import BaseEstimator
         | 
| 27 | 
             
            from sklearn.dummy import DummyClassifier
         | 
| @@ -98,7 +98,6 @@ def init_repo() -> None: | |
| 98 | 
             
                        data=data,
         | 
| 99 | 
             
                        requirements=requirements,
         | 
| 100 | 
             
                    )
         | 
| 101 | 
            -
                    1
         | 
| 102 | 
             
                except Exception as exc:
         | 
| 103 | 
             
                    print("Uh oh, something went wrong when initializing the repo:", exc)
         | 
| 104 |  | 
| @@ -130,7 +129,7 @@ def create_hf_model_card() -> None: | |
| 130 | 
             
                    return
         | 
| 131 |  | 
| 132 | 
             
                try:
         | 
| 133 | 
            -
                    path =  | 
| 134 | 
             
                except (HFValidationError, RepositoryNotFoundError):
         | 
| 135 | 
             
                    st.error(
         | 
| 136 | 
             
                        f"Repository '{repo_id}' could not be found on HF Hub, "
         | 
| @@ -138,7 +137,12 @@ def create_hf_model_card() -> None: | |
| 138 | 
             
                    )
         | 
| 139 | 
             
                    return
         | 
| 140 |  | 
| 141 | 
            -
                 | 
|  | |
|  | |
|  | |
|  | |
|  | |
| 142 | 
             
                st.session_state.model_card = model_card
         | 
| 143 | 
             
                st.session_state.model_card_type = "loaded"
         | 
| 144 | 
             
                st.session_state.screen.state = "edit"
         | 
|  | |
| 21 | 
             
            import pandas as pd
         | 
| 22 | 
             
            import sklearn
         | 
| 23 | 
             
            import streamlit as st
         | 
| 24 | 
            +
            from huggingface_hub import snapshot_download
         | 
| 25 | 
             
            from huggingface_hub.utils import HFValidationError, RepositoryNotFoundError
         | 
| 26 | 
             
            from sklearn.base import BaseEstimator
         | 
| 27 | 
             
            from sklearn.dummy import DummyClassifier
         | 
|  | |
| 98 | 
             
                        data=data,
         | 
| 99 | 
             
                        requirements=requirements,
         | 
| 100 | 
             
                    )
         | 
|  | |
| 101 | 
             
                except Exception as exc:
         | 
| 102 | 
             
                    print("Uh oh, something went wrong when initializing the repo:", exc)
         | 
| 103 |  | 
|  | |
| 129 | 
             
                    return
         | 
| 130 |  | 
| 131 | 
             
                try:
         | 
| 132 | 
            +
                    path = snapshot_download(repo_id)
         | 
| 133 | 
             
                except (HFValidationError, RepositoryNotFoundError):
         | 
| 134 | 
             
                    st.error(
         | 
| 135 | 
             
                        f"Repository '{repo_id}' could not be found on HF Hub, "
         | 
|  | |
| 137 | 
             
                    )
         | 
| 138 | 
             
                    return
         | 
| 139 |  | 
| 140 | 
            +
                # move everything to the hf_path and working dir
         | 
| 141 | 
            +
                hf_path = st.session_state.hf_path
         | 
| 142 | 
            +
                shutil.copytree(path, hf_path, dirs_exist_ok=True)
         | 
| 143 | 
            +
                shutil.copytree(path, ".", dirs_exist_ok=True)
         | 
| 144 | 
            +
             | 
| 145 | 
            +
                model_card = card.parse_modelcard(hf_path / "README.md")
         | 
| 146 | 
             
                st.session_state.model_card = model_card
         | 
| 147 | 
             
                st.session_state.model_card_type = "loaded"
         | 
| 148 | 
             
                st.session_state.screen.state = "edit"
         | 
