Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from paddlenlp import Taskflow
|
3 |
+
import json
|
4 |
+
import numpy as np
|
5 |
+
import requests
|
6 |
+
import urllib
|
7 |
+
from io import BytesIO
|
8 |
+
from PIL import Image
|
9 |
+
|
10 |
+
vision_language=Taskflow("feature_extraction", model='PaddlePaddle/ernie_vil-2.0-base-zh')
|
11 |
+
|
12 |
+
def getImageTestFeture(content):
|
13 |
+
if content.startswith("http"):
|
14 |
+
response = requests.get(content)
|
15 |
+
x=BytesIO(response.content)
|
16 |
+
f_embeds = vision_language(Image.open(x))
|
17 |
+
else:
|
18 |
+
f_embeds = vision_language(content)
|
19 |
+
text_features = f_embeds["features"][0]
|
20 |
+
text_features=text_features.tolist()
|
21 |
+
return text_features
|
22 |
+
|
23 |
+
def greet(name):
|
24 |
+
x=getImageTestFeture(name)
|
25 |
+
return x
|
26 |
+
|
27 |
+
demo = gr.Interface(fn=greet, inputs="text", outputs="text")
|
28 |
+
|
29 |
+
if __name__ == "__main__":
|
30 |
+
demo.launch()
|