File size: 672 Bytes
1de29c7
7bfed32
 
 
6ba43a7
1de29c7
7bfed32
 
 
ad4cf3d
6ba43a7
1de29c7
 
7bfed32
ad4cf3d
2e36404
8bd6ba4
46e7008
1de29c7
ad4cf3d
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import os, threading
import gradio as gr
from transformers import pipeline

lock = threading.Lock()

pipe = pipeline("image-to-text",
                model="Salesforce/blip-image-captioning-base")

def exec(input):
    with lock:
        out = pipe(input)
        return out[0]["generated_text"]

demo = gr.Interface(exec,
                    inputs=gr.Image(type="pil",
                                    value="https://raw.githubusercontent.com/bstraehle/ai-ml-dl/main/hugging-face/hugging-face/beach.jpg"),
                    outputs=[gr.Textbox(label = "output", value=os.environ["OUTPUT"])],
                    description=os.environ["DESCRIPTION"])

demo.launch()