Spaces:
				
			
			
	
			
			
		Sleeping
		
	
	
	
			
			
	
	
	
	
		
		
		Sleeping
		
	Update app.py
Browse files
    	
        app.py
    CHANGED
    
    | @@ -101,47 +101,55 @@ def process_new_image(image_key, image, kbvqa): | |
| 101 | 
             
            def run_inference():
         | 
| 102 | 
             
                st.title("Run Inference")
         | 
| 103 |  | 
| 104 | 
            -
                method = st.selectbox( | 
| 105 | 
            -
             | 
| 106 | 
            -
             | 
| 107 | 
            -
             | 
| 108 | 
            -
                 | 
| 109 | 
            -
             | 
| 110 | 
            -
                 | 
| 111 | 
            -
             | 
| 112 | 
            -
             | 
| 113 | 
            -
                     | 
| 114 | 
            -
             | 
| 115 | 
            -
             | 
| 116 | 
            -
             | 
| 117 | 
            -
             | 
| 118 | 
            -
             | 
| 119 | 
            -
             | 
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
| 120 |  | 
| 121 | 
             
                if method == "Fine-Tuned Model":
         | 
| 122 | 
             
                    if 'kbvqa' not in st.session_state:
         | 
| 123 | 
             
                        st.session_state['kbvqa'] = None
         | 
| 124 | 
            -
                
         | 
| 125 | 
            -
                    # Button to load KBVQA models
         | 
| 126 | 
            -
             | 
| 127 |  | 
| 128 | 
            -
             | 
| 129 | 
            -
             | 
| 130 | 
            -
                        if st.session_state.get('kbvqa') and not model_changed and not confidence_changed:
         | 
| 131 | 
             
                            st.write("Model already loaded.")
         | 
| 132 | 
             
                        else:
         | 
| 133 | 
             
                            st.text("Loading the model will take no more than a few minutes . .")
         | 
| 134 | 
             
                            st.session_state['kbvqa'] = prepare_kbvqa_model(detection_model)
         | 
| 135 | 
             
                            st.session_state['kbvqa'].detection_confidence = confidence_level
         | 
| 136 | 
            -
                            st. | 
|  | |
| 137 |  | 
| 138 | 
            -
                    if st.session_state | 
| 139 | 
            -
                        st.write("Model is ready for inference.")
         | 
| 140 | 
             
                        image_qa_app(st.session_state['kbvqa'])
         | 
| 141 |  | 
| 142 | 
            -
                else: | 
| 143 | 
             
                    st.write('Model is not ready for inference yet')
         | 
| 144 | 
            -
             | 
| 145 |  | 
| 146 |  | 
| 147 | 
             
            # Main function
         | 
| @@ -149,7 +157,7 @@ def main(): | |
| 149 |  | 
| 150 |  | 
| 151 | 
             
                st.sidebar.title("Navigation")
         | 
| 152 | 
            -
                selection = st.sidebar.radio("Go to", ["Home", "Dataset Analysis", "Finetuning and Evaluation Results", "Run Inference", "Dissertation Report"])
         | 
| 153 | 
             
                st.sidebar.write("More Pages will follow .. ")
         | 
| 154 |  | 
| 155 | 
             
                if selection == "Home":
         | 
| @@ -185,9 +193,15 @@ def main(): | |
| 185 | 
             
                elif selection == "Run Inference":
         | 
| 186 | 
             
                    run_inference()
         | 
| 187 |  | 
|  | |
|  | |
|  | |
|  | |
| 188 | 
             
                elif selection == "More Pages will follow .. ":
         | 
| 189 | 
             
                    st.title("Staye Tuned")
         | 
| 190 | 
             
                    st.write("This is a Place Holder until the contents are uploaded.")
         | 
|  | |
|  | |
| 191 |  | 
| 192 |  | 
| 193 |  | 
|  | |
| 101 | 
             
            def run_inference():
         | 
| 102 | 
             
                st.title("Run Inference")
         | 
| 103 |  | 
| 104 | 
            +
                method = st.selectbox(
         | 
| 105 | 
            +
                    "Choose a method:",
         | 
| 106 | 
            +
                    ["Fine-Tuned Model", "In-Context Learning (n-shots)"],
         | 
| 107 | 
            +
                    index=0
         | 
| 108 | 
            +
                )
         | 
| 109 | 
            +
             | 
| 110 | 
            +
                detection_model = st.selectbox(
         | 
| 111 | 
            +
                    "Choose a model for object detection:",
         | 
| 112 | 
            +
                    ["yolov5", "detic"],
         | 
| 113 | 
            +
                    index=0
         | 
| 114 | 
            +
                )
         | 
| 115 | 
            +
             | 
| 116 | 
            +
                default_confidence = 0.2 if detection_model == "yolov5" else 0.4
         | 
| 117 | 
            +
                confidence_level = st.slider(
         | 
| 118 | 
            +
                    "Select minimum detection confidence level",
         | 
| 119 | 
            +
                    min_value=0.1,
         | 
| 120 | 
            +
                    max_value=0.9,
         | 
| 121 | 
            +
                    value=default_confidence,
         | 
| 122 | 
            +
                    step=0.1
         | 
| 123 | 
            +
                )
         | 
| 124 | 
            +
             | 
| 125 | 
            +
                if 'model_settings' not in st.session_state:
         | 
| 126 | 
            +
                    st.session_state['model_settings'] = {'detection_model': None, 'confidence_level': None}
         | 
| 127 | 
            +
             | 
| 128 | 
            +
                settings_changed = (st.session_state['model_settings']['detection_model'] != detection_model or
         | 
| 129 | 
            +
                                    st.session_state['model_settings']['confidence_level'] != confidence_level)
         | 
| 130 | 
            +
             | 
| 131 | 
            +
                button_label = "Reload Model" if settings_changed else "Load Model"
         | 
| 132 |  | 
| 133 | 
             
                if method == "Fine-Tuned Model":
         | 
| 134 | 
             
                    if 'kbvqa' not in st.session_state:
         | 
| 135 | 
             
                        st.session_state['kbvqa'] = None
         | 
|  | |
|  | |
|  | |
| 136 |  | 
| 137 | 
            +
                    if st.button(button_label):
         | 
| 138 | 
            +
                        if st.session_state['kbvqa'] is not None and not settings_changed:
         | 
|  | |
| 139 | 
             
                            st.write("Model already loaded.")
         | 
| 140 | 
             
                        else:
         | 
| 141 | 
             
                            st.text("Loading the model will take no more than a few minutes . .")
         | 
| 142 | 
             
                            st.session_state['kbvqa'] = prepare_kbvqa_model(detection_model)
         | 
| 143 | 
             
                            st.session_state['kbvqa'].detection_confidence = confidence_level
         | 
| 144 | 
            +
                            st.session_state['model_settings'] = {'detection_model': detection_model, 'confidence_level': confidence_level}
         | 
| 145 | 
            +
                            st.write("Model is ready for inference.")
         | 
| 146 |  | 
| 147 | 
            +
                    if st.session_state['kbvqa']:
         | 
|  | |
| 148 | 
             
                        image_qa_app(st.session_state['kbvqa'])
         | 
| 149 |  | 
| 150 | 
            +
                else:
         | 
| 151 | 
             
                    st.write('Model is not ready for inference yet')
         | 
| 152 | 
            +
             | 
| 153 |  | 
| 154 |  | 
| 155 | 
             
            # Main function
         | 
|  | |
| 157 |  | 
| 158 |  | 
| 159 | 
             
                st.sidebar.title("Navigation")
         | 
| 160 | 
            +
                selection = st.sidebar.radio("Go to", ["Home", "Dataset Analysis", "Finetuning and Evaluation Results", "Run Inference", "Dissertation Report", "Code"])
         | 
| 161 | 
             
                st.sidebar.write("More Pages will follow .. ")
         | 
| 162 |  | 
| 163 | 
             
                if selection == "Home":
         | 
|  | |
| 193 | 
             
                elif selection == "Run Inference":
         | 
| 194 | 
             
                    run_inference()
         | 
| 195 |  | 
| 196 | 
            +
                elif selection == "Code":
         | 
| 197 | 
            +
                    st.title("Staye Tuned")
         | 
| 198 | 
            +
                    st.write("This is a Place Holder until the contents are uploaded.")
         | 
| 199 | 
            +
             | 
| 200 | 
             
                elif selection == "More Pages will follow .. ":
         | 
| 201 | 
             
                    st.title("Staye Tuned")
         | 
| 202 | 
             
                    st.write("This is a Place Holder until the contents are uploaded.")
         | 
| 203 | 
            +
             | 
| 204 | 
            +
             | 
| 205 |  | 
| 206 |  | 
| 207 |  | 
