ankur-bohra commited on
Commit
6c36d86
·
1 Parent(s): ebab21a

Change JSON to DataFrame

Browse files
Files changed (1) hide show
  1. app.py +13 -3
app.py CHANGED
@@ -5,6 +5,7 @@ from io import BytesIO
5
  from pathlib import Path
6
 
7
  import gradio as gr
 
8
  from langchain.schema.output_parser import OutputParserException
9
  from PIL import Image
10
 
@@ -141,7 +142,9 @@ def parse(category, chatbot):
141
  chain = categories.category_modules[category].chain
142
  yield {"status": "Parsing response..."}
143
  try:
144
- information = chain.output_parser.parse(answer)
 
 
145
  information = information.json() if information else {}
146
  except OutputParserException as e:
147
  information = {
@@ -149,7 +152,7 @@ def parse(category, chatbot):
149
  "details": str(e),
150
  "output": e.llm_output,
151
  }
152
- yield information
153
 
154
 
155
  def activate_flags():
@@ -260,7 +263,14 @@ with gr.Blocks(title="Automatic Reimbursement Tool Demo") as page:
260
  interactive=False,
261
  height=240,
262
  )
263
- information = gr.JSON(label="Extracted information")
 
 
 
 
 
 
 
264
  with gr.Row():
265
  flag_incorrect_button = gr.Button(
266
  "Flag as incorrect", variant="stop", interactive=True
 
5
  from pathlib import Path
6
 
7
  import gradio as gr
8
+ import pandas as pd
9
  from langchain.schema.output_parser import OutputParserException
10
  from PIL import Image
11
 
 
142
  chain = categories.category_modules[category].chain
143
  yield {"status": "Parsing response..."}
144
  try:
145
+ information = chain.output_parser.parse(answer) or {
146
+ "Error": "No output"
147
+ }
148
  information = information.json() if information else {}
149
  except OutputParserException as e:
150
  information = {
 
152
  "details": str(e),
153
  "output": e.llm_output,
154
  }
155
+ yield pd.json_normalize(information)
156
 
157
 
158
  def activate_flags():
 
263
  interactive=False,
264
  height=240,
265
  )
266
+ information = gr.Dataframe(
267
+ pd.json_normalize({
268
+ "Waiting for input...": ''
269
+ }),
270
+ label="Extracted information",
271
+ interactive=False,
272
+ row_count = (1, "fixed"), # 1 till multiple inputs/outputs is implemented
273
+ )
274
  with gr.Row():
275
  flag_incorrect_button = gr.Button(
276
  "Flag as incorrect", variant="stop", interactive=True