|
import gradio as gr |
|
from paddlenlp import Taskflow |
|
from PIL import Image |
|
vision_language=Taskflow("feature_extraction", model='PaddlePaddle/ernie_vil-2.0-base-zh') |
|
|
|
def getImageTestFeture(content,flag): |
|
if flag==1: |
|
f_embeds = vision_language(Image.open(content)) |
|
else: |
|
f_embeds = vision_language(content) |
|
text_features = f_embeds["features"][0] |
|
text_features=text_features.tolist() |
|
return text_features |
|
|
|
|
|
def quickstart(name,fileinfo): |
|
pname=name |
|
flag=0 |
|
if not fileinfo is None: |
|
pname=fileinfo.name |
|
flag=1 |
|
xp=getImageTestFeture(pname,flag) |
|
return xp |
|
|
|
|
|
demo = gr.Interface(fn=quickstart, inputs=["text","file"], outputs="text") |
|
|
|
demo.launch() |
|
|