Spaces:
				
			
			
	
			
			
					
		Running
		
	
	
	
			
			
	
	
	
	
		
		
					
		Running
		
	add error handling
Browse files- myapp/app.py +13 -8
    	
        myapp/app.py
    CHANGED
    
    | @@ -9,13 +9,12 @@ from huggingface_hub import InferenceClient | |
| 9 | 
             
            from PIL import Image
         | 
| 10 | 
             
            from qrcode_artistic import write_artistic
         | 
| 11 |  | 
| 12 | 
            -
             | 
| 13 | 
            -
                 | 
| 14 | 
            -
                    import dotenv
         | 
| 15 |  | 
| 16 | 
            -
             | 
| 17 | 
            -
             | 
| 18 | 
            -
             | 
| 19 |  | 
| 20 | 
             
            client = InferenceClient(model="black-forest-labs/FLUX.1-schnell")
         | 
| 21 |  | 
| @@ -35,10 +34,16 @@ with gr.Blocks() as demo: | |
| 35 | 
             
                @gr.on(
         | 
| 36 | 
             
                    triggers=[button.click, prompt.submit],
         | 
| 37 | 
             
                    inputs=prompt,
         | 
| 38 | 
            -
                    outputs=[ | 
| 39 | 
             
                )
         | 
| 40 | 
             
                def generate_background(prompt):
         | 
| 41 | 
            -
                     | 
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
| 42 |  | 
| 43 | 
             
                @gr.on(
         | 
| 44 | 
             
                    triggers=[text.submit, background.change, scale.change],
         | 
|  | |
| 9 | 
             
            from PIL import Image
         | 
| 10 | 
             
            from qrcode_artistic import write_artistic
         | 
| 11 |  | 
| 12 | 
            +
            try:
         | 
| 13 | 
            +
                import dotenv
         | 
|  | |
| 14 |  | 
| 15 | 
            +
                dotenv.load_dotenv()
         | 
| 16 | 
            +
            except ImportError:
         | 
| 17 | 
            +
                pass
         | 
| 18 |  | 
| 19 | 
             
            client = InferenceClient(model="black-forest-labs/FLUX.1-schnell")
         | 
| 20 |  | 
|  | |
| 34 | 
             
                @gr.on(
         | 
| 35 | 
             
                    triggers=[button.click, prompt.submit],
         | 
| 36 | 
             
                    inputs=prompt,
         | 
| 37 | 
            +
                    outputs=[button, background],
         | 
| 38 | 
             
                )
         | 
| 39 | 
             
                def generate_background(prompt):
         | 
| 40 | 
            +
                    yield gr.update(interactive=False), None
         | 
| 41 | 
            +
                    response = None
         | 
| 42 | 
            +
             | 
| 43 | 
            +
                    try:
         | 
| 44 | 
            +
                        response = client.text_to_image(prompt, width=400, height=400)
         | 
| 45 | 
            +
                    finally:
         | 
| 46 | 
            +
                        yield gr.update(interactive=True), response
         | 
| 47 |  | 
| 48 | 
             
                @gr.on(
         | 
| 49 | 
             
                    triggers=[text.submit, background.change, scale.change],
         | 
