|
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") |
|
|
|
|
|
html_image = f'<img src="data:image/jpeg;base64,{image_base64}" alt="Imagen de la propiedad" width="300"/>' |
|
|
|
|
|
for i in range(len(response_text)): |
|
time.sleep(0.05) |
|
yield response_text[:i + 1] |
|
|
|
|
|
yield html_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 en el chat como HTML.", |
|
).launch() |
|
|