Spaces:
Runtime error
Runtime error
Geraldine J
commited on
Commit
·
d959e29
1
Parent(s):
1a545a7
Update app
Browse files
app.py
CHANGED
@@ -49,46 +49,7 @@ aws_access_key_id = os.environ['aws_access_key_id']
|
|
49 |
aws_secret_access_key = os.environ['aws_secret_access_key']
|
50 |
region = os.environ['region']
|
51 |
|
52 |
-
#
|
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):
|
85 |
-
temp = tempfile.NamedTemporaryFile(mode="wb")
|
86 |
-
with temp as jpg:
|
87 |
-
jpg.write(img_file)
|
88 |
-
print(jpg.name)
|
89 |
-
uf = upload_file(jpg.name)
|
90 |
-
return uf
|
91 |
-
|
92 |
def removeStr(string):
|
93 |
return string.replace(" ", "")
|
94 |
|
@@ -133,8 +94,48 @@ def arrayLista(a,b,c,d):
|
|
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 |
|
|
|
49 |
aws_secret_access_key = os.environ['aws_secret_access_key']
|
50 |
region = os.environ['region']
|
51 |
|
52 |
+
#Lista Json y Dataframe
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
53 |
def removeStr(string):
|
54 |
return string.replace(" ", "")
|
55 |
|
|
|
94 |
strlist2.append(d)
|
95 |
strlista = [strlist,strlist2]
|
96 |
df = pd.DataFrame(strlista,columns=['Cantidad','Especie'])
|
|
|
97 |
return df
|
98 |
+
|
99 |
+
#Imagen temporal guardada en upload_file
|
100 |
+
def tempFileJSON(img_file):
|
101 |
+
temp = tempfile.NamedTemporaryFile(mode="wb")
|
102 |
+
with temp as jpg:
|
103 |
+
jpg.write(img_file)
|
104 |
+
print(jpg.name)
|
105 |
+
uf = upload_file(jpg.name)
|
106 |
+
return uf
|
107 |
+
|
108 |
+
# Envio de imagenes a S3
|
109 |
+
def upload_file(file_name, bucket=None, object_name=None):
|
110 |
+
"""Upload a file to an S3 bucket
|
111 |
+
|
112 |
+
:param file_name: File to upload
|
113 |
+
:param bucket: Bucket to upload to
|
114 |
+
:param object_name: S3 object name. If not specified then file_name is used
|
115 |
+
:return: Json if file was uploaded, else False
|
116 |
+
"""
|
117 |
+
# If S3 object_name was not specified, use file_name
|
118 |
+
if object_name is None:
|
119 |
+
object_name = os.path.basename(file_name+".jpg")
|
120 |
+
if bucket is None:
|
121 |
+
bucket = 'oceanapp'
|
122 |
+
s3_client = boto3.client('s3',aws_access_key_id=aws_access_key_id,aws_secret_access_key=aws_secret_access_key)
|
123 |
+
aws_region = boto3.session.Session().region_name
|
124 |
+
# Upload the file
|
125 |
+
try:
|
126 |
+
with open(file_name, "rb") as f:
|
127 |
+
response = s3_client.upload_fileobj(f, bucket, object_name)
|
128 |
+
s3_url = f"https://{bucket}.s3.amazonaws.com/{object_name}"
|
129 |
+
stado = '"url_details":[{"statusCode":200, "s3_url":"'+s3_url+'"}]'
|
130 |
+
print(s3_url)
|
131 |
+
except FileNotFoundError:
|
132 |
+
print("The file was not found")
|
133 |
+
return False
|
134 |
+
except NoCredentialsError as e:
|
135 |
+
logging.error(e)
|
136 |
+
return False
|
137 |
+
return stado
|
138 |
+
|
139 |
# Model
|
140 |
model = torch.hub.load('ultralytics/yolov5', 'custom', path='best.pt', force_reload=True, autoshape=True) # local model o google colab
|
141 |
|