Spaces:
				
			
			
	
			
			
		Runtime error
		
	
	
	
			
			
	
	
	
	
		
		
		Runtime error
		
	Add app.py
Browse files
    	
        app.py
    ADDED
    
    | 
         @@ -0,0 +1,260 @@ 
     | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
| 
         | 
|
| 1 | 
         
            +
            #!/usr/bin/env python
         
     | 
| 2 | 
         
            +
            # encoding: utf-8
         
     | 
| 3 | 
         
            +
            import gradio as gr
         
     | 
| 4 | 
         
            +
            from PIL import Image
         
     | 
| 5 | 
         
            +
            import traceback
         
     | 
| 6 | 
         
            +
            import re
         
     | 
| 7 | 
         
            +
            import torch
         
     | 
| 8 | 
         
            +
            import argparse
         
     | 
| 9 | 
         
            +
            from transformers import AutoModel, AutoTokenizer
         
     | 
| 10 | 
         
            +
             
     | 
| 11 | 
         
            +
            # README, How to run demo on different devices
         
     | 
| 12 | 
         
            +
            # For Nvidia GPUs support BF16 (like A100, H100, RTX3090)
         
     | 
| 13 | 
         
            +
            # python web_demo.py --device cuda --dtype bf16
         
     | 
| 14 | 
         
            +
             
     | 
| 15 | 
         
            +
            # For Nvidia GPUs do NOT support BF16 (like V100, T4, RTX2080)
         
     | 
| 16 | 
         
            +
            # python web_demo.py --device cuda --dtype fp16
         
     | 
| 17 | 
         
            +
             
     | 
| 18 | 
         
            +
            # For Mac with MPS (Apple silicon or AMD GPUs).
         
     | 
| 19 | 
         
            +
            # PYTORCH_ENABLE_MPS_FALLBACK=1 python web_demo.py --device mps --dtype fp16
         
     | 
| 20 | 
         
            +
             
     | 
| 21 | 
         
            +
            # Argparser
         
     | 
| 22 | 
         
            +
            parser = argparse.ArgumentParser(description='demo')
         
     | 
| 23 | 
         
            +
            parser.add_argument('--device', type=str, default='cuda', help='cuda or mps')
         
     | 
| 24 | 
         
            +
            parser.add_argument('--dtype', type=str, default='bf16', help='bf16 or fp16')
         
     | 
| 25 | 
         
            +
            args = parser.parse_args()
         
     | 
| 26 | 
         
            +
            device = args.device
         
     | 
| 27 | 
         
            +
            assert device in ['cuda', 'mps']
         
     | 
| 28 | 
         
            +
            if args.dtype == 'bf16':
         
     | 
| 29 | 
         
            +
                dtype = torch.bfloat16
         
     | 
| 30 | 
         
            +
            else:
         
     | 
| 31 | 
         
            +
                dtype = torch.float16
         
     | 
| 32 | 
         
            +
             
     | 
| 33 | 
         
            +
            # Load model
         
     | 
| 34 | 
         
            +
            model_path = 'openbmb/MiniCPM-V-2'
         
     | 
| 35 | 
         
            +
            model = AutoModel.from_pretrained(model_path, trust_remote_code=True).to(dtype=torch.bfloat16)
         
     | 
| 36 | 
         
            +
            tokenizer = AutoTokenizer.from_pretrained(model_path, trust_remote_code=True)
         
     | 
| 37 | 
         
            +
             
     | 
| 38 | 
         
            +
            model = model.to(device=device, dtype=dtype)
         
     | 
| 39 | 
         
            +
            model.eval()
         
     | 
| 40 | 
         
            +
             
     | 
| 41 | 
         
            +
             
     | 
| 42 | 
         
            +
             
     | 
| 43 | 
         
            +
            ERROR_MSG = "Error, please retry"
         
     | 
| 44 | 
         
            +
            model_name = 'MiniCPM-V 2.0'
         
     | 
| 45 | 
         
            +
             
     | 
