xxx1 commited on
Commit
5b067c5
1 Parent(s): 023fc36

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -3
app.py CHANGED
@@ -24,17 +24,20 @@ def caption(input_image):
24
  inputs['num_return_sequences'] =4
25
  out = model.generate(**inputs)
26
  return "\n".join(processor.decode(out[0], skip_special_tokens=True))
27
- def gpt3(input_text):
 
 
 
28
  response = openai.Completion.create(
29
  engine="text-davinci-003",
30
- prompt=input_text,
31
  max_tokens=10,
32
  n=1,
33
  stop=None,
34
  temperature=0.7,
35
  )
36
  answer = response.choices[0].text.strip()
37
- return answer
38
 
39
 
40
  def inference_chat(input_image,input_text):
@@ -71,9 +74,13 @@ with gr.Blocks(
71
  cap_submit_button = gr.Button(
72
  value="Submit", interactive=True, variant="primary"
73
  )
 
 
 
74
  with gr.Column():
75
  caption_output = gr.Textbox(lines=0, label="VQA Output(模型答案输出)")
76
  caption_output_v1 = gr.Textbox(lines=0, label="Caption Output(模型caption输出)")
 
77
 
78
  image_input.change(
79
  lambda: ("", "", []),
@@ -111,6 +118,15 @@ with gr.Blocks(
111
  ],
112
  [caption_output_v1],
113
  )
 
 
 
 
 
 
 
 
 
114
 
115
  # examples = gr.Examples(
116
  # examples=examples,
 
24
  inputs['num_return_sequences'] =4
25
  out = model.generate(**inputs)
26
  return "\n".join(processor.decode(out[0], skip_special_tokens=True))
27
+ import openai
28
+ openai.api_key=openai_appkey
29
+ def gpt3(question,vqa_answer,caption):
30
+ prompt=caption+"\n"+question+"\n"+vqa_answer+"\n Tell me the right answer."
31
  response = openai.Completion.create(
32
  engine="text-davinci-003",
33
+ prompt=prompt,
34
  max_tokens=10,
35
  n=1,
36
  stop=None,
37
  temperature=0.7,
38
  )
39
  answer = response.choices[0].text.strip()
40
+ return "input_text:\n"+prompt+"\n\n output_answer:\n"+answer
41
 
42
 
43
  def inference_chat(input_image,input_text):
 
74
  cap_submit_button = gr.Button(
75
  value="Submit", interactive=True, variant="primary"
76
  )
77
+ gpt3_submit_button = gr.Button(
78
+ value="Submit", interactive=True, variant="primary"
79
+ )
80
  with gr.Column():
81
  caption_output = gr.Textbox(lines=0, label="VQA Output(模型答案输出)")
82
  caption_output_v1 = gr.Textbox(lines=0, label="Caption Output(模型caption输出)")
83
+ gpt3_output_v1 = gr.Textbox(lines=0, label="GPT3 Output(模型caption输出)")
84
 
85
  image_input.change(
86
  lambda: ("", "", []),
 
118
  ],
119
  [caption_output_v1],
120
  )
121
+ gpt3_submit_button.click(
122
+ gpt3,
123
+ [
124
+ chat_input,
125
+ caption_output ,
126
+ caption_output_v1,
127
+ ],
128
+ [gpt3_output_v1],
129
+ )
130
 
131
  # examples = gr.Examples(
132
  # examples=examples,