Hjgugugjhuhjggg commited on
Commit
48f9783
verified
1 Parent(s): 84aad02

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -20
app.py CHANGED
@@ -14,7 +14,6 @@ from io import BytesIO
14
  import boto3
15
  from botocore.exceptions import NoCredentialsError
16
  from huggingface_hub import snapshot_download
17
- import asyncio
18
  import shutil
19
 
20
  # Configuraci贸n global
@@ -72,6 +71,12 @@ class S3ModelLoader:
72
  print(f"Modelo {model_name} ya existe en S3.")
73
  except self.s3_client.exceptions.ClientError:
74
  print(f"Modelo {model_name} no existe en S3. Descargando desde Hugging Face...")
 
 
 
 
 
 
75
  model_path = snapshot_download(model_name, token=HUGGINGFACE_HUB_TOKEN)
76
 
77
  # Cargar el modelo y tokenizer
@@ -212,25 +217,6 @@ async def generate_image(request: GenerateRequest):
212
  except Exception as e:
213
  raise HTTPException(status_code=500, detail=f"Internal server error: {str(e)}")
214
 
215
- # Endpoint para generar texto a voz
216
- @app.post("/generate-text-to-speech")
217
- async def generate_text_to_speech(request: GenerateRequest):
218
- try:
219
- validated_body = request
220
- device = "cuda" if torch.cuda.is_available() else "cpu"
221
-
222
- audio_generator = pipeline("text-to-speech", model=validated_body.model_name, device=device)
223
- audio = audio_generator(validated_body.input_text)[0]
224
-
225
- audio_byte_arr = BytesIO()
226
- audio.save(audio_byte_arr, format="WAV")
227
- audio_byte_arr.seek(0)
228
-
229
- return StreamingResponse(audio_byte_arr, media_type="audio/wav")
230
-
231
- except Exception as e:
232
- raise HTTPException(status_code=500, detail=f"Internal server error: {str(e)}")
233
-
234
  # Ejecutar el servidor FastAPI con Uvicorn
235
  if __name__ == "__main__":
236
  import uvicorn
 
14
  import boto3
15
  from botocore.exceptions import NoCredentialsError
16
  from huggingface_hub import snapshot_download
 
17
  import shutil
18
 
19
  # Configuraci贸n global
 
71
  print(f"Modelo {model_name} ya existe en S3.")
72
  except self.s3_client.exceptions.ClientError:
73
  print(f"Modelo {model_name} no existe en S3. Descargando desde Hugging Face...")
74
+
75
+ # Eliminar cach茅 local de Hugging Face (si existe)
76
+ local_cache_dir = os.path.join(os.getenv("HOME"), ".cache/huggingface/hub/models--")
77
+ if os.path.exists(local_cache_dir):
78
+ shutil.rmtree(local_cache_dir)
79
+
80
  model_path = snapshot_download(model_name, token=HUGGINGFACE_HUB_TOKEN)
81
 
82
  # Cargar el modelo y tokenizer
 
217
  except Exception as e:
218
  raise HTTPException(status_code=500, detail=f"Internal server error: {str(e)}")
219
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
220
  # Ejecutar el servidor FastAPI con Uvicorn
221
  if __name__ == "__main__":
222
  import uvicorn