| 46 | 
         
            +
            form_radio = {
         
     | 
| 47 | 
         
            +
                'choices': ['Beam Search', 'Sampling'],
         
     | 
| 48 | 
         
            +
                #'value': 'Beam Search',
         
     | 
| 49 | 
         
            +
                'value': 'Sampling',
         
     | 
| 50 | 
         
            +
                'interactive': True,
         
     | 
| 51 | 
         
            +
                'label': 'Decode Type'
         
     | 
| 52 | 
         
            +
            }
         
     | 
| 53 | 
         
            +
            # Beam Form
         
     | 
| 54 | 
         
            +
            num_beams_slider = {
         
     | 
| 55 | 
         
            +
                'minimum': 0,
         
     | 
| 56 | 
         
            +
                'maximum': 5,
         
     | 
| 57 | 
         
            +
                'value': 3,
         
     | 
| 58 | 
         
            +
                'step': 1,
         
     | 
| 59 | 
         
            +
                'interactive': True,
         
     | 
| 60 | 
         
            +
                'label': 'Num Beams'
         
     | 
| 61 | 
         
            +
            }
         
     | 
| 62 | 
         
            +
            repetition_penalty_slider = {
         
     | 
| 63 | 
         
            +
                'minimum': 0,
         
     | 
| 64 | 
         
            +
                'maximum': 3,
         
     | 
| 65 | 
         
            +
                'value': 1.2,
         
     | 
| 66 | 
         
            +
                'step': 0.01,
         
     | 
| 67 | 
         
            +
                'interactive': True,
         
     | 
| 68 | 
         
            +
                'label': 'Repetition Penalty'
         
     | 
| 69 | 
         
            +
            }
         
     | 
| 70 | 
         
            +
            repetition_penalty_slider2 = {
         
     | 
| 71 | 
         
            +
                'minimum': 0,
         
     | 
| 72 | 
         
            +
                'maximum': 3,
         
     | 
| 73 | 
         
            +
                'value': 1.05,
         
     | 
| 74 | 
         
            +
                'step': 0.01,
         
     | 
| 75 | 
         
            +
                'interactive': True,
         
     | 
| 76 | 
         
            +
                'label': 'Repetition Penalty'
         
     | 
| 77 | 
         
            +
            }
         
     | 
| 78 | 
         
            +
            max_new_tokens_slider = {
         
     | 
| 79 | 
         
            +
                'minimum': 1,
         
     | 
| 80 | 
         
            +
                'maximum': 4096,
         
     | 
| 81 | 
         
            +
                'value': 1024,
         
     | 
| 82 | 
         
            +
                'step': 1,
         
     | 
| 83 | 
         
            +
                'interactive': True,
         
     | 
| 84 | 
         
            +
                'label': 'Max New Tokens'    
         
     | 
| 85 | 
         
            +
            }
         
     | 
| 86 | 
         
            +
             
     | 
| 87 | 
         
            +
            top_p_slider = {
         
     | 
| 88 | 
         
            +
                'minimum': 0,
         
     | 
| 89 | 
         
            +
                'maximum': 1,
         
     | 
| 90 | 
         
            +
                'value': 0.8,
         
     | 
| 91 | 
         
            +
                'step': 0.05,
         
     | 
| 92 | 
         
            +
                'interactive': True,
         
     | 
| 93 | 
         
            +
                'label': 'Top P'    
         
     | 
| 94 | 
         
            +
            }
         
     | 
| 95 | 
         
            +
            top_k_slider = {
         
     | 
| 96 | 
         
            +
                'minimum': 0,
         
     | 
| 97 | 
         
            +
                'maximum': 200,
         
     | 
| 98 | 
         
            +
                'value': 100,
         
     | 
| 99 | 
         
            +
                'step': 1,
         
     | 
| 100 | 
         
            +
                'interactive': True,
         
     | 
| 101 | 
         
            +
                'label': 'Top K'    
         
     | 
| 102 | 
         
            +
            }
         
     | 
| 103 | 
         
            +
            temperature_slider = {
         
     | 
| 104 | 
         
            +
                'minimum': 0,
         
     | 
| 105 | 
         
            +
                'maximum': 2,
         
     | 
| 106 | 
         
            +
                'value': 0.7,
         
     | 
| 107 | 
         
            +
                'step': 0.05,
         
     | 
| 108 | 
         
            +
                'interactive': True,
         
     | 
| 109 | 
         
            +
                'label': 'Temperature'    
         
     | 
| 110 | 
         
            +
            }
         
     | 
