Fangyu Liu commited on
Commit
6dc09e2
1 Parent(s): 7eb1431

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -6
app.py CHANGED
@@ -156,26 +156,36 @@ def process_document(image, question):
156
  # image = Image.open(image)
157
  inputs = processor_deplot(images=image, text="Generate the underlying data table for the figure below:", return_tensors="pt")
158
  predictions = model_deplot.generate(**inputs, max_new_tokens=512)
159
- table = processor_deplot.decode(predictions[0], skip_special_tokens=True)
160
 
161
  # send prompt+table to LLM
162
- res = evaluate(table.replace("<0x0A>", "\n"), question)
163
  #return res + "\n\n" + res.split("A:")[-1]
164
- return res.split("A:")[-1]
165
 
166
- description = "Demo for deplot+llm for QA or summarisation. To use it, simply upload your image and type a question and click 'submit', or click one of the examples to load them. Read more at the links below."
167
  article = "<p style='text-align: center'><a href='https://arxiv.org/abs/2212.10505' target='_blank'>DePlot: One-shot visual language reasoning by plot-to-table translation</a></p>"
168
 
169
  demo = gr.Interface(
170
  fn=process_document,
171
  inputs=["image", "text"],
172
  outputs="text",
173
- title="Demo: deplot+llm test",
174
  description=description,
 
 
 
 
 
 
 
 
 
 
175
  article=article,
176
  enable_queue=True,
177
  examples=[["deplot_case_study_m1.png", "What is the sum of numbers of Indonesia and Ireland? Remember to think step by step."],
178
- ["deplot_case_study_x2.png", "By how much does the number increase from 2006 to 2011? Remember to think step by step."]],
179
  cache_examples=False)
180
 
181
  demo.launch()
 
156
  # image = Image.open(image)
157
  inputs = processor_deplot(images=image, text="Generate the underlying data table for the figure below:", return_tensors="pt")
158
  predictions = model_deplot.generate(**inputs, max_new_tokens=512)
159
+ table = processor_deplot.decode(predictions[0], skip_special_tokens=True).replace("<0x0A>", "\n")
160
 
161
  # send prompt+table to LLM
162
+ res = evaluate(table, question)
163
  #return res + "\n\n" + res.split("A:")[-1]
164
+ return [table, res.split("A:")[-1]]
165
 
166
+ description = "Demo for DePlot+LLM for QA and summarisation. To use it, simply upload your image and type a question or instruction and click 'submit', or click one of the examples to load them. Read more at the links below."
167
  article = "<p style='text-align: center'><a href='https://arxiv.org/abs/2212.10505' target='_blank'>DePlot: One-shot visual language reasoning by plot-to-table translation</a></p>"
168
 
169
  demo = gr.Interface(
170
  fn=process_document,
171
  inputs=["image", "text"],
172
  outputs="text",
173
+ title="DePlot+LLM (Multimodal chain-of-thought reasoning on plots)",
174
  description=description,
175
+ outputs=[
176
+ gr.inputs.Textbox(
177
+ lines=8,
178
+ label="Intermediate Table",
179
+ ),
180
+ gr.inputs.Textbox(
181
+ lines=5,
182
+ label="Output",
183
+ )
184
+ ],
185
  article=article,
186
  enable_queue=True,
187
  examples=[["deplot_case_study_m1.png", "What is the sum of numbers of Indonesia and Ireland? Remember to think step by step."],
188
+ ["deplot_case_study_x2.png", "Summarise the chart for me please."]],
189
  cache_examples=False)
190
 
191
  demo.launch()