Spaces:
Runtime error
Runtime error
Update app.py
Browse filesmodiy '_add_markup': use the raw table if parsing fails
app.py
CHANGED
@@ -10,15 +10,19 @@ from peft import PeftModel
|
|
10 |
## CoT prompts
|
11 |
|
12 |
def _add_markup(table):
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
|
|
|
|
|
|
|
|
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()
|
|