Spaces:
				
			
			
	
			
			
		Runtime error
		
	
	
	
			
			
	
	
	
	
		
		
		Runtime error
		
	Commit 
							
							·
						
						34bb9f0
	
1
								Parent(s):
							
							8a4df7f
								
Update app.py
Browse files
    	
        app.py
    CHANGED
    
    | @@ -20,9 +20,11 @@ def caption_image(model_choice, image_input, url_input, load_in_8bit): | |
| 20 | 
             
                else:
         | 
| 21 | 
             
                    input_data = url_input
         | 
| 22 |  | 
|  | |
|  | |
| 23 | 
             
                # Check if the model is already loaded
         | 
| 24 | 
            -
                if  | 
| 25 | 
            -
                    captioner = loaded_models[ | 
| 26 | 
             
                else:
         | 
| 27 | 
             
                    model_kwargs = {"load_in_8bit": load_in_8bit} if load_in_8bit else {}
         | 
| 28 | 
             
                    captioner = pipeline(task="image-to-text",
         | 
| @@ -31,7 +33,7 @@ def caption_image(model_choice, image_input, url_input, load_in_8bit): | |
| 31 | 
             
                                        device_map="cpu", model_kwargs=model_kwargs, use_fast=True
         | 
| 32 | 
             
                                        )
         | 
| 33 | 
             
                    # Store the loaded model
         | 
| 34 | 
            -
                    loaded_models[ | 
| 35 |  | 
| 36 | 
             
                caption = captioner(input_data)[0]['generated_text']
         | 
| 37 | 
             
                return str(caption).strip()
         | 
| @@ -45,4 +47,4 @@ url_input = gr.Text(label="Input URL") | |
| 45 | 
             
            load_in_8bit = gr.Checkbox(label="Load model in 8bit")
         | 
| 46 |  | 
| 47 | 
             
            iface = gr.Interface(launch, inputs=[model_dropdown, image_input, url_input, load_in_8bit], outputs="text")
         | 
| 48 | 
            -
            iface.launch()
         | 
|  | |
| 20 | 
             
                else:
         | 
| 21 | 
             
                    input_data = url_input
         | 
| 22 |  | 
| 23 | 
            +
                model_key = (model_choice, load_in_8bit)  # Create a tuple to represent the unique combination of model and 8bit loading
         | 
| 24 | 
            +
             | 
| 25 | 
             
                # Check if the model is already loaded
         | 
| 26 | 
            +
                if model_key in loaded_models:
         | 
| 27 | 
            +
                    captioner = loaded_models[model_key]
         | 
| 28 | 
             
                else:
         | 
| 29 | 
             
                    model_kwargs = {"load_in_8bit": load_in_8bit} if load_in_8bit else {}
         | 
| 30 | 
             
                    captioner = pipeline(task="image-to-text",
         | 
|  | |
| 33 | 
             
                                        device_map="cpu", model_kwargs=model_kwargs, use_fast=True
         | 
| 34 | 
             
                                        )
         | 
| 35 | 
             
                    # Store the loaded model
         | 
| 36 | 
            +
                    loaded_models[model_key] = captioner
         | 
| 37 |  | 
| 38 | 
             
                caption = captioner(input_data)[0]['generated_text']
         | 
| 39 | 
             
                return str(caption).strip()
         | 
|  | |
| 47 | 
             
            load_in_8bit = gr.Checkbox(label="Load model in 8bit")
         | 
| 48 |  | 
| 49 | 
             
            iface = gr.Interface(launch, inputs=[model_dropdown, image_input, url_input, load_in_8bit], outputs="text")
         | 
| 50 | 
            +
            iface.launch()
         | 
