Spaces:
Sleeping
Sleeping
Hjgugugjhuhjggg
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -139,6 +139,13 @@ class S3DirectStream:
|
|
139 |
logger.error(f"Error al subir archivo a S3: {e}")
|
140 |
raise HTTPException(status_code=500, detail=f"Error al subir archivo a S3: {e}")
|
141 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
142 |
@app.post("/predict/")
|
143 |
async def predict(model_request: dict):
|
144 |
try:
|
@@ -146,6 +153,9 @@ async def predict(model_request: dict):
|
|
146 |
task = model_request.get("pipeline_task")
|
147 |
input_text = model_request.get("input_text")
|
148 |
|
|
|
|
|
|
|
149 |
streamer = S3DirectStream(S3_BUCKET_NAME)
|
150 |
model = streamer.load_model_from_s3(model_name)
|
151 |
tokenizer = streamer.load_tokenizer_from_s3(model_name)
|
|
|
139 |
logger.error(f"Error al subir archivo a S3: {e}")
|
140 |
raise HTTPException(status_code=500, detail=f"Error al subir archivo a S3: {e}")
|
141 |
|
142 |
+
def file_exists_in_s3(self, s3_key):
|
143 |
+
try:
|
144 |
+
self.s3_client.head_object(Bucket=self.bucket_name, Key=s3_key)
|
145 |
+
return True
|
146 |
+
except self.s3_client.exceptions.ClientError:
|
147 |
+
return False
|
148 |
+
|
149 |
@app.post("/predict/")
|
150 |
async def predict(model_request: dict):
|
151 |
try:
|
|
|
153 |
task = model_request.get("pipeline_task")
|
154 |
input_text = model_request.get("input_text")
|
155 |
|
156 |
+
if not model_name or not task or not input_text:
|
157 |
+
raise HTTPException(status_code=400, detail="Faltan parámetros en la solicitud.")
|
158 |
+
|
159 |
streamer = S3DirectStream(S3_BUCKET_NAME)
|
160 |
model = streamer.load_model_from_s3(model_name)
|
161 |
tokenizer = streamer.load_tokenizer_from_s3(model_name)
|