Spaces:
Running
Running
ArrcttacsrjksX
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -48,16 +48,15 @@ class ImageToDxfConverter:
|
|
48 |
|
49 |
def convert_image(self,
|
50 |
image_path: Optional[str],
|
51 |
-
output_folder: Optional[str] = None,
|
52 |
use_lines: bool = False) -> Tuple[Optional[str], Optional[str], List[str]]:
|
53 |
"""Convert image to DXF format."""
|
54 |
try:
|
55 |
# Input validation
|
56 |
if not image_path:
|
57 |
-
return
|
58 |
|
59 |
-
# Setup output directory
|
60 |
-
output_dir = self._ensure_directory(
|
61 |
timestamp = datetime.datetime.now().strftime("%Y-%m-%d_%H-%M-%S")
|
62 |
paths = self._generate_output_paths(output_dir, timestamp)
|
63 |
|
@@ -81,9 +80,8 @@ class ImageToDxfConverter:
|
|
81 |
)
|
82 |
logger.info(f"Conversion output: {result.stdout}")
|
83 |
except subprocess.CalledProcessError as e:
|
84 |
-
|
85 |
-
|
86 |
-
return error_msg, None, []
|
87 |
|
88 |
# Move temporary files to final locations
|
89 |
shutil.move(paths['temp_dxf'], paths['output_dxf'])
|
@@ -133,9 +131,8 @@ class ImageToDxfConverter:
|
|
133 |
)
|
134 |
|
135 |
except Exception as e:
|
136 |
-
|
137 |
-
|
138 |
-
return error_msg, None, []
|
139 |
|
140 |
def create_gradio_interface():
|
141 |
"""Create and configure the Gradio interface."""
|
@@ -177,14 +174,12 @@ def create_gradio_interface():
|
|
177 |
label="Debug Preview",
|
178 |
elem_id="debug_output"
|
179 |
)
|
180 |
-
|
181 |
|
182 |
-
output_folder = "OutPut"
|
183 |
# Event handler
|
184 |
convert_btn.click(
|
185 |
fn=converter.convert_image,
|
186 |
-
inputs=[image_input,
|
187 |
-
outputs=[dxf_output, debug_output
|
188 |
)
|
189 |
|
190 |
return demo
|
|
|
48 |
|
49 |
def convert_image(self,
|
50 |
image_path: Optional[str],
|
|
|
51 |
use_lines: bool = False) -> Tuple[Optional[str], Optional[str], List[str]]:
|
52 |
"""Convert image to DXF format."""
|
53 |
try:
|
54 |
# Input validation
|
55 |
if not image_path:
|
56 |
+
return None, None, []
|
57 |
|
58 |
+
# Setup output directory with fixed path
|
59 |
+
output_dir = self._ensure_directory("OutputPDF")
|
60 |
timestamp = datetime.datetime.now().strftime("%Y-%m-%d_%H-%M-%S")
|
61 |
paths = self._generate_output_paths(output_dir, timestamp)
|
62 |
|
|
|
80 |
)
|
81 |
logger.info(f"Conversion output: {result.stdout}")
|
82 |
except subprocess.CalledProcessError as e:
|
83 |
+
logger.error(f"Conversion failed: {e.stderr}")
|
84 |
+
return None, None, []
|
|
|
85 |
|
86 |
# Move temporary files to final locations
|
87 |
shutil.move(paths['temp_dxf'], paths['output_dxf'])
|
|
|
131 |
)
|
132 |
|
133 |
except Exception as e:
|
134 |
+
logger.error(f"Conversion failed: {str(e)}")
|
135 |
+
return None, None, []
|
|
|
136 |
|
137 |
def create_gradio_interface():
|
138 |
"""Create and configure the Gradio interface."""
|
|
|
174 |
label="Debug Preview",
|
175 |
elem_id="debug_output"
|
176 |
)
|
|
|
177 |
|
|
|
178 |
# Event handler
|
179 |
convert_btn.click(
|
180 |
fn=converter.convert_image,
|
181 |
+
inputs=[image_input, use_lines_checkbox],
|
182 |
+
outputs=[dxf_output, debug_output]
|
183 |
)
|
184 |
|
185 |
return demo
|