Update app.py
Browse files
app.py
CHANGED
|
@@ -54,32 +54,40 @@ def extract_text_from_pdf(pdf_file):
|
|
| 54 |
def generate_image(description):
|
| 55 |
try:
|
| 56 |
client = genai.Client(api_key=GEMINI_API_KEY)
|
| 57 |
-
|
| 58 |
# Suponiendo que la API de Gemini tiene un endpoint para generar imágenes
|
| 59 |
-
model = "gemini-
|
| 60 |
contents = [
|
| 61 |
types.Content(
|
| 62 |
role="user",
|
| 63 |
parts=[types.Part.from_text(text=description)],
|
| 64 |
),
|
| 65 |
]
|
|
|
|
|
|
|
| 66 |
generate_content_config = types.GenerateContentConfig(
|
| 67 |
temperature=0.7,
|
| 68 |
top_p=0.95,
|
| 69 |
top_k=64,
|
| 70 |
-
max_output_tokens=
|
| 71 |
-
response_mime_type="image/png", #
|
| 72 |
)
|
| 73 |
|
|
|
|
| 74 |
response_image_url = ""
|
| 75 |
for chunk in client.models.generate_content_stream(
|
| 76 |
model=model,
|
| 77 |
contents=contents,
|
| 78 |
config=generate_content_config,
|
| 79 |
):
|
| 80 |
-
response_image_url += chunk.text #
|
| 81 |
|
| 82 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 83 |
except Exception as e:
|
| 84 |
return f"Se produjo un error al generar la imagen: {e}"
|
| 85 |
|
|
|
|
| 54 |
def generate_image(description):
|
| 55 |
try:
|
| 56 |
client = genai.Client(api_key=GEMINI_API_KEY)
|
| 57 |
+
|
| 58 |
# Suponiendo que la API de Gemini tiene un endpoint para generar imágenes
|
| 59 |
+
model = "gemini-image-model" # Suponiendo que este es el modelo correcto
|
| 60 |
contents = [
|
| 61 |
types.Content(
|
| 62 |
role="user",
|
| 63 |
parts=[types.Part.from_text(text=description)],
|
| 64 |
),
|
| 65 |
]
|
| 66 |
+
|
| 67 |
+
# Configuración de la generación de imágenes, puedes ajustar estos parámetros
|
| 68 |
generate_content_config = types.GenerateContentConfig(
|
| 69 |
temperature=0.7,
|
| 70 |
top_p=0.95,
|
| 71 |
top_k=64,
|
| 72 |
+
max_output_tokens=2048, # Reducir los tokens si es necesario
|
| 73 |
+
response_mime_type="image/png", # Ajustar a "image/jpeg" si la API lo requiere
|
| 74 |
)
|
| 75 |
|
| 76 |
+
# Suponiendo que la API devuelva una URL de la imagen
|
| 77 |
response_image_url = ""
|
| 78 |
for chunk in client.models.generate_content_stream(
|
| 79 |
model=model,
|
| 80 |
contents=contents,
|
| 81 |
config=generate_content_config,
|
| 82 |
):
|
| 83 |
+
response_image_url += chunk.text # Se supone que aquí obtenemos la URL de la imagen generada
|
| 84 |
|
| 85 |
+
# Verifica si obtuviste una URL
|
| 86 |
+
if response_image_url:
|
| 87 |
+
return response_image_url
|
| 88 |
+
else:
|
| 89 |
+
return "No se pudo generar la imagen, la respuesta está vacía."
|
| 90 |
+
|
| 91 |
except Exception as e:
|
| 92 |
return f"Se produjo un error al generar la imagen: {e}"
|
| 93 |
|