Spaces:
Running
Running
ArrcttacsrjksX
commited on
Update Backup/app(47).py
Browse files- Backup/app(47).py +38 -1
Backup/app(47).py
CHANGED
@@ -8,6 +8,8 @@ from huggingface_hub import upload_file
|
|
8 |
from typing import Optional, Tuple, List, Union
|
9 |
import logging
|
10 |
import shutil
|
|
|
|
|
11 |
|
12 |
# Configure logging
|
13 |
logging.basicConfig(
|
@@ -46,6 +48,25 @@ class ImageToDxfConverter:
|
|
46 |
'temp_debug': output_folder / "_debug.png"
|
47 |
}
|
48 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
49 |
def convert_image(self,
|
50 |
image_path: Optional[str],
|
51 |
use_lines: bool = False) -> Tuple[Optional[str], Optional[str], List[str]]:
|
@@ -138,6 +159,11 @@ def create_gradio_interface():
|
|
138 |
"""Create and configure the Gradio interface."""
|
139 |
converter = ImageToDxfConverter()
|
140 |
|
|
|
|
|
|
|
|
|
|
|
141 |
with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
142 |
gr.Markdown("""
|
143 |
# Image to DXF Converter
|
@@ -151,6 +177,12 @@ def create_gradio_interface():
|
|
151 |
label="Input Image",
|
152 |
elem_id="image_input"
|
153 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
154 |
with gr.Column(scale=1):
|
155 |
use_lines_checkbox = gr.Checkbox(
|
156 |
label="Enable line detection",
|
@@ -175,7 +207,12 @@ def create_gradio_interface():
|
|
175 |
elem_id="debug_output"
|
176 |
)
|
177 |
|
178 |
-
# Event
|
|
|
|
|
|
|
|
|
|
|
179 |
convert_btn.click(
|
180 |
fn=converter.convert_image,
|
181 |
inputs=[image_input, use_lines_checkbox],
|
|
|
8 |
from typing import Optional, Tuple, List, Union
|
9 |
import logging
|
10 |
import shutil
|
11 |
+
from PIL import ImageGrab
|
12 |
+
import numpy as np
|
13 |
|
14 |
# Configure logging
|
15 |
logging.basicConfig(
|
|
|
48 |
'temp_debug': output_folder / "_debug.png"
|
49 |
}
|
50 |
|
51 |
+
def get_clipboard_image(self) -> Optional[str]:
|
52 |
+
"""Get image from clipboard and save it to a temporary file."""
|
53 |
+
try:
|
54 |
+
# Get image from clipboard
|
55 |
+
image = ImageGrab.grabclipboard()
|
56 |
+
if image is None:
|
57 |
+
return None
|
58 |
+
|
59 |
+
# Create temporary file
|
60 |
+
temp_dir = self._ensure_directory("temp")
|
61 |
+
temp_path = temp_dir / f"clipboard_{datetime.datetime.now().strftime('%Y%m%d_%H%M%S')}.png"
|
62 |
+
|
63 |
+
# Save image
|
64 |
+
image.save(str(temp_path))
|
65 |
+
return str(temp_path)
|
66 |
+
except Exception as e:
|
67 |
+
logger.error(f"Failed to get clipboard image: {e}")
|
68 |
+
return None
|
69 |
+
|
70 |
def convert_image(self,
|
71 |
image_path: Optional[str],
|
72 |
use_lines: bool = False) -> Tuple[Optional[str], Optional[str], List[str]]:
|
|
|
159 |
"""Create and configure the Gradio interface."""
|
160 |
converter = ImageToDxfConverter()
|
161 |
|
162 |
+
def paste_from_clipboard():
|
163 |
+
"""Handle paste from clipboard button click."""
|
164 |
+
image_path = converter.get_clipboard_image()
|
165 |
+
return image_path if image_path else None
|
166 |
+
|
167 |
with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
168 |
gr.Markdown("""
|
169 |
# Image to DXF Converter
|
|
|
177 |
label="Input Image",
|
178 |
elem_id="image_input"
|
179 |
)
|
180 |
+
with gr.Row():
|
181 |
+
paste_btn = gr.Button(
|
182 |
+
"📋 Paste from Clipboard",
|
183 |
+
size="sm",
|
184 |
+
elem_id="paste_btn"
|
185 |
+
)
|
186 |
with gr.Column(scale=1):
|
187 |
use_lines_checkbox = gr.Checkbox(
|
188 |
label="Enable line detection",
|
|
|
207 |
elem_id="debug_output"
|
208 |
)
|
209 |
|
210 |
+
# Event handlers
|
211 |
+
paste_btn.click(
|
212 |
+
fn=paste_from_clipboard,
|
213 |
+
outputs=[image_input]
|
214 |
+
)
|
215 |
+
|
216 |
convert_btn.click(
|
217 |
fn=converter.convert_image,
|
218 |
inputs=[image_input, use_lines_checkbox],
|