import herramientas import time import databank from fastapi.responses import FileResponse async def crea_partynight(image, outfit_color): endpoint = 'partynight' try: prompt = databank.obtenPrompt(endpoint, outfit_color=outfit_color) #Van a tener que ser kwargs porque variará de lo recibido de ep a ep. print(prompt) resultado = await herramientas.exeCute(endpoint, image, prompt) if type(resultado) is str: return FileResponse(resultado, media_type="image/jpg", filename=herramientas.formaFilename(endpoint)) #Usa el prompt como nombre en dev para info más rica, endpoint para usuario final. elif type(resultado) is dict: return resultado except Exception as e: print(f"Error 182: {e}") return {"error": e} async def crea_babydoll(image, outfit_color): endpoint = 'babydoll' try: prompt = databank.obtenPrompt(endpoint, outfit_color=outfit_color) print(prompt) resultado = await herramientas.exeCute(endpoint, image, prompt) if type(resultado) is str: return FileResponse(resultado, media_type="image/jpg", filename=herramientas.formaFilename(endpoint)) elif type(resultado) is dict: return resultado except Exception as e: print(f"Error: {e}") return {"error": "Unable to detect a face in the image. Please upload a different photo with a clear face."} async def crea_leather(image): endpoint = 'leather' try: prompt = databank.obtenPrompt(endpoint) print("Prompt final: ", prompt) resultado = await herramientas.exeCute(endpoint, image, prompt) if type(resultado) is str: return FileResponse(resultado, media_type="image/jpg", filename=herramientas.formaFilename(endpoint)) elif type(resultado) is dict: return resultado except Exception as e: print(f"Error: {e}") return {"error": "Unable to detect a face in the image. Please upload a different photo with a clear face."} async def crea_stewardess(image, outfit_color): endpoint = 'stewardess' try: prompt = databank.obtenPrompt(endpoint, outfit_color=outfit_color) print(prompt) resultado = await herramientas.exeCute(endpoint, image, prompt) #execute ya debe recibir prompt hecho. if type(resultado) is str: return FileResponse(resultado, media_type="image/jpg", filename=herramientas.formaFilename(endpoint)) elif type(resultado) is dict: return resultado except Exception as e: print(f"Error: {e}") return {"error": "Unable to detect a face in the image. Please upload a different photo with a clear face."} async def crea_oktoberfest(image): endpoint = 'oktoberfest' try: prompt = databank.obtenPrompt(endpoint) print(prompt) resultado = await herramientas.exeCute(endpoint, image, prompt) #execute ya debe recibir prompt hecho. if type(resultado) is str: return FileResponse(resultado, media_type="image/jpg", filename=herramientas.formaFilename(endpoint)) elif type(resultado) is dict: return resultado except Exception as e: print(f"Error: {e}") return {"error": "Unable to detect a face in the image. Please upload a different photo with a clear face."} async def crea_ghibli(image): endpoint = 'ghibli' try: prompt = databank.obtenPrompt(endpoint) print(prompt) resultado = await herramientas.exeCute(endpoint, image, prompt) #execute ya debe recibir prompt hecho. if type(resultado) is str: return FileResponse(resultado, media_type="image/jpg", filename=herramientas.formaFilename(endpoint)) elif type(resultado) is dict: return resultado except Exception as e: print(f"Error: {e}") return {"error": "Unable to detect a face in the image. Please upload a different photo with a clear face."} async def crea_wildwest(image): endpoint = 'wildwest' try: prompt = databank.obtenPrompt(endpoint) print(prompt) resultado = await herramientas.exeCute(endpoint, image, prompt) #execute ya debe recibir prompt hecho. if type(resultado) is str: return FileResponse(resultado, media_type="image/jpg", filename=herramientas.formaFilename(endpoint)) elif type(resultado) is dict: return resultado except Exception as e: print(f"Error: {e}") return {"error": "Unable to detect a face in the image. Please upload a different photo with a clear face."} async def crea_bride(image): endpoint = 'bride' try: prompt = databank.obtenPrompt(endpoint) print(prompt) resultado = await herramientas.exeCute(endpoint, image, prompt) #execute ya debe recibir prompt hecho. if type(resultado) is str: return FileResponse(resultado, media_type="image/jpg", filename=herramientas.formaFilename(endpoint)) elif type(resultado) is dict: return resultado except Exception as e: print(f"Error: {e}") return {"error": "Unable to detect a face in the image. Please upload a different photo with a clear face."} async def crea_swimsuit(image, outfit_color): endpoint = 'swimsuit' try: prompt = databank.obtenPrompt(endpoint, outfit_color=outfit_color) print(prompt) resultado = await herramientas.exeCute(endpoint, image, prompt) #execute ya debe recibir prompt hecho. if type(resultado) is str: return FileResponse(resultado, media_type="image/jpg", filename=herramientas.formaFilename(endpoint)) elif type(resultado) is dict: return resultado except Exception as e: print(f"Error: {e}") return {"error": "Unable to detect a face in the image. Please upload a different photo with a clear face."} async def crea_lingerie(image): endpoint = 'lingerie' try: prompt = databank.obtenPrompt(endpoint) print(prompt) resultado = await herramientas.exeCute(endpoint, image, prompt) #execute ya debe recibir prompt hecho. if type(resultado) is str: return FileResponse(resultado, media_type="image/jpg", filename=herramientas.formaFilename(prompt)) elif type(resultado) is dict: return resultado except Exception as e: print(f"Error: {e}") return {"error": "Unable to detect a face in the image. Please upload a different photo with a clear face."} async def crea_schooluniform(image): endpoint = 'schooluniform' try: prompt = databank.obtenPrompt(endpoint) print(prompt) resultado = await herramientas.exeCute(endpoint, image, prompt) #execute ya debe recibir prompt hecho. if type(resultado) is str: return FileResponse(resultado, media_type="image/jpg", filename=herramientas.formaFilename(prompt)) elif type(resultado) is dict: return resultado except Exception as e: print(f"Error: {e}") return {"error": "Unable to detect a face in the image. Please upload a different photo with a clear face."} async def crea_frenchmaid(image): endpoint = 'frenchmaid' try: prompt = databank.obtenPrompt(endpoint) print(prompt) resultado = await herramientas.exeCute(endpoint, image, prompt) #execute ya debe recibir prompt hecho. if type(resultado) is str: return FileResponse(resultado, media_type="image/jpg", filename=herramientas.formaFilename(prompt)) elif type(resultado) is dict: return resultado except Exception as e: print(f"Error: {e}") return {"error": "Unable to detect a face in the image. Please upload a different photo with a clear face."} async def crea_cheerleader(image, color, hairstyle): endpoint = 'cheerleader' try: prompt = databank.obtenPrompt(endpoint, outfit_color=color, hair_style = hairstyle) print(prompt) resultado = await herramientas.exeCute(endpoint, image, prompt) #execute ya debe recibir prompt hecho. if type(resultado) is str: return FileResponse(resultado, media_type="image/jpg", filename=herramientas.formaFilename(prompt)) elif type(resultado) is dict: return resultado except Exception as e: print(f"Error: {e}") return {"error": "Unable to detect a face in the image. Please upload a different photo with a clear face."}