Update app.py
Browse files
    	
        app.py
    CHANGED
    
    | @@ -127,23 +127,6 @@ def instruct_generate( | |
| 127 | 
             
                return result
         | 
| 128 |  | 
| 129 |  | 
| 130 | 
            -
            def caption_generate(
         | 
| 131 | 
            -
                img: str,
         | 
| 132 | 
            -
                max_gen_len=512,
         | 
| 133 | 
            -
                temperature: float = 0.1,
         | 
| 134 | 
            -
                top_p: float = 0.75,
         | 
| 135 | 
            -
            ):
         | 
| 136 | 
            -
                imgs = [Image.open(img).convert('RGB')]
         | 
| 137 | 
            -
                prompts = ["Generate caption of this image :",] * len(imgs)
         | 
| 138 | 
            -
             | 
| 139 | 
            -
                results = generator.generate(
         | 
| 140 | 
            -
                    prompts, imgs=imgs, max_gen_len=max_gen_len, temperature=temperature, top_p=top_p
         | 
| 141 | 
            -
                )
         | 
| 142 | 
            -
                result = results[0].strip()
         | 
| 143 | 
            -
                print(result)
         | 
| 144 | 
            -
                return result
         | 
| 145 | 
            -
             | 
| 146 | 
            -
             | 
| 147 | 
             
            def download_llama_adapter(instruct_adapter_path, caption_adapter_path):
         | 
| 148 | 
             
                if not os.path.exists(instruct_adapter_path):
         | 
| 149 | 
             
                    os.system(
         | 
| @@ -202,6 +185,26 @@ def create_instruct_demo(): | |
| 202 | 
             
                        with gr.Column():
         | 
| 203 | 
             
                            outputs = gr.Textbox(lines=10, label="Output")
         | 
| 204 |  | 
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
| 205 | 
             
                return instruct_demo
         | 
| 206 |  | 
| 207 |  | 
|  | |
| 127 | 
             
                return result
         | 
| 128 |  | 
| 129 |  | 
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
| 130 | 
             
            def download_llama_adapter(instruct_adapter_path, caption_adapter_path):
         | 
| 131 | 
             
                if not os.path.exists(instruct_adapter_path):
         | 
| 132 | 
             
                    os.system(
         | 
|  | |
| 185 | 
             
                        with gr.Column():
         | 
| 186 | 
             
                            outputs = gr.Textbox(lines=10, label="Output")
         | 
| 187 |  | 
| 188 | 
            +
                    inputs = [instruction, input, max_len, temp, top_p]
         | 
| 189 | 
            +
             | 
| 190 | 
            +
                    examples = [
         | 
| 191 | 
            +
                        "Tell me about alpacas.",
         | 
| 192 | 
            +
                        "Write a Python program that prints the first 10 Fibonacci numbers.",
         | 
| 193 | 
            +
                        "Write a conversation between the sun and pluto.",
         | 
| 194 | 
            +
                        "Write a theory to explain why cat never existed",
         | 
| 195 | 
            +
                    ]
         | 
| 196 | 
            +
                    examples = [
         | 
| 197 | 
            +
                        [x, "none", 128, 0.1, 0.75]
         | 
| 198 | 
            +
                        for x in examples]
         | 
| 199 | 
            +
             | 
| 200 | 
            +
                    gr.Examples(
         | 
| 201 | 
            +
                        examples=examples,
         | 
| 202 | 
            +
                        inputs=inputs,
         | 
| 203 | 
            +
                        outputs=outputs,
         | 
| 204 | 
            +
                        fn=instruct_generate,
         | 
| 205 | 
            +
                        cache_examples=os.getenv('SYSTEM') == 'spaces'
         | 
| 206 | 
            +
                    )
         | 
| 207 | 
            +
                    run_botton.click(fn=instruct_generate, inputs=inputs, outputs=outputs)
         | 
| 208 | 
             
                return instruct_demo
         | 
| 209 |  | 
| 210 |  |