keithhon commited on
Commit
592a383
1 Parent(s): 2604528

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +32 -0
app.py ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import requests
2
+ import json
3
+ import gradio as gr
4
+
5
+
6
+ url = "https://demo-cas.jina.ai:8443/post"
7
+ headers = {
8
+ 'Content-Type': 'application/json'
9
+ }
10
+
11
+ def rank(uri, options):
12
+ matches = []
13
+ for option in options
14
+ matches.append({"text": option})
15
+ payload = json.dumps({
16
+ "data": [
17
+ {
18
+ "uri": uri,
19
+ "matches": matches
20
+ }
21
+ ],
22
+ "execEndpoint": "/rank"
23
+ })
24
+
25
+ response = requests.request("POST", url, headers=headers, data=payload)
26
+
27
+ return response.text
28
+
29
+ examples = [["https://picsum.photos/id/102/300/300", "three berry, four berries, ten berries"]]
30
+ iface = gr.Interface(fn=rank, inputs=["text", "text"], outputs="text", examples=examples)
31
+ iface.launch()
32
+