Update app.py
Browse files
    	
        app.py
    CHANGED
    
    | 
         @@ -11,7 +11,7 @@ model_id = 'J-LAB/Florence_2_B_FluxiAI_Product_Caption' 
     | 
|
| 11 | 
         
             
            model = AutoModelForCausalLM.from_pretrained(model_id, trust_remote_code=True).to("cuda").eval()
         
     | 
| 12 | 
         
             
            processor = AutoProcessor.from_pretrained(model_id, trust_remote_code=True)
         
     | 
| 13 | 
         | 
| 14 | 
         
            -
            DESCRIPTION = "# 
     | 
| 15 | 
         | 
| 16 | 
         
             
            @spaces.GPU
         
     | 
| 17 | 
         
             
            def run_example(task_prompt, image):
         
     | 
| 
         @@ -61,14 +61,31 @@ css = """ 
     | 
|
| 61 | 
         | 
| 62 | 
         
             
            with gr.Blocks(css=css) as demo:
         
     | 
| 63 | 
         
             
                gr.Markdown(DESCRIPTION)
         
     | 
| 64 | 
         
            -
                with gr.Tab(label=" 
     | 
| 65 | 
         
             
                    with gr.Row():
         
     | 
| 66 | 
         
             
                        with gr.Column():
         
     | 
| 67 | 
         
             
                            input_img = gr.Image(label="Input Picture")
         
     | 
| 68 | 
         
             
                            submit_btn = gr.Button(value="Submit")
         
     | 
| 69 | 
         
             
                        with gr.Column():
         
     | 
| 70 | 
         
             
                            output_text = gr.HTML(label="Output Text", elem_id="output")
         
     | 
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 71 | 
         | 
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 72 | 
         
             
                    submit_btn.click(process_image, [input_img], [output_text])
         
     | 
| 73 | 
         | 
| 74 | 
         
             
            demo.launch(debug=True)
         
     | 
| 
         | 
|
| 11 | 
         
             
            model = AutoModelForCausalLM.from_pretrained(model_id, trust_remote_code=True).to("cuda").eval()
         
     | 
| 12 | 
         
             
            processor = AutoProcessor.from_pretrained(model_id, trust_remote_code=True)
         
     | 
| 13 | 
         | 
| 14 | 
         
            +
            DESCRIPTION = "#Product Describe by Fluxi IA\n### Base Model [Florence-2] (https://huggingface.co/microsoft/Florence-2-large) ]"
         
     | 
| 15 | 
         | 
| 16 | 
         
             
            @spaces.GPU
         
     | 
| 17 | 
         
             
            def run_example(task_prompt, image):
         
     | 
| 
         | 
|
| 61 | 
         | 
| 62 | 
         
             
            with gr.Blocks(css=css) as demo:
         
     | 
| 63 | 
         
             
                gr.Markdown(DESCRIPTION)
         
     | 
| 64 | 
         
            +
                with gr.Tab(label="Product Image Select"):
         
     | 
| 65 | 
         
             
                    with gr.Row():
         
     | 
| 66 | 
         
             
                        with gr.Column():
         
     | 
| 67 | 
         
             
                            input_img = gr.Image(label="Input Picture")
         
     | 
| 68 | 
         
             
                            submit_btn = gr.Button(value="Submit")
         
     | 
| 69 | 
         
             
                        with gr.Column():
         
     | 
| 70 | 
         
             
                            output_text = gr.HTML(label="Output Text", elem_id="output")
         
     | 
| 71 | 
         
            +
                    
         
     | 
| 72 | 
         
            +
                    gr.Markdown("""
         
     | 
| 73 | 
         
            +
                    ## How to use via API
         
     | 
| 74 | 
         
            +
                    To use this model via API, you can follow the example code below:
         
     | 
| 75 | 
         | 
| 76 | 
         
            +
                    ```python
         
     | 
| 77 | 
         
            +
                    !pip install gradio_client
         
     | 
| 78 | 
         
            +
                    from gradio_client import Client, handle_file
         
     | 
| 79 | 
         
            +
             
     | 
| 80 | 
         
            +
                    client = Client("J-LAB/Fluxi-IA")
         
     | 
| 81 | 
         
            +
                    result = client.predict(
         
     | 
| 82 | 
         
            +
                        image=handle_file('https://raw.githubusercontent.com/gradio-app/gradio/main/test/test_files/bus.png'),
         
     | 
| 83 | 
         
            +
                        api_name="/process_image"
         
     | 
| 84 | 
         
            +
                    )
         
     | 
| 85 | 
         
            +
                    print(result)
         
     | 
| 86 | 
         
            +
                    ```
         
     | 
| 87 | 
         
            +
                    """)
         
     | 
| 88 | 
         
            +
                    
         
     | 
| 89 | 
         
             
                    submit_btn.click(process_image, [input_img], [output_text])
         
     | 
| 90 | 
         | 
| 91 | 
         
             
            demo.launch(debug=True)
         
     |