import time import gradio as gr import base64 from io import BytesIO from PIL import Image def encode_image_to_base64(image_path): with open(image_path, "rb") as image_file: encoded_string = base64.b64encode(image_file.read()).decode('utf-8') return encoded_string def slow_api_response(message, history): response_text = "Aquí tienes una imagen de la propiedad:" image_base64 = encode_image_to_base64("baño.jpeg") for i in range(len(response_text)): time.sleep(0.05) yield response_text[:i + 1] image = Image.open(BytesIO(base64.b64decode(image_base64))) yield image examples = [ ["Hola, quiero ver la propiedad", []], ["¿Tienen más fotos?", []] ] demo = gr.ChatInterface( fn=slow_api_response, examples=examples, title="Simulación de AI Assistant", description="muestra la imagen de la propiedad", ).launch()