yanka commited on
Commit
89afb80
·
1 Parent(s): f8c859a
Files changed (1) hide show
  1. app.py +13 -8
app.py CHANGED
@@ -1,16 +1,21 @@
1
  import gradio as gr
2
- import numpy as np
 
3
 
4
  TITLE = 'FaVQA - Fashion-related Visual Question Answering'
5
  DESCRIPTION = 'Fine-tuned ViLT with DeepFashion dataset images for VQA task'
6
- IMG_EX = np.zeros((100, 100), dtype=np.uint8)
7
  ARTICLE = 'COLOCAR DESCRIÇÃO AQUI MONA'
8
 
9
 
10
  ##########################################################
11
  # WRAPPER FUNCTION
12
  ##########################################################
 
 
 
 
13
 
 
14
 
15
  ##########################################################
16
  # COMPONENTS
@@ -22,27 +27,27 @@ txt_input = gr.Textbox(
22
  )
23
 
24
  img_input = gr.Image(
25
- value=IMG_EX,
26
- sources=['upload', 'clipboard']
27
  )
28
 
29
- txt_output = gr.Textbox(
30
- max_lines=2,
31
  label='Answer',
 
32
  )
33
 
34
  ##########################################################
35
  # BUILDER
36
  ##########################################################
37
  demo = gr.Interface(
38
- fn=gr.load('models/yanka9/vilt_finetuned_deepfashionVQA_v2'),
39
  title=TITLE,
40
  description=DESCRIPTION,
41
  article=ARTICLE,
42
  theme='gradio/monochrome',
43
  allow_flagging='never',
44
  inputs=[txt_input, img_input],
45
- outputs=txt_output
46
  )
47
 
48
  demo.launch()
 
1
  import gradio as gr
2
+ from transformers import pipeline
3
+
4
 
5
  TITLE = 'FaVQA - Fashion-related Visual Question Answering'
6
  DESCRIPTION = 'Fine-tuned ViLT with DeepFashion dataset images for VQA task'
 
7
  ARTICLE = 'COLOCAR DESCRIÇÃO AQUI MONA'
8
 
9
 
10
  ##########################################################
11
  # WRAPPER FUNCTION
12
  ##########################################################
13
+ def predict(txt, img):
14
+ pipe = pipeline(model='yanka9/vilt_finetuned_deepfashionVQA_v2')
15
+ output = pipe(image=img, question=txt, top_k=2)
16
+ result = {item['answer']:item['score'] for item in output}
17
 
18
+ return result
19
 
20
  ##########################################################
21
  # COMPONENTS
 
27
  )
28
 
29
  img_input = gr.Image(
30
+ sources=['upload', 'clipboard'],
31
+ type='pil'
32
  )
33
 
34
+ label_output = gr.Label(
 
35
  label='Answer',
36
+ num_top_classes=2
37
  )
38
 
39
  ##########################################################
40
  # BUILDER
41
  ##########################################################
42
  demo = gr.Interface(
43
+ fn=predict,
44
  title=TITLE,
45
  description=DESCRIPTION,
46
  article=ARTICLE,
47
  theme='gradio/monochrome',
48
  allow_flagging='never',
49
  inputs=[txt_input, img_input],
50
+ outputs=label_output
51
  )
52
 
53
  demo.launch()