Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -3,28 +3,35 @@ import os
|
|
| 3 |
import gradio as gr
|
| 4 |
import json
|
| 5 |
import torch
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
#
|
| 24 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
|
| 26 |
# --- The rest of the application ---
|
| 27 |
-
print("Initializing...")
|
| 28 |
# This line should now work because we have successfully imported OmniParser.
|
| 29 |
parser_instance = OmniParser.from_model_path("omniparser-v2-effnet")
|
| 30 |
print("β
OmniParser model loaded successfully.")
|
|
@@ -50,6 +57,7 @@ iface = gr.Interface(
|
|
| 50 |
gr.Code(label="Full JSON Output", language="json")
|
| 51 |
],
|
| 52 |
title="Microsoft OmniParser Demo (Final Workaround)",
|
| 53 |
-
description="This deployment works by directly
|
| 54 |
)
|
| 55 |
-
iface.launch()
|
|
|
|
|
|
| 3 |
import gradio as gr
|
| 4 |
import json
|
| 5 |
import torch
|
| 6 |
+
import importlib.util # <-- Import the special library
|
| 7 |
+
|
| 8 |
+
# --- FINAL WORKAROUND using importlib ---
|
| 9 |
+
print("--- Starting final import workaround ---")
|
| 10 |
+
try:
|
| 11 |
+
# 1. Construct the absolute path to the target file.
|
| 12 |
+
project_root = os.path.dirname(os.path.abspath(__file__))
|
| 13 |
+
parser_file_path = os.path.join(project_root, "omnitool", "omniparserserver", "parser.py")
|
| 14 |
+
print(f"DEBUG: Loading module directly from path: {parser_file_path}")
|
| 15 |
+
|
| 16 |
+
# 2. Use importlib to load the module directly from its file path.
|
| 17 |
+
# This is the most robust way to import a specific file and avoid name conflicts.
|
| 18 |
+
module_name = "omni_parser_module" # We give it a unique internal name
|
| 19 |
+
spec = importlib.util.spec_from_file_location(module_name, parser_file_path)
|
| 20 |
+
parser_module = importlib.util.module_from_spec(spec)
|
| 21 |
+
spec.loader.exec_module(parser_module)
|
| 22 |
+
|
| 23 |
+
# 3. Get the OmniParser class from the successfully loaded module.
|
| 24 |
+
OmniParser = parser_module.OmniParser
|
| 25 |
+
print("DEBUG: Successfully loaded OmniParser class using importlib.")
|
| 26 |
+
|
| 27 |
+
except Exception as e:
|
| 28 |
+
print("!!! CRITICAL FAILURE during final importlib loading !!!")
|
| 29 |
+
import traceback
|
| 30 |
+
traceback.print_exc()
|
| 31 |
+
raise e
|
| 32 |
|
| 33 |
# --- The rest of the application ---
|
| 34 |
+
print("Initializing model...")
|
| 35 |
# This line should now work because we have successfully imported OmniParser.
|
| 36 |
parser_instance = OmniParser.from_model_path("omniparser-v2-effnet")
|
| 37 |
print("β
OmniParser model loaded successfully.")
|
|
|
|
| 57 |
gr.Code(label="Full JSON Output", language="json")
|
| 58 |
],
|
| 59 |
title="Microsoft OmniParser Demo (Final Workaround)",
|
| 60 |
+
description="This deployment works by directly loading the parser.py file to bypass import conflicts."
|
| 61 |
)
|
| 62 |
+
iface.launch()
|
| 63 |
+
print("--- Gradio UI launched ---")
|