Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -33,7 +33,6 @@ model = genai.GenerativeModel(
|
|
33 |
chat = model.start_chat(history=[])
|
34 |
|
35 |
# Constantes para el manejo de im谩genes
|
36 |
-
IMAGE_CACHE_DIRECTORY = "/tmp"
|
37 |
IMAGE_WIDTH = 512
|
38 |
CHAT_HISTORY = List[Tuple[Optional[Union[Tuple[str], str]], Optional[str]]]
|
39 |
|
@@ -44,15 +43,6 @@ def preprocess_image(image: Image.Image) -> Optional[Image.Image]:
|
|
44 |
image_height = int(image.height * IMAGE_WIDTH / image.width)
|
45 |
return image.resize((IMAGE_WIDTH, image_height))
|
46 |
|
47 |
-
# Funci贸n para almacenar una imagen en cach茅
|
48 |
-
def cache_pil_image(image: Image.Image) -> str:
|
49 |
-
"""Guarda la imagen como archivo JPEG en un directorio temporal."""
|
50 |
-
image_filename = f"{uuid.uuid4()}.jpeg"
|
51 |
-
os.makedirs(IMAGE_CACHE_DIRECTORY, exist_ok=True)
|
52 |
-
image_path = os.path.join(IMAGE_CACHE_DIRECTORY, image_filename)
|
53 |
-
image.save(image_path, "JPEG")
|
54 |
-
return image_path
|
55 |
-
|
56 |
# Funci贸n para transformar el historial de Gradio al formato de Gemini
|
57 |
def transform_history(history):
|
58 |
"""Transforma el historial del formato de Gradio al formato que Gemini espera."""
|
@@ -83,12 +73,9 @@ def response(message, history):
|
|
83 |
image = Image.open(file).convert('RGB')
|
84 |
image_preview = preprocess_image(image)
|
85 |
if image_preview:
|
86 |
-
# Guardar la imagen y obtener la ruta
|
87 |
-
image_path = cache_pil_image(image)
|
88 |
-
# Leer la imagen en formato binario para enviarla como Blob
|
89 |
-
with open(image_path, "rb") as img_file:
|
90 |
-
img_data = img_file.read()
|
91 |
# Crear un diccionario con los datos binarios y su tipo MIME
|
|
|
|
|
92 |
image_prompt = {
|
93 |
"mime_type": "image/jpeg",
|
94 |
"data": img_data
|
|
|
33 |
chat = model.start_chat(history=[])
|
34 |
|
35 |
# Constantes para el manejo de im谩genes
|
|
|
36 |
IMAGE_WIDTH = 512
|
37 |
CHAT_HISTORY = List[Tuple[Optional[Union[Tuple[str], str]], Optional[str]]]
|
38 |
|
|
|
43 |
image_height = int(image.height * IMAGE_WIDTH / image.width)
|
44 |
return image.resize((IMAGE_WIDTH, image_height))
|
45 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
46 |
# Funci贸n para transformar el historial de Gradio al formato de Gemini
|
47 |
def transform_history(history):
|
48 |
"""Transforma el historial del formato de Gradio al formato que Gemini espera."""
|
|
|
73 |
image = Image.open(file).convert('RGB')
|
74 |
image_preview = preprocess_image(image)
|
75 |
if image_preview:
|
|
|
|
|
|
|
|
|
|
|
76 |
# Crear un diccionario con los datos binarios y su tipo MIME
|
77 |
+
with open(file, "rb") as img_file:
|
78 |
+
img_data = img_file.read()
|
79 |
image_prompt = {
|
80 |
"mime_type": "image/jpeg",
|
81 |
"data": img_data
|