Spaces:
Sleeping
Sleeping
ArrcttacsrjksX
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -7,11 +7,6 @@ from huggingface_hub import upload_file
|
|
7 |
|
8 |
def convert_image_to_dxf(image_file, output_folder=None, use_lines=False):
|
9 |
try:
|
10 |
-
# Ensure HF_TOKEN environment variable is set
|
11 |
-
hf_token = os.getenv("HF_TOKEN")
|
12 |
-
if not hf_token:
|
13 |
-
return "Hugging Face token not found", None, None
|
14 |
-
|
15 |
# Validate input image
|
16 |
if image_file is None:
|
17 |
return "No image provided", None, None
|
@@ -54,7 +49,12 @@ def convert_image_to_dxf(image_file, output_folder=None, use_lines=False):
|
|
54 |
|
55 |
# Prepare folder structure for upload
|
56 |
date_folder = f"{current_date}"
|
57 |
-
|
|
|
|
|
|
|
|
|
|
|
58 |
# Upload input image, output DXF, and optionally debug image to Hugging Face in a date-based folder
|
59 |
uploaded_files = []
|
60 |
|
@@ -62,8 +62,8 @@ def convert_image_to_dxf(image_file, output_folder=None, use_lines=False):
|
|
62 |
uploaded_input = upload_file(
|
63 |
path_or_fileobj=image_path,
|
64 |
path_in_repo=f"datasets/ArrcttacsrjksX/ImageToAutocadData/{date_folder}/{os.path.basename(image_path)}",
|
65 |
-
repo_id="ArrcttacsrjksX/ImageToAutocadData",
|
66 |
-
token=hf_token
|
67 |
)
|
68 |
uploaded_files.append(uploaded_input)
|
69 |
|
@@ -71,8 +71,8 @@ def convert_image_to_dxf(image_file, output_folder=None, use_lines=False):
|
|
71 |
uploaded_dxf = upload_file(
|
72 |
path_or_fileobj=output_path,
|
73 |
path_in_repo=f"datasets/ArrcttacsrjksX/ImageToAutocadData/{date_folder}/{os.path.basename(output_path)}",
|
74 |
-
repo_id="ArrcttacsrjksX/ImageToAutocadData",
|
75 |
-
token=hf_token
|
76 |
)
|
77 |
uploaded_files.append(uploaded_dxf)
|
78 |
|
@@ -81,8 +81,8 @@ def convert_image_to_dxf(image_file, output_folder=None, use_lines=False):
|
|
81 |
uploaded_debug = upload_file(
|
82 |
path_or_fileobj=debug_output_path,
|
83 |
path_in_repo=f"datasets/ArrcttacsrjksX/ImageToAutocadData/{date_folder}/{os.path.basename(debug_output_path)}",
|
84 |
-
repo_id="ArrcttacsrjksX/ImageToAutocadData",
|
85 |
-
token=hf_token
|
86 |
)
|
87 |
uploaded_files.append(uploaded_debug)
|
88 |
|
@@ -93,7 +93,6 @@ def convert_image_to_dxf(image_file, output_folder=None, use_lines=False):
|
|
93 |
error_msg = f"Error converting image to DXF: {e.stderr.decode('utf-8') if e.stderr else e}"
|
94 |
return error_msg, None, None
|
95 |
|
96 |
-
|
97 |
def main():
|
98 |
with gr.Blocks() as demo:
|
99 |
with gr.Tabs():
|
@@ -128,7 +127,6 @@ def main():
|
|
128 |
|
129 |
demo.launch(share=True)
|
130 |
|
131 |
-
|
132 |
if __name__ == "__main__":
|
133 |
try:
|
134 |
subprocess.run(['chmod', '+x', './SimpleImageToDxfHavePass'], check=True)
|
|
|
7 |
|
8 |
def convert_image_to_dxf(image_file, output_folder=None, use_lines=False):
|
9 |
try:
|
|
|
|
|
|
|
|
|
|
|
10 |
# Validate input image
|
11 |
if image_file is None:
|
12 |
return "No image provided", None, None
|
|
|
49 |
|
50 |
# Prepare folder structure for upload
|
51 |
date_folder = f"{current_date}"
|
52 |
+
|
53 |
+
# Hugging Face token
|
54 |
+
hf_token = os.getenv("HF_TOKEN")
|
55 |
+
if not hf_token:
|
56 |
+
return "Hugging Face token not found", None, None
|
57 |
+
|
58 |
# Upload input image, output DXF, and optionally debug image to Hugging Face in a date-based folder
|
59 |
uploaded_files = []
|
60 |
|
|
|
62 |
uploaded_input = upload_file(
|
63 |
path_or_fileobj=image_path,
|
64 |
path_in_repo=f"datasets/ArrcttacsrjksX/ImageToAutocadData/{date_folder}/{os.path.basename(image_path)}",
|
65 |
+
repo_id="ArrcttacsrjksX/ImageToAutocadData",
|
66 |
+
token=hf_token
|
67 |
)
|
68 |
uploaded_files.append(uploaded_input)
|
69 |
|
|
|
71 |
uploaded_dxf = upload_file(
|
72 |
path_or_fileobj=output_path,
|
73 |
path_in_repo=f"datasets/ArrcttacsrjksX/ImageToAutocadData/{date_folder}/{os.path.basename(output_path)}",
|
74 |
+
repo_id="ArrcttacsrjksX/ImageToAutocadData",
|
75 |
+
token=hf_token
|
76 |
)
|
77 |
uploaded_files.append(uploaded_dxf)
|
78 |
|
|
|
81 |
uploaded_debug = upload_file(
|
82 |
path_or_fileobj=debug_output_path,
|
83 |
path_in_repo=f"datasets/ArrcttacsrjksX/ImageToAutocadData/{date_folder}/{os.path.basename(debug_output_path)}",
|
84 |
+
repo_id="ArrcttacsrjksX/ImageToAutocadData",
|
85 |
+
token=hf_token
|
86 |
)
|
87 |
uploaded_files.append(uploaded_debug)
|
88 |
|
|
|
93 |
error_msg = f"Error converting image to DXF: {e.stderr.decode('utf-8') if e.stderr else e}"
|
94 |
return error_msg, None, None
|
95 |
|
|
|
96 |
def main():
|
97 |
with gr.Blocks() as demo:
|
98 |
with gr.Tabs():
|
|
|
127 |
|
128 |
demo.launch(share=True)
|
129 |
|
|
|
130 |
if __name__ == "__main__":
|
131 |
try:
|
132 |
subprocess.run(['chmod', '+x', './SimpleImageToDxfHavePass'], check=True)
|