Netrava commited on
Commit
f9ea44f
Β·
verified Β·
1 Parent(s): 9e6864d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -14
app.py CHANGED
@@ -5,32 +5,30 @@ import json
5
  import torch
6
 
7
  # This part is correct and finds the project files.
8
- # We don't need the complex importlib anymore as we have fixed all dependencies.
9
  sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
10
 
 
11
 
12
- # --- START OF THE FINAL CORRECTED INITIALIZATION ---
13
-
14
- # 1. Import the necessary class AND the special config helper function.
15
  from util.omniparser import Omniparser
16
- from util.utils import get_config
 
 
17
 
18
- # 2. Define the model name.
19
- model_name = "omniparser-v2-effnet"
 
20
 
21
- # 3. Call the helper function to create the required config dictionary.
22
- print(f"Generating configuration for model: {model_name}...")
23
- config = get_config(model_name)
24
- print("βœ… Configuration generated.")
25
 
26
  # 4. Pass the CONFIG DICTIONARY to the class constructor.
27
- print("Initializing model with config...")
28
  parser_instance = Omniparser(config)
29
  print("βœ… OmniParser model loaded successfully.")
30
 
31
  # --- END OF THE FINAL CORRECTED INITIALIZATION ---
32
 
33
-
34
  def parse_document(input_file):
35
  if input_file is None: return "Please upload a document.", "{}"
36
  print(f"Processing file: {input_file.name}")
@@ -52,7 +50,7 @@ iface = gr.Interface(
52
  gr.Code(label="Full JSON Output", language="json")
53
  ],
54
  title="Microsoft OmniParser Demo",
55
- description="A working deployment of the OmniParser model."
56
  )
57
  iface.launch()
58
  print("--- Gradio UI launched ---")
 
5
  import torch
6
 
7
  # This part is correct and finds the project files.
 
8
  sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
9
 
10
+ # --- START OF THE FINAL CORRECTED INITIALIZATION (Based on official demo) ---
11
 
12
+ # 1. Import the correct class and helper objects from the project's own files.
 
 
13
  from util.omniparser import Omniparser
14
+ from util.utils import VLP_MODEL_CONFIG, get_model_path
15
+
16
+ print("Initializing...")
17
 
18
+ # 2. Use the helper function to get the full model path/key.
19
+ model_name_key = get_model_path("omniparser-v2-effnet")
20
+ print(f"Resolved model name to key: {model_name_key}")
21
 
22
+ # 3. Get the correct configuration dictionary from the VLP_MODEL_CONFIG constant.
23
+ config = VLP_MODEL_CONFIG[model_name_key]
24
+ print("βœ… Configuration dictionary loaded successfully.")
 
25
 
26
  # 4. Pass the CONFIG DICTIONARY to the class constructor.
 
27
  parser_instance = Omniparser(config)
28
  print("βœ… OmniParser model loaded successfully.")
29
 
30
  # --- END OF THE FINAL CORRECTED INITIALIZATION ---
31
 
 
32
  def parse_document(input_file):
33
  if input_file is None: return "Please upload a document.", "{}"
34
  print(f"Processing file: {input_file.name}")
 
50
  gr.Code(label="Full JSON Output", language="json")
51
  ],
52
  title="Microsoft OmniParser Demo",
53
+ description="This deployment is now fully functional."
54
  )
55
  iface.launch()
56
  print("--- Gradio UI launched ---")