| 111 | 
         
            +
             
     | 
| 112 | 
         
            +
             
     | 
| 113 | 
         
            +
            def create_component(params, comp='Slider'):
         
     | 
| 114 | 
         
            +
                if comp == 'Slider':
         
     | 
| 115 | 
         
            +
                    return gr.Slider(
         
     | 
| 116 | 
         
            +
                        minimum=params['minimum'],
         
     | 
| 117 | 
         
            +
                        maximum=params['maximum'],
         
     | 
| 118 | 
         
            +
                        value=params['value'],
         
     | 
| 119 | 
         
            +
                        step=params['step'],
         
     | 
| 120 | 
         
            +
                        interactive=params['interactive'],
         
     | 
| 121 | 
         
            +
                        label=params['label']
         
     | 
| 122 | 
         
            +
                    )
         
     | 
| 123 | 
         
            +
                elif comp == 'Radio':
         
     | 
| 124 | 
         
            +
                    return gr.Radio(
         
     | 
| 125 | 
         
            +
                        choices=params['choices'],
         
     | 
| 126 | 
         
            +
                        value=params['value'],
         
     | 
| 127 | 
         
            +
                        interactive=params['interactive'],
         
     | 
| 128 | 
         
            +
                        label=params['label']
         
     | 
| 129 | 
         
            +
                    )
         
     | 
| 130 | 
         
            +
                elif comp == 'Button':
         
     | 
| 131 | 
         
            +
                    return gr.Button(
         
     | 
| 132 | 
         
            +
                        value=params['value'],
         
     | 
| 133 | 
         
            +
                        interactive=True
         
     | 
| 134 | 
         
            +
                    )
         
     | 
| 135 | 
         
            +
             
     | 
| 136 | 
         
            +
             
     | 
| 137 | 
         
            +
            def chat(img, msgs, ctx, params=None, vision_hidden_states=None):
         
     | 
| 138 | 
         
            +
                default_params = {"num_beams":3, "repetition_penalty": 1.2, "max_new_tokens": 1024}
         
     | 
| 139 | 
         
            +
                if params is None:
         
     | 
| 140 | 
         
            +
                    params = default_params
         
     | 
| 141 | 
         
            +
                if img is None:
         
     | 
| 142 | 
         
            +
                    return -1, "Error, invalid image, please upload a new image", None, None
         
     | 
| 143 | 
         
            +
                try:
         
     | 
| 144 | 
         
            +
                    image = img.convert('RGB')
         
     | 
| 145 | 
         
            +
                    answer, context, _ = model.chat(
         
     | 
| 146 | 
         
            +
                        image=image,
         
     | 
| 147 | 
         
            +
                        msgs=msgs,
         
     | 
| 148 | 
         
            +
                        context=None,
         
     | 
| 149 | 
         
            +
                        tokenizer=tokenizer,
         
     | 
| 150 | 
         
            +
                        **params
         
     | 
| 151 | 
         
            +
                    )
         
     | 
| 152 | 
         
            +
                    res = re.sub(r'(<box>.*</box>)', '', answer)
         
     | 
| 153 | 
         
            +
                    res = res.replace('<ref>', '')
         
     | 
| 154 | 
         
            +
                    res = res.replace('</ref>', '')
         
     | 
| 155 | 
         
            +
                    res = res.replace('<box>', '')
         
     | 
| 156 | 
         
            +
                    answer = res.replace('</box>', '')
         
     | 
| 157 | 
         
            +
                    return -1, answer, None, None
         
     | 
| 158 | 
         
            +
                except Exception as err:
         
     | 
| 159 | 
         
            +
                    print(err)
         
     | 
| 160 | 
         
            +
                    traceback.print_exc()
         
     | 
| 161 | 
         
            +
                    return -1, ERROR_MSG, None, None
         
     | 
| 162 | 
         
            +
             
     | 
| 163 | 
         
            +
             
     | 
| 164 | 
         
            +
            def upload_img(image, _chatbot, _app_session):
         
     | 
| 165 | 
         
            +
                image = Image.fromarray(image)
         
     | 
| 166 | 
         
            +
             
     | 
| 167 | 
         
            +
                _app_session['sts']=None
         
     | 
