heerjtdev commited on
Commit
ae075a3
Β·
verified Β·
1 Parent(s): 75487ef

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -6
app.py CHANGED
@@ -4,8 +4,21 @@ import os
4
  import tempfile
5
  from pathlib import Path
6
 
7
- # Import your pipeline function
 
8
  from working_yolo_pipeline import run_document_pipeline, DEFAULT_LAYOUTLMV3_MODEL_PATH, WEIGHTS_PATH
 
 
 
 
 
 
 
 
 
 
 
 
9
 
10
 
11
  def process_pdf(pdf_file, layoutlmv3_model_path=None):
@@ -47,16 +60,13 @@ def process_pdf(pdf_file, layoutlmv3_model_path=None):
47
  output_filename = f"{Path(pdf_path).stem}_analysis.json"
48
  temp_output = tempfile.NamedTemporaryFile(mode='w', delete=False, suffix='.json', prefix='analysis_')
49
 
 
50
  with open(temp_output.name, 'w', encoding='utf-8') as f:
51
  json.dump(result, f, indent=2, ensure_ascii=False)
52
 
53
  # Format JSON for display
54
  json_display = json.dumps(result, indent=2, ensure_ascii=False)
55
 
56
- # Truncate if too long for display
57
- # if len(json_display) > 50000:
58
- # json_display = json_display[:50000] + "\n\n... (truncated for display, download full file)"
59
-
60
  return json_display, temp_output.name
61
 
62
  except Exception as e:
@@ -64,7 +74,8 @@ def process_pdf(pdf_file, layoutlmv3_model_path=None):
64
 
65
 
66
  # Create Gradio interface
67
- with gr.Blocks(title="Document Analysis Pipeline", theme=gr.themes.Soft()) as demo:
 
68
  gr.Markdown("""
69
  # πŸ“„ Document Analysis Pipeline
70
 
 
4
  import tempfile
5
  from pathlib import Path
6
 
7
+ # NOTE: You must ensure that 'working_yolo_pipeline.py' exists
8
+ # and defines the following items correctly:
9
  from working_yolo_pipeline import run_document_pipeline, DEFAULT_LAYOUTLMV3_MODEL_PATH, WEIGHTS_PATH
10
+ # Since I don't have this file, I am assuming the imports are correct.
11
+
12
+ # Define placeholders for assumed constants if the pipeline file isn't present
13
+ # You should replace these with your actual definitions if they are missing
14
+ try:
15
+ from working_yolo_pipeline import run_document_pipeline, DEFAULT_LAYOUTLMV3_MODEL_PATH, WEIGHTS_PATH
16
+ except ImportError:
17
+ print("Warning: 'working_yolo_pipeline.py' not found. Using dummy paths.")
18
+ def run_document_pipeline(*args):
19
+ return {"error": "Placeholder pipeline function called."}
20
+ DEFAULT_LAYOUTLMV3_MODEL_PATH = "./models/layoutlmv3_model"
21
+ WEIGHTS_PATH = "./weights/yolo_weights.pt"
22
 
23
 
24
  def process_pdf(pdf_file, layoutlmv3_model_path=None):
 
60
  output_filename = f"{Path(pdf_path).stem}_analysis.json"
61
  temp_output = tempfile.NamedTemporaryFile(mode='w', delete=False, suffix='.json', prefix='analysis_')
62
 
63
+ # Dump results to the temporary file
64
  with open(temp_output.name, 'w', encoding='utf-8') as f:
65
  json.dump(result, f, indent=2, ensure_ascii=False)
66
 
67
  # Format JSON for display
68
  json_display = json.dumps(result, indent=2, ensure_ascii=False)
69
 
 
 
 
 
70
  return json_display, temp_output.name
71
 
72
  except Exception as e:
 
74
 
75
 
76
  # Create Gradio interface
77
+ # FIX APPLIED: Removed 'theme=gr.themes.Soft()' which caused the TypeError
78
+ with gr.Blocks(title="Document Analysis Pipeline") as demo:
79
  gr.Markdown("""
80
  # πŸ“„ Document Analysis Pipeline
81