YiHuan commited on
Commit
3b8da3f
1 Parent(s): d0986a9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -17
app.py CHANGED
@@ -1,30 +1,28 @@
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()
 
 
1
  import gradio as gr
2
  from paddlenlp import Taskflow
 
 
 
 
 
3
  from PIL import Image
 
4
  vision_language=Taskflow("feature_extraction", model='PaddlePaddle/ernie_vil-2.0-base-zh')
5
 
6
+ def getImageTestFeture(content,flag):
7
+ if flag==1:
8
+ f_embeds = vision_language(Image.open(content))
 
 
9
  else:
10
  f_embeds = vision_language(content)
11
  text_features = f_embeds["features"][0]
12
  text_features=text_features.tolist()
13
  return text_features
14
 
 
 
 
15
 
16
+ def quickstart(name,fileinfo):
17
+ pname=name
18
+ flag=0
19
+ if not fileinfo is None:
20
+ pname=fileinfo.name
21
+ flag=1
22
+ xp=getImageTestFeture(pname,flag)
23
+ return xp
24
+
25
 
26
+ demo = gr.Interface(fn=quickstart, inputs=["text","file"], outputs="text")
27
+
28
+ demo.launch()