| 168 | 
         
            +
                _app_session['ctx']=[]
         
     | 
| 169 | 
         
            +
                _app_session['img']=image 
         
     | 
| 170 | 
         
            +
                _chatbot.append(('', 'Image uploaded successfully, you can talk to me now'))
         
     | 
| 171 | 
         
            +
                return _chatbot, _app_session
         
     | 
| 172 | 
         
            +
             
     | 
| 173 | 
         
            +
             
     | 
| 174 | 
         
            +
            def respond(_question, _chat_bot, _app_cfg, params_form, num_beams, repetition_penalty, repetition_penalty_2, top_p, top_k, temperature):
         
     | 
| 175 | 
         
            +
                if _app_cfg.get('ctx', None) is None:
         
     | 
| 176 | 
         
            +
                    _chat_bot.append((_question, 'Please upload an image to start'))
         
     | 
| 177 | 
         
            +
                    return '', _chat_bot, _app_cfg
         
     | 
| 178 | 
         
            +
             
     | 
| 179 | 
         
            +
                _context = _app_cfg['ctx'].copy()
         
     | 
| 180 | 
         
            +
                if _context:
         
     | 
| 181 | 
         
            +
                    _context.append({"role": "user", "content": _question})
         
     | 
| 182 | 
         
            +
                else:
         
     | 
| 183 | 
         
            +
                    _context = [{"role": "user", "content": _question}] 
         
     | 
| 184 | 
         
            +
                print('<User>:', _question)
         
     | 
| 185 | 
         
            +
             
     | 
| 186 | 
         
            +
                if params_form == 'Beam Search':
         
     | 
| 187 | 
         
            +
                    params = {
         
     | 
| 188 | 
         
            +
                        'sampling': False,
         
     | 
| 189 | 
         
            +
                        'num_beams': num_beams,
         
     | 
| 190 | 
         
            +
                        'repetition_penalty': repetition_penalty,
         
     | 
| 191 | 
         
            +
                        "max_new_tokens": 896 
         
     | 
| 192 | 
         
            +
                    }
         
     | 
| 193 | 
         
            +
                else:
         
     | 
| 194 | 
         
            +
                    params = {
         
     | 
| 195 | 
         
            +
                        'sampling': True,
         
     | 
| 196 | 
         
            +
                        'top_p': top_p,
         
     | 
| 197 | 
         
            +
                        'top_k': top_k,
         
     | 
| 198 | 
         
            +
                        'temperature': temperature,
         
     | 
| 199 | 
         
            +
                        'repetition_penalty': repetition_penalty_2,
         
     | 
| 200 | 
         
            +
                        "max_new_tokens": 896 
         
     | 
| 201 | 
         
            +
                    }
         
     | 
| 202 | 
         
            +
                code, _answer, _, sts = chat(_app_cfg['img'], _context, None, params)
         
     | 
| 203 | 
         
            +
                print('<Assistant>:', _answer)
         
     | 
| 204 | 
         
            +
             
     | 
| 205 | 
         
            +
                _context.append({"role": "assistant", "content": _answer}) 
         
     | 
| 206 | 
         
            +
                _chat_bot.append((_question, _answer))
         
     | 
| 207 | 
         
            +
                if code == 0:
         
     | 
| 208 | 
         
            +
                    _app_cfg['ctx']=_context
         
     | 
| 209 | 
         
            +
                    _app_cfg['sts']=sts
         
     | 
| 210 | 
         
            +
                return '', _chat_bot, _app_cfg
         
     | 
| 211 | 
         
            +
             
     | 
| 212 | 
         
            +
             
     | 
| 213 | 
         
            +
            def regenerate_button_clicked(_question, _chat_bot, _app_cfg, params_form, num_beams, repetition_penalty, repetition_penalty_2, top_p, top_k, temperature):
         
     | 
| 214 | 
         
            +
                if len(_chat_bot) <= 1:
         
     | 
| 215 | 
         
            +
                    _chat_bot.append(('Regenerate', 'No question for regeneration.'))
         
     | 
| 216 | 
         
            +
                    return '', _chat_bot, _app_cfg
         
     | 
| 217 | 
         
            +
                elif _chat_bot[-1][0] == 'Regenerate':
         
     | 
