Pushpak21 commited on
Commit
e93edf5
·
verified ·
1 Parent(s): 2ab62dd

Delete app.py

Browse files
Files changed (1) hide show
  1. app.py +0 -107
app.py DELETED
@@ -1,107 +0,0 @@
1
- # === app.py (FastAPI backend) ===
2
- from fastapi import FastAPI, UploadFile, File
3
- from fastapi.middleware.cors import CORSMiddleware
4
- from fastapi.responses import JSONResponse
5
- import uvicorn
6
-
7
- app = FastAPI()
8
-
9
- app.add_middleware(
10
- CORSMiddleware,
11
- allow_origins=["*"],
12
- allow_credentials=True,
13
- allow_methods=["*"],
14
- allow_headers=["*"],
15
- )
16
-
17
- def parse_dcm_assembly_from_bytes(file_bytes):
18
- lines = file_bytes.decode("utf-8").splitlines()
19
-
20
- blocks = []
21
- current_block = []
22
-
23
- for line in lines:
24
- if line.startswith("CLASS"):
25
- if current_block:
26
- blocks.append(current_block)
27
- current_block = []
28
- current_block.append(line.strip())
29
- if current_block:
30
- blocks.append(current_block)
31
-
32
- parts = []
33
- geometry = {}
34
- constraints = []
35
-
36
- plane_map = {}
37
- tag_to_plane = {}
38
- label_map = {}
39
-
40
- for block in blocks:
41
- header = block[0]
42
- if header.startswith("CLASS SET "):
43
- part = {}
44
- member_tags = []
45
- for line in block:
46
- if line.startswith("DCM3_TEXT_LABEL"):
47
- part['name'] = line.split("DCM3_TEXT_LABEL", 1)[1].strip()
48
- elif line.startswith("FMEMBER TAGS"):
49
- member_tags = list(map(int, line.split()[2:]))
50
- if 'name' in part:
51
- part['member_tags'] = member_tags
52
- parts.append(part)
53
-
54
- elif header.startswith("CLASS PLANE "):
55
- plane_id = int(header.split()[-1])
56
- base_point = None
57
- normal = None
58
- for line in block:
59
- if line.startswith("FBASE_POINT"):
60
- base_point = tuple(map(float, line.split()[1:]))
61
- elif line.startswith("FNORMAL"):
62
- normal = tuple(map(float, line.split()[1:]))
63
- if base_point and normal:
64
- plane_map[plane_id] = {'base_point': base_point, 'normal': normal}
65
-
66
- elif header.startswith("CLASS WORK_PLANE "):
67
- work_plane_id = int(header.split()[-1])
68
- plane_tag = None
69
- label = None
70
- for line in block:
71
- if line.startswith("FMY_PLANE TAG"):
72
- plane_tag = int(line.split()[-1])
73
- elif line.startswith("DCM3_TEXT_LABEL"):
74
- label = line.split("DCM3_TEXT_LABEL", 1)[1].strip()
75
- if plane_tag:
76
- tag_to_plane[work_plane_id] = plane_tag
77
- label_map[work_plane_id] = label
78
-
79
- elif header.startswith("CLASS CONSTRAINT "):
80
- constraint = {}
81
- for line in block:
82
- if line.startswith("FEND_1 TAG"):
83
- constraint['from'] = int(line.split()[-1])
84
- elif line.startswith("FEND_2 TAG"):
85
- constraint['to'] = int(line.split()[-1])
86
- elif line.startswith("DCM3_TEXT_LABEL"):
87
- constraint['label'] = line.split("DCM3_TEXT_LABEL", 1)[1].strip()
88
- if constraint:
89
- constraints.append(constraint)
90
-
91
- for wp_id, plane_id in tag_to_plane.items():
92
- if plane_id in plane_map:
93
- geometry[wp_id] = {
94
- **plane_map[plane_id],
95
- 'label': label_map.get(wp_id)
96
- }
97
-
98
- return {"parts": parts, "geometry": geometry, "constraints": constraints}
99
-
100
- @app.post("/parse")
101
- async def parse_file(file: UploadFile = File(...)):
102
- content = await file.read()
103
- parsed_data = parse_dcm_assembly_from_bytes(content)
104
- return JSONResponse(content=parsed_data)
105
-
106
- if __name__ == "__main__":
107
- uvicorn.run(app, host="0.0.0.0", port=7860)