fl399 commited on
Commit
e9ecd38
1 Parent(s): 9421dc1

Update app.py

Browse files

modiy '_add_markup': use the raw table if parsing fails

Files changed (1) hide show
  1. app.py +14 -11
app.py CHANGED
@@ -10,15 +10,19 @@ from peft import PeftModel
10
  ## CoT prompts
11
 
12
  def _add_markup(table):
13
- parts = [p.strip() for p in table.splitlines(keepends=False)]
14
- if parts[0].startswith('TITLE'):
15
- result = f"Title: {parts[0].split(' | ')[1].strip()}\n"
16
- rows = parts[1:]
17
- else:
18
- result = ''
19
- rows = parts
20
- prefixes = ['Header: '] + [f'Row {i+1}: ' for i in range(len(rows) - 1)]
21
- return result + '\n'.join(prefix + row for prefix, row in zip(prefixes, rows))
 
 
 
 
22
 
23
 
24
  _TABLE = """Year | Democrats | Republicans | Independents
@@ -267,5 +271,4 @@ with gr.Blocks(theme=theme) as demo:
267
  process_document, inputs=[input_image, instruction, llm], outputs=[output_table, output_text]
268
  )
269
 
270
- demo.queue()
271
- demo.launch()
 
10
  ## CoT prompts
11
 
12
  def _add_markup(table):
13
+ try:
14
+ parts = [p.strip() for p in table.splitlines(keepends=False)]
15
+ if parts[0].startswith('TITLE'):
16
+ result = f"Title: {parts[0].split(' | ')[1].strip()}\n"
17
+ rows = parts[1:]
18
+ else:
19
+ result = ''
20
+ rows = parts
21
+ prefixes = ['Header: '] + [f'Row {i+1}: ' for i in range(len(rows) - 1)]
22
+ return result + '\n'.join(prefix + row for prefix, row in zip(prefixes, rows))
23
+ except:
24
+ # just use the raw table if parsing fails
25
+ return table
26
 
27
 
28
  _TABLE = """Year | Democrats | Republicans | Independents
 
271
  process_document, inputs=[input_image, instruction, llm], outputs=[output_table, output_text]
272
  )
273
 
274
+ demo.queue(concurrency_count=1).launch()