| 218 | 
         
            +
                    return '', _chat_bot, _app_cfg
         
     | 
| 219 | 
         
            +
                else:
         
     | 
| 220 | 
         
            +
                    _question = _chat_bot[-1][0]
         
     | 
| 221 | 
         
            +
                    _chat_bot = _chat_bot[:-1]
         
     | 
| 222 | 
         
            +
                    _app_cfg['ctx'] = _app_cfg['ctx'][:-2]
         
     | 
| 223 | 
         
            +
                return respond(_question, _chat_bot, _app_cfg, params_form, num_beams, repetition_penalty, repetition_penalty_2, top_p, top_k, temperature)
         
     | 
| 224 | 
         
            +
             
     | 
| 225 | 
         
            +
             
     | 
| 226 | 
         
            +
             
     | 
| 227 | 
         
            +
            with gr.Blocks() as demo:
         
     | 
| 228 | 
         
            +
                with gr.Row():
         
     | 
| 229 | 
         
            +
                    with gr.Column(scale=1, min_width=300):
         
     | 
| 230 | 
         
            +
                        params_form = create_component(form_radio, comp='Radio')
         
     | 
| 231 | 
         
            +
                        with gr.Accordion("Beam Search") as beams_according:
         
     | 
| 232 | 
         
            +
                            num_beams = create_component(num_beams_slider)
         
     | 
| 233 | 
         
            +
                            repetition_penalty = create_component(repetition_penalty_slider)
         
     | 
| 234 | 
         
            +
                        with gr.Accordion("Sampling") as sampling_according:
         
     | 
| 235 | 
         
            +
                            top_p = create_component(top_p_slider)
         
     | 
| 236 | 
         
            +
                            top_k = create_component(top_k_slider)
         
     | 
| 237 | 
         
            +
                            temperature = create_component(temperature_slider)
         
     | 
| 238 | 
         
            +
                            repetition_penalty_2 = create_component(repetition_penalty_slider2)
         
     | 
| 239 | 
         
            +
                        regenerate = create_component({'value': 'Regenerate'}, comp='Button')
         
     | 
| 240 | 
         
            +
                    with gr.Column(scale=3, min_width=500):
         
     | 
| 241 | 
         
            +
                        app_session = gr.State({'sts':None,'ctx':None,'img':None})
         
     | 
| 242 | 
         
            +
                        bt_pic = gr.Image(label="Upload an image to start")
         
     | 
| 243 | 
         
            +
                        chat_bot = gr.Chatbot(label=f"Chat with {model_name}")
         
     | 
| 244 | 
         
            +
                        txt_message = gr.Textbox(label="Input text")
         
     | 
| 245 | 
         
            +
                        
         
     | 
| 246 | 
         
            +
                        regenerate.click(
         
     | 
| 247 | 
         
            +
                            regenerate_button_clicked,
         
     | 
| 248 | 
         
            +
                            [txt_message, chat_bot, app_session, params_form, num_beams, repetition_penalty, repetition_penalty_2, top_p, top_k, temperature],
         
     | 
| 249 | 
         
            +
                            [txt_message, chat_bot, app_session]
         
     | 
| 250 | 
         
            +
                        )
         
     | 
| 251 | 
         
            +
                        txt_message.submit(
         
     | 
| 252 | 
         
            +
                            respond, 
         
     | 
| 253 | 
         
            +
                            [txt_message, chat_bot, app_session, params_form, num_beams, repetition_penalty, repetition_penalty_2, top_p, top_k, temperature], 
         
     | 
| 254 | 
         
            +
                            [txt_message, chat_bot, app_session]
         
     | 
| 255 | 
         
            +
                        )
         
     | 
| 256 | 
         
            +
                        bt_pic.upload(lambda: None, None, chat_bot, queue=False).then(upload_img, inputs=[bt_pic,chat_bot,app_session], outputs=[chat_bot,app_session])
         
     | 
| 257 | 
         
            +
             
     | 
| 258 | 
         
            +
            # launch
         
     | 
| 259 | 
         
            +
            demo.launch(share=False, debug=True, show_api=False, server_port=8080, server_name="0.0.0.0")
         
     | 
| 260 | 
         
            +
             
     |