Spaces:
Runtime error
Runtime error
Geraldine J
commited on
Commit
·
1a545a7
1
Parent(s):
094aae1
Update app lists
Browse files
app.py
CHANGED
@@ -51,34 +51,34 @@ region = os.environ['region']
|
|
51 |
|
52 |
# Envio de imagenes a S3
|
53 |
def upload_file(file_name, bucket=None, object_name=None):
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
|
83 |
#Imagen temporal guardada en upload_file
|
84 |
def tempFileJSON(img_file):
|
@@ -90,53 +90,53 @@ def tempFileJSON(img_file):
|
|
90 |
return uf
|
91 |
|
92 |
def removeStr(string):
|
93 |
-
|
94 |
-
|
95 |
-
# Model
|
96 |
-
model = torch.hub.load('ultralytics/yolov5', 'custom', path='best.pt', force_reload=True, autoshape=True) # local model o google colab
|
97 |
|
98 |
def listJSON(a,b,c,d,e,f,resImg):
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
|
119 |
def arrayLista(a,b,c,d):
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
|
|
|
|
|
|
140 |
|
141 |
def yolo(size, iou, conf, im):
|
142 |
try:
|
|
|
51 |
|
52 |
# Envio de imagenes a S3
|
53 |
def upload_file(file_name, bucket=None, object_name=None):
|
54 |
+
"""Upload a file to an S3 bucket
|
55 |
+
|
56 |
+
:param file_name: File to upload
|
57 |
+
:param bucket: Bucket to upload to
|
58 |
+
:param object_name: S3 object name. If not specified then file_name is used
|
59 |
+
:return: Json if file was uploaded, else False
|
60 |
+
"""
|
61 |
+
# If S3 object_name was not specified, use file_name
|
62 |
+
if object_name is None:
|
63 |
+
object_name = os.path.basename(file_name+".jpg")
|
64 |
+
if bucket is None:
|
65 |
+
bucket = 'oceanapp'
|
66 |
+
s3_client = boto3.client('s3',aws_access_key_id=aws_access_key_id,aws_secret_access_key=aws_secret_access_key)
|
67 |
+
aws_region = boto3.session.Session().region_name
|
68 |
+
# Upload the file
|
69 |
+
try:
|
70 |
+
with open(file_name, "rb") as f:
|
71 |
+
response = s3_client.upload_fileobj(f, bucket, object_name)
|
72 |
+
s3_url = f"https://{bucket}.s3.amazonaws.com/{object_name}"
|
73 |
+
stado = '"url_details":[{"statusCode":200, "s3_url":"'+s3_url+'"}]'
|
74 |
+
print(s3_url)
|
75 |
+
except FileNotFoundError:
|
76 |
+
print("The file was not found")
|
77 |
+
return False
|
78 |
+
except NoCredentialsError as e:
|
79 |
+
logging.error(e)
|
80 |
+
return False
|
81 |
+
return stado
|
82 |
|
83 |
#Imagen temporal guardada en upload_file
|
84 |
def tempFileJSON(img_file):
|
|
|
90 |
return uf
|
91 |
|
92 |
def removeStr(string):
|
93 |
+
return string.replace(" ", "")
|
|
|
|
|
|
|
94 |
|
95 |
def listJSON(a,b,c,d,e,f,resImg):
|
96 |
+
x = re.findall("obo mar", d)
|
97 |
+
y = re.findall("elica", d)
|
98 |
+
z = re.findall("elica", f)
|
99 |
+
if x:
|
100 |
+
d = 'Lobo marino'
|
101 |
+
if y:
|
102 |
+
d = 'Pelicano'
|
103 |
+
if z:
|
104 |
+
f = 'Pelicano'
|
105 |
+
if(d=='Lobo marino' or d=='Pelicano'):
|
106 |
+
if d =='Pelicano\nSp' or d =='Pelicano\nS':
|
107 |
+
d = 'Pelicano'
|
108 |
+
if f!='Pelicano':
|
109 |
+
strlista = '"detail":[{"quantity":"'+str(removeStr(c))+'","description":"'+str(d)+'"}]'
|
110 |
+
else:
|
111 |
+
strlista = '"detail":[{"quantity":"'+str(removeStr(c))+'","description":"'+str(d)+'"},{"quantity":"'+str(removeStr(e))+'","description":"'+str(f)+'"}]'
|
112 |
+
strlist = '{"image":"'+str(removeStr(a))+'","size":"'+str(removeStr(b))+'",'+strlista+','+resImg+'}'
|
113 |
+
json_string = json.loads(strlist)
|
114 |
+
return json_string
|
115 |
|
116 |
def arrayLista(a,b,c,d):
|
117 |
+
x = re.findall("obo mar", b)
|
118 |
+
y = re.findall("elica", b)
|
119 |
+
z = re.findall("elica", d)
|
120 |
+
if x:
|
121 |
+
b = 'Lobo marino'
|
122 |
+
if y:
|
123 |
+
b = 'Pelicano'
|
124 |
+
if z:
|
125 |
+
d = 'Pelicano'
|
126 |
+
if(b=='Lobo marino' or b=='Pelicano'):
|
127 |
+
strlist =[]
|
128 |
+
strlist2 =[]
|
129 |
+
strlist.append(removeStr(a))
|
130 |
+
strlist.append(b)
|
131 |
+
if d=='Pelicano':
|
132 |
+
strlist2.append(removeStr(c))
|
133 |
+
strlist2.append(d)
|
134 |
+
strlista = [strlist,strlist2]
|
135 |
+
df = pd.DataFrame(strlista,columns=['Cantidad','Especie'])
|
136 |
+
print(df)
|
137 |
+
return df
|
138 |
+
# Model
|
139 |
+
model = torch.hub.load('ultralytics/yolov5', 'custom', path='best.pt', force_reload=True, autoshape=True) # local model o google colab
|
140 |
|
141 |
def yolo(size, iou, conf, im):
|
142 |
try:
|