mosidi commited on
Commit
f9ef99e
·
1 Parent(s): b2e9632

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +41 -2
app.py CHANGED
@@ -1,8 +1,9 @@
1
  try:
 
2
  import detectron2
3
  except:
4
  import os
5
- os.system('pip install git+https://github.com/facebookresearch/detectron2.git')
6
 
7
  import cv2
8
  import json
@@ -32,6 +33,23 @@ from detectron2.engine import DefaultPredictor
32
  from detectron2.config import get_cfg
33
  from detectron2.utils.visualizer import Visualizer
34
  from detectron2.data import MetadataCatalog, DatasetCatalog
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
35
  # try:
36
  # register_coco_instances("Fiber", {}, "./labels-fiver.json", "./Fiber")
37
  # Fiber_metadata = MetadataCatalog.get("Fiber")
@@ -135,16 +153,37 @@ def inference(image_url, image, min_score):
135
  segmentation = np.where(item_mask == True)
136
  measurement = int(0.5+len(segmentation[0])/600)
137
  measurements[ind] = {'measurement': measurement, 'x_min': x_min, 'x_max': x_max, 'y_min': y_min, 'y_max': y_max}
 
 
 
 
 
 
 
 
 
138
 
 
 
 
139
  # Write the measurements to a CSV file
140
  with open('dmeasurements.csv', mode='w') as file:
141
  writer = csv.writer(file)
142
  writer.writerow(['ID', 'Measurement', 'X_Min', 'X_Max', 'Y_Min', 'Y_Max'])
143
  for id, data in measurements.items():
144
  writer.writerow([id, data['measurement'], data['x_min'], data['x_max'], data['y_min'], data['y_max']])
 
 
 
 
 
 
 
 
 
145
  # return file
146
 
147
- return "dmeasurements.csv"
148
 
149
 
150
  title = " Detectron2 Model Demo"
 
1
  try:
2
+ import cloudinary
3
  import detectron2
4
  except:
5
  import os
6
+ os.system('pip install cloudinary')
7
 
8
  import cv2
9
  import json
 
33
  from detectron2.config import get_cfg
34
  from detectron2.utils.visualizer import Visualizer
35
  from detectron2.data import MetadataCatalog, DatasetCatalog
36
+
37
+
38
+
39
+ import cloudinary.uploader
40
+ import io
41
+ import os
42
+ API_KEY =os.environ.getattribute("API_KEY")
43
+ Cloud_Name =os.environ.getattribute("Cloud_Name")
44
+ API_Secret =os.environ.getattribute("API_Secret")
45
+
46
+ # Print the Cloudinary URL of the uploaded file
47
+ print(upload_result["url"])
48
+
49
+
50
+
51
+
52
+
53
  # try:
54
  # register_coco_instances("Fiber", {}, "./labels-fiver.json", "./Fiber")
55
  # Fiber_metadata = MetadataCatalog.get("Fiber")
 
153
  segmentation = np.where(item_mask == True)
154
  measurement = int(0.5+len(segmentation[0])/600)
155
  measurements[ind] = {'measurement': measurement, 'x_min': x_min, 'x_max': x_max, 'y_min': y_min, 'y_max': y_max}
156
+ cloudinary.config(
157
+ cloud_name = Cloud_Name,
158
+ api_key = API_KEY,
159
+ api_secret = API_Secret,
160
+ secure = True
161
+ )
162
+
163
+ # Replace with the name of your CSV file
164
+ filename = "your_file.csv"
165
 
166
+
167
+
168
+
169
  # Write the measurements to a CSV file
170
  with open('dmeasurements.csv', mode='w') as file:
171
  writer = csv.writer(file)
172
  writer.writerow(['ID', 'Measurement', 'X_Min', 'X_Max', 'Y_Min', 'Y_Max'])
173
  for id, data in measurements.items():
174
  writer.writerow([id, data['measurement'], data['x_min'], data['x_max'], data['y_min'], data['y_max']])
175
+ # Convert the CSV content to a bytes object
176
+ csv_bytes = io.StringIO( file).read().encode("utf-8")
177
+
178
+ # Upload the file to Cloudinary
179
+ upload_result = cloudinary.uploader.upload(
180
+ csv_bytes,
181
+ resource_type = "raw",
182
+ folder = "csv_files"
183
+ )
184
  # return file
185
 
186
+ return upload_result["url"]
187
 
188
 
189
  title = " Detectron2 Model Demo"