Moibe commited on
Commit
a3d7f6f
·
1 Parent(s): eba05c5

Finished winner prompts!

Browse files
app.py CHANGED
@@ -1,17 +1,20 @@
 
1
  from fastapi import FastAPI, Form
2
  from fastapi import FastAPI, File, UploadFile
3
- import funciones
4
  from typing import Literal
5
 
6
  app = FastAPI()
7
 
 
 
8
  @app.post("/partynight/")
9
  async def partynight(
10
  image: UploadFile = File(...),
11
- outfit_color: Literal["red", "black", "blue", "golden", "pink", "green", "yellow", "purple", "silver", "white", "blue sky", "light blue", "royal blue", "navy blue", "orange", "random", ""] = Form(None)):
 
12
  if not image.content_type.startswith("image/"):
13
  return {"error": "The file is not an image."}
14
- return await funciones.crea_partynight(image, outfit_color)
15
 
16
  @app.post("/babydoll/")
17
  async def babydoll(
@@ -73,4 +76,50 @@ async def bride(
73
  ):
74
  if not image.content_type.startswith("image/"):
75
  return {"error": "The file is not an image."}
76
- return await funciones.crea_bride(image)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import funciones
2
  from fastapi import FastAPI, Form
3
  from fastapi import FastAPI, File, UploadFile
 
4
  from typing import Literal
5
 
6
  app = FastAPI()
7
 
8
+ #Future Importante, los errores como no detección de rostro, deben ser devueltos por ésta API.
9
+
10
  @app.post("/partynight/")
11
  async def partynight(
12
  image: UploadFile = File(...),
13
+ outfit_color: Literal["red", "black", "blue", "golden", "pink", "green", "yellow", "purple", "silver", "white", "blue sky", "light blue", "royal blue", "navy blue", "orange", "random", ""] = Form(None)
14
+ ):
15
  if not image.content_type.startswith("image/"):
16
  return {"error": "The file is not an image."}
17
+ return await funciones.crea_partynight(image, outfit_color)
18
 
19
  @app.post("/babydoll/")
20
  async def babydoll(
 
76
  ):
77
  if not image.content_type.startswith("image/"):
78
  return {"error": "The file is not an image."}
79
+ return await funciones.crea_bride(image)
80
+
81
+ @app.post("/swimsuit/")
82
+ async def swimsuit(
83
+ image: UploadFile = File(...),
84
+ color: Literal["red", "black", "blue", "golden", "pink", "green", "yellow", "purple", "silver", "white", "blue sky", "light blue", "royal blue", "navy blue", "orange", "random", ""] = Form(None)
85
+ ):
86
+ if not image.content_type.startswith("image/"):
87
+ return {"error": "The file is not an image."}
88
+ return await funciones.crea_swimsuit(image, color)
89
+
90
+ @app.post("/lingerie/")
91
+ async def lingerie(
92
+ image: UploadFile = File(...),
93
+ #color: Literal["red", "black", "blue", "golden", "pink", "green", "yellow", "purple", "silver", "white", "blue sky", "light blue", "royal blue", "navy blue", "orange", "random", ""] = Form(None)
94
+ ):
95
+ if not image.content_type.startswith("image/"):
96
+ return {"error": "The file is not an image."}
97
+ return await funciones.crea_lingerie(image)
98
+
99
+ @app.post("/schooluniform/")
100
+ async def schooluniform(
101
+ image: UploadFile = File(...),
102
+ #color: Literal["red", "black", "blue", "golden", "pink", "green", "yellow", "purple", "silver", "white", "blue sky", "light blue", "royal blue", "navy blue", "orange", "random", ""] = Form(None)
103
+ ):
104
+ if not image.content_type.startswith("image/"):
105
+ return {"error": "The file is not an image."}
106
+ return await funciones.crea_schooluniform(image)
107
+
108
+ @app.post("/frenchmaid/")
109
+ async def frenchmaid(
110
+ image: UploadFile = File(...),
111
+ #color: Literal["red", "black", "blue", "golden", "pink", "green", "yellow", "purple", "silver", "white", "blue sky", "light blue", "royal blue", "navy blue", "orange", "random", ""] = Form(None)
112
+ ):
113
+ if not image.content_type.startswith("image/"):
114
+ return {"error": "The file is not an image."}
115
+ return await funciones.crea_frenchmaid(image)
116
+
117
+ @app.post("/cheerleader/")
118
+ async def cheerleader(
119
+ image: UploadFile = File(...),
120
+ color: Literal["red", "black", "blue", "golden", "pink", "green", "yellow", "purple", "silver", "white", "blue sky", "light blue", "royal blue", "navy blue", "orange", "random", ""] = Form(None),
121
+ hairstyle: Literal["ponytail", "pigtails", ""] = Form(None)
122
+ ):
123
+ if not image.content_type.startswith("image/"):
124
+ return {"error": "The file is not an image."}
125
+ return await funciones.crea_cheerleader(image, color, hairstyle)
databank.py CHANGED
@@ -7,31 +7,31 @@ def obtenPrompt(endpoint, **kwargs): #Son opcionales todos los demás argumentos
7
  hair_style = kwargs["hair_style"] if "hair_style" in kwargs else ""
8
 
9
  if endpoint == "partynight":
10
- return f"A manga picture of a beautiful girl with a sexy {outfit_color} sequins cocktail dress."
11
  elif endpoint == "babydoll":
12
- return f"A manga picture of a beautiful girl with a sexy {outfit_color} babydoll dress."
13
  elif endpoint == "leather":
14
- return f"A {defineEstilo('leather')} picture of a beautiful girl with a neck chocker, a black leather skirt and black deep-cut long sleeved blouse."
15
  elif endpoint == "oktoberfest":
16
- return f"A Ghibli manga of a beautiful Oktoberfest waitress with big boobs serving beers."
17
  elif endpoint == "ghibli":
18
- return f"A Ghibli manga of a beautiful girl."
19
  elif endpoint == "wildwest":
20
- return f"A Ghibli manga of a beautiful wild west girl with a poncho, a revolver and bullets bandolier."
21
  elif endpoint == "stewardess":
22
- return f"A Ghibli manga of a beautiful flight attendant in a {outfit_color} uniform skirt with a {obtenAccesorio('stewardess')}."
23
  elif endpoint == "bride":
24
- return f"A {defineEstilo('bride')} art nouveau of a beautiful bride in a spectacular wedding dress."
25
  elif endpoint == "swimsuit":
26
- return f"A manga picture of a beautiful girl in {outfit_color} swimsuit."
27
  elif endpoint == "lingerie":
28
- return f"A manga picture of a girl in corset and hosiery."
29
  elif endpoint == "schooluniform":
30
- return f"A manga picture of a girl in school uniform."
31
  elif endpoint == "frenchmaid":
32
- return f"A manga picture of a girl in french maid uniform with maid's tiara."
33
  elif endpoint == "cheerleader":
34
- return f"A manga picture of a cheerleader with {outfit_color} uniform and {hair_style}."
35
 
36
  def obtenAccesorio(endpoint):
37
 
 
7
  hair_style = kwargs["hair_style"] if "hair_style" in kwargs else ""
8
 
9
  if endpoint == "partynight":
10
+ return f"A manga picture of a beautiful girl with a sexy {outfit_color} sequins cocktail dress"
11
  elif endpoint == "babydoll":
12
+ return f"A manga picture of a beautiful girl with a sexy {outfit_color} babydoll dress"
13
  elif endpoint == "leather":
14
+ return f"A {defineEstilo('leather')} picture of a beautiful girl with a neck chocker, a black leather skirt and black deep-cut long sleeved blouse"
15
  elif endpoint == "oktoberfest":
16
+ return f"A Ghibli manga of a beautiful Oktoberfest waitress with big boobs serving beers"
17
  elif endpoint == "ghibli":
18
+ return f"A Ghibli manga of a beautiful girl"
19
  elif endpoint == "wildwest":
20
+ return f"A Ghibli manga of a beautiful wild west girl with a poncho, a revolver and bullets bandolier"
21
  elif endpoint == "stewardess":
22
+ return f"A Ghibli manga of a beautiful flight attendant in a {outfit_color} uniform skirt with a {obtenAccesorio('stewardess')}"
23
  elif endpoint == "bride":
24
+ return f"A {defineEstilo('bride')} art nouveau of a beautiful bride in a spectacular wedding dress"
25
  elif endpoint == "swimsuit":
26
+ return f"A manga picture of a beautiful girl in {outfit_color} swimsuit"
27
  elif endpoint == "lingerie":
28
+ return f"A manga picture of a girl in corset and hosiery"
29
  elif endpoint == "schooluniform":
30
+ return f"A manga picture of a girl in school uniform"
31
  elif endpoint == "frenchmaid":
32
+ return f"A manga picture of a girl in french maid uniform with maid's tiara"
33
  elif endpoint == "cheerleader":
34
+ return f"A manga picture of a cheerleader with {outfit_color} uniform and {hair_style}"
35
 
36
  def obtenAccesorio(endpoint):
37
 
funciones.py CHANGED
@@ -3,20 +3,17 @@ import time
3
  import databank
4
  from fastapi.responses import FileResponse
5
 
6
- timestamp_segundos = int(time.time())
7
- print(f"Printed at: {timestamp_segundos}.")
8
-
9
  async def crea_partynight(image, outfit_color):
10
  endpoint = 'partynight'
11
  try:
12
  prompt = databank.obtenPrompt(endpoint, outfit_color=outfit_color) #Van a tener que ser kwargs porque variará de lo recibido de ep a ep.
13
  resultado = await herramientas.exeCute(endpoint, image, prompt)
14
- if type(resultado) is str:
15
- return FileResponse(resultado, media_type="image/jpg", filename=f"{endpoint}-{timestamp_segundos}.jpg")
16
- elif type(resultado) is dict:
17
- return resultado
18
  except Exception as e:
19
- print(f"Error: {e}")
20
  return {"error": e}
21
 
22
  async def crea_babydoll(image, outfit_color):
@@ -25,7 +22,7 @@ async def crea_babydoll(image, outfit_color):
25
  prompt = databank.obtenPrompt(endpoint, outfit_color=outfit_color)
26
  resultado = await herramientas.exeCute(endpoint, image, prompt)
27
  if type(resultado) is str:
28
- return FileResponse(resultado, media_type="image/jpg", filename=f"{endpoint}-{timestamp_segundos}.jpg")
29
  elif type(resultado) is dict:
30
  return resultado
31
  except Exception as e:
@@ -39,7 +36,7 @@ async def crea_leather(image):
39
  print("Prompt final: ", prompt)
40
  resultado = await herramientas.exeCute(endpoint, image, prompt)
41
  if type(resultado) is str:
42
- return FileResponse(resultado, media_type="image/jpg", filename=f"{endpoint}-{timestamp_segundos}.jpg")
43
  elif type(resultado) is dict:
44
  return resultado
45
  except Exception as e:
@@ -52,7 +49,7 @@ async def crea_stewardess(image, outfit_color):
52
  prompt = databank.obtenPrompt(endpoint, outfit_color=outfit_color)
53
  resultado = await herramientas.exeCute(endpoint, image, prompt) #execute ya debe recibir prompt hecho.
54
  if type(resultado) is str:
55
- return FileResponse(resultado, media_type="image/jpg", filename=f"{endpoint}-{timestamp_segundos}.jpg")
56
  elif type(resultado) is dict:
57
  return resultado
58
  except Exception as e:
@@ -65,7 +62,7 @@ async def crea_oktoberfest(image):
65
  prompt = databank.obtenPrompt(endpoint)
66
  resultado = await herramientas.exeCute(endpoint, image, prompt) #execute ya debe recibir prompt hecho.
67
  if type(resultado) is str:
68
- return FileResponse(resultado, media_type="image/jpg", filename=f"{endpoint}-{timestamp_segundos}.jpg")
69
  elif type(resultado) is dict:
70
  return resultado
71
  except Exception as e:
@@ -78,7 +75,7 @@ async def crea_ghibli(image):
78
  prompt = databank.obtenPrompt(endpoint)
79
  resultado = await herramientas.exeCute(endpoint, image, prompt) #execute ya debe recibir prompt hecho.
80
  if type(resultado) is str:
81
- return FileResponse(resultado, media_type="image/jpg", filename=f"{endpoint}-{timestamp_segundos}.jpg")
82
  elif type(resultado) is dict:
83
  return resultado
84
  except Exception as e:
@@ -91,7 +88,7 @@ async def crea_wildwest(image):
91
  prompt = databank.obtenPrompt(endpoint)
92
  resultado = await herramientas.exeCute(endpoint, image, prompt) #execute ya debe recibir prompt hecho.
93
  if type(resultado) is str:
94
- return FileResponse(resultado, media_type="image/jpg", filename=f"{endpoint}-{timestamp_segundos}.jpg")
95
  elif type(resultado) is dict:
96
  return resultado
97
  except Exception as e:
@@ -104,10 +101,76 @@ async def crea_bride(image):
104
  prompt = databank.obtenPrompt(endpoint)
105
  resultado = await herramientas.exeCute(endpoint, image, prompt) #execute ya debe recibir prompt hecho.
106
  if type(resultado) is str:
107
- return FileResponse(resultado, media_type="image/jpg", filename=f"{endpoint}-{timestamp_segundos}.jpg")
 
 
 
 
 
 
 
 
 
 
 
 
 
108
  elif type(resultado) is dict:
109
  return resultado
110
  except Exception as e:
111
  print(f"Error: {e}")
112
- return {"error": "Unable to detect a face in the image. Please upload a different photo with a clear face."}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
113
 
 
3
  import databank
4
  from fastapi.responses import FileResponse
5
 
 
 
 
6
  async def crea_partynight(image, outfit_color):
7
  endpoint = 'partynight'
8
  try:
9
  prompt = databank.obtenPrompt(endpoint, outfit_color=outfit_color) #Van a tener que ser kwargs porque variará de lo recibido de ep a ep.
10
  resultado = await herramientas.exeCute(endpoint, image, prompt)
11
+ if type(resultado) is str:
12
+ return FileResponse(resultado, media_type="image/jpg", filename=herramientas.formaFilename(prompt))
13
+ elif type(resultado) is dict:
14
+ return resultado
15
  except Exception as e:
16
+ print(f"Error 182: {e}")
17
  return {"error": e}
18
 
19
  async def crea_babydoll(image, outfit_color):
 
22
  prompt = databank.obtenPrompt(endpoint, outfit_color=outfit_color)
23
  resultado = await herramientas.exeCute(endpoint, image, prompt)
24
  if type(resultado) is str:
25
+ return FileResponse(resultado, media_type="image/jpg", filename=herramientas.formaFilename(prompt))
26
  elif type(resultado) is dict:
27
  return resultado
28
  except Exception as e:
 
36
  print("Prompt final: ", prompt)
37
  resultado = await herramientas.exeCute(endpoint, image, prompt)
38
  if type(resultado) is str:
39
+ return FileResponse(resultado, media_type="image/jpg", filename=herramientas.formaFilename(prompt))
40
  elif type(resultado) is dict:
41
  return resultado
42
  except Exception as e:
 
49
  prompt = databank.obtenPrompt(endpoint, outfit_color=outfit_color)
50
  resultado = await herramientas.exeCute(endpoint, image, prompt) #execute ya debe recibir prompt hecho.
51
  if type(resultado) is str:
52
+ return FileResponse(resultado, media_type="image/jpg", filename=herramientas.formaFilename(prompt))
53
  elif type(resultado) is dict:
54
  return resultado
55
  except Exception as e:
 
62
  prompt = databank.obtenPrompt(endpoint)
63
  resultado = await herramientas.exeCute(endpoint, image, prompt) #execute ya debe recibir prompt hecho.
64
  if type(resultado) is str:
65
+ return FileResponse(resultado, media_type="image/jpg", filename=herramientas.formaFilename(prompt))
66
  elif type(resultado) is dict:
67
  return resultado
68
  except Exception as e:
 
75
  prompt = databank.obtenPrompt(endpoint)
76
  resultado = await herramientas.exeCute(endpoint, image, prompt) #execute ya debe recibir prompt hecho.
77
  if type(resultado) is str:
78
+ return FileResponse(resultado, media_type="image/jpg", filename=herramientas.formaFilename(prompt))
79
  elif type(resultado) is dict:
80
  return resultado
81
  except Exception as e:
 
88
  prompt = databank.obtenPrompt(endpoint)
89
  resultado = await herramientas.exeCute(endpoint, image, prompt) #execute ya debe recibir prompt hecho.
90
  if type(resultado) is str:
91
+ return FileResponse(resultado, media_type="image/jpg", filename=herramientas.formaFilename(prompt))
92
  elif type(resultado) is dict:
93
  return resultado
94
  except Exception as e:
 
101
  prompt = databank.obtenPrompt(endpoint)
102
  resultado = await herramientas.exeCute(endpoint, image, prompt) #execute ya debe recibir prompt hecho.
103
  if type(resultado) is str:
104
+ return FileResponse(resultado, media_type="image/jpg", filename=herramientas.formaFilename(prompt))
105
+ elif type(resultado) is dict:
106
+ return resultado
107
+ except Exception as e:
108
+ print(f"Error: {e}")
109
+ return {"error": "Unable to detect a face in the image. Please upload a different photo with a clear face."}
110
+
111
+ async def crea_swimsuit(image, outfit_color):
112
+ endpoint = 'swimsuit'
113
+ try:
114
+ prompt = databank.obtenPrompt(endpoint, outfit_color=outfit_color)
115
+ resultado = await herramientas.exeCute(endpoint, image, prompt) #execute ya debe recibir prompt hecho.
116
+ if type(resultado) is str:
117
+ return FileResponse(resultado, media_type="image/jpg", filename=herramientas.formaFilename(prompt))
118
  elif type(resultado) is dict:
119
  return resultado
120
  except Exception as e:
121
  print(f"Error: {e}")
122
+ return {"error": "Unable to detect a face in the image. Please upload a different photo with a clear face."}
123
+
124
+ async def crea_lingerie(image):
125
+ endpoint = 'lingerie'
126
+ try:
127
+ prompt = databank.obtenPrompt(endpoint)
128
+ resultado = await herramientas.exeCute(endpoint, image, prompt) #execute ya debe recibir prompt hecho.
129
+ if type(resultado) is str:
130
+ return FileResponse(resultado, media_type="image/jpg", filename=herramientas.formaFilename(prompt))
131
+ elif type(resultado) is dict:
132
+ return resultado
133
+ except Exception as e:
134
+ print(f"Error: {e}")
135
+ return {"error": "Unable to detect a face in the image. Please upload a different photo with a clear face."}
136
+
137
+ async def crea_schooluniform(image):
138
+ endpoint = 'schooluniform'
139
+ try:
140
+ prompt = databank.obtenPrompt(endpoint)
141
+ resultado = await herramientas.exeCute(endpoint, image, prompt) #execute ya debe recibir prompt hecho.
142
+ if type(resultado) is str:
143
+ return FileResponse(resultado, media_type="image/jpg", filename=herramientas.formaFilename(prompt))
144
+ elif type(resultado) is dict:
145
+ return resultado
146
+ except Exception as e:
147
+ print(f"Error: {e}")
148
+ return {"error": "Unable to detect a face in the image. Please upload a different photo with a clear face."}
149
+
150
+ async def crea_frenchmaid(image):
151
+ endpoint = 'frenchmaid'
152
+ try:
153
+ prompt = databank.obtenPrompt(endpoint)
154
+ resultado = await herramientas.exeCute(endpoint, image, prompt) #execute ya debe recibir prompt hecho.
155
+ if type(resultado) is str:
156
+ return FileResponse(resultado, media_type="image/jpg", filename=herramientas.formaFilename(prompt))
157
+ elif type(resultado) is dict:
158
+ return resultado
159
+ except Exception as e:
160
+ print(f"Error: {e}")
161
+ return {"error": "Unable to detect a face in the image. Please upload a different photo with a clear face."}
162
+
163
+ async def crea_cheerleader(image, color, hairstyle):
164
+ endpoint = 'cheerleader'
165
+ try:
166
+ prompt = databank.obtenPrompt(endpoint, outfit_color=color, hair_style = hairstyle)
167
+ resultado = await herramientas.exeCute(endpoint, image, prompt) #execute ya debe recibir prompt hecho.
168
+ if type(resultado) is str:
169
+ return FileResponse(resultado, media_type="image/jpg", filename=herramientas.formaFilename(prompt))
170
+ elif type(resultado) is dict:
171
+ return resultado
172
+ except Exception as e:
173
+ print(f"Error: {e}")
174
+ return {"error": "Unable to detect a face in the image. Please upload a different photo with a clear face."}
175
+
176
 
herramientas.py CHANGED
@@ -2,7 +2,7 @@ import os
2
  import socket
3
  import random
4
  import globales
5
- import databank
6
  import tempfile
7
  import gradio_client
8
 
@@ -84,7 +84,6 @@ def getPosition(carpeta_positions):
84
 
85
  async def exeCute(endpoint, image, prompt):
86
 
87
- print("Prompt to exeCute: ")
88
  print(prompt)
89
 
90
  temp_image = await imageToTemp(image)
@@ -117,11 +116,24 @@ async def exeCute(endpoint, image, prompt):
117
  return result[0]
118
 
119
  except Exception as e:
120
- print(f"Error: {e}")
121
- return {"error": "Unable to detect a face in the image. Please upload a different photo with a clear face."}
 
 
 
 
 
 
122
  finally:
123
  borrado = borraTemp(temp_image)
124
  print("El resultado de borrarTemp fue: ", borrado)
 
 
 
 
 
 
 
125
 
126
 
127
 
 
2
  import socket
3
  import random
4
  import globales
5
+ import time
6
  import tempfile
7
  import gradio_client
8
 
 
84
 
85
  async def exeCute(endpoint, image, prompt):
86
 
 
87
  print(prompt)
88
 
89
  temp_image = await imageToTemp(image)
 
116
  return result[0]
117
 
118
  except Exception as e:
119
+ print(f"Error en exeCute: {e}")
120
+ print("E es del tipo : ", type(e))
121
+ if "PAUSED" in str(e):
122
+ return {"error": "Space Paused"}
123
+ elif "timed out" in str(e):
124
+ return {"error": "Network error try again."}
125
+ else:
126
+ return {"error": "Face not detected, please try again or with other pic."}
127
  finally:
128
  borrado = borraTemp(temp_image)
129
  print("El resultado de borrarTemp fue: ", borrado)
130
+
131
+ def formaFilename(prompt):
132
+
133
+ timestamp_segundos = int(time.time())
134
+ print(f"Printed at: {timestamp_segundos}.")
135
+
136
+ return f"{prompt}-{timestamp_segundos}.jpg"
137
 
138
 
139
 
images/positions/all/Daredevil'sElektraNatchioswithtrinche-1740954016.jpg DELETED

Git LFS Details

  • SHA256: aea27d2f9e87c102836e5db37d7c6addf0d5753953f594f837f0aabf706f5c60
  • Pointer size: 131 Bytes
  • Size of remote file: 114 kB