lwdragon commited on
Commit
658194c
1 Parent(s): aa849b5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -15
app.py CHANGED
@@ -2,39 +2,29 @@ import os
2
  import requests
3
  import gradio as gr
4
 
5
- from utils import get_token
6
-
7
  url_caption = os.environ["CAPTION_NODE"]
8
  url_vqa = os.environ["VQA_NODE"]
9
 
10
 
11
  def image_caption(file_path):
12
- token = get_token()
13
-
14
- files = {"file": open(file_path, "rb")}
15
- headers = {"X-Auth-Token": token}
16
  resp = requests.post(url_caption,
17
  files=files,
18
- headers=headers,
19
  verify=False)
20
  resp = resp.json()
21
- desc = resp["inference_result"]["instances"]["image"][0]
22
  return desc
23
 
24
 
25
  def vqa(file_path, question):
26
- token = get_token()
27
-
28
- files = {"file": open(file_path, "rb")}
29
  question = {"question": question}
30
- headers = {"X-Auth-Token": token}
31
  resp = requests.post(url_vqa,
32
  files=files,
33
  data=question,
34
- headers=headers,
35
  verify=False)
36
  resp = resp.json()
37
- ans = resp["inference_result"]["instances"]
38
  return ans
39
 
40
 
@@ -63,7 +53,6 @@ examples_vqa = [
63
 
64
  css = """
65
  .gradio-container {background-image: url('file=./background.jpg'); background-size:cover; background-repeat: no-repeat;}
66
-
67
  #infer {
68
  background: linear-gradient(to bottom right, #FFD8B4, #FFB066);
69
  border: 1px solid #ffd8b4;
 
2
  import requests
3
  import gradio as gr
4
 
 
 
5
  url_caption = os.environ["CAPTION_NODE"]
6
  url_vqa = os.environ["VQA_NODE"]
7
 
8
 
9
  def image_caption(file_path):
10
+ files = {"picture": open(file_path, "rb")}
 
 
 
11
  resp = requests.post(url_caption,
12
  files=files,
 
13
  verify=False)
14
  resp = resp.json()
15
+ desc = resp["data"]["desc"]
16
  return desc
17
 
18
 
19
  def vqa(file_path, question):
20
+ files = {"picture": open(file_path, "rb")}
 
 
21
  question = {"question": question}
 
22
  resp = requests.post(url_vqa,
23
  files=files,
24
  data=question,
 
25
  verify=False)
26
  resp = resp.json()
27
+ ans = resp["data"]["answer"]
28
  return ans
29
 
30
 
 
53
 
54
  css = """
55
  .gradio-container {background-image: url('file=./background.jpg'); background-size:cover; background-repeat: no-repeat;}
 
56
  #infer {
57
  background: linear-gradient(to bottom right, #FFD8B4, #FFB066);
58
  border: 1px solid #ffd8b4;