JuanMa360 commited on
Commit
24f3fdc
1 Parent(s): 6259580

Add application file

Browse files
Files changed (1) hide show
  1. app.py +36 -0
app.py ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import time
2
+ import gradio as gr
3
+ import base64
4
+ from io import BytesIO
5
+ from PIL import Image
6
+
7
+ def encode_image_to_base64(image_path):
8
+ with open(image_path, "rb") as image_file:
9
+ encoded_string = base64.b64encode(image_file.read()).decode('utf-8')
10
+ return encoded_string
11
+
12
+ def slow_api_response(message, history):
13
+
14
+ response_text = "Aquí tienes una imagen de la propiedad:"
15
+
16
+ image_base64 = encode_image_to_base64("baño.jpeg")
17
+
18
+ for i in range(len(response_text)):
19
+ time.sleep(0.05)
20
+ yield response_text[:i + 1]
21
+
22
+
23
+ image = Image.open(BytesIO(base64.b64decode(image_base64)))
24
+ yield image
25
+
26
+ examples = [
27
+ ["Hola, quiero ver la propiedad", []],
28
+ ["¿Tienen más fotos?", []]
29
+ ]
30
+
31
+ demo = gr.ChatInterface(
32
+ fn=slow_api_response,
33
+ examples=examples,
34
+ title="Simulación de AI Assistant",
35
+ description="muestra la imagen de la propiedad",
36
+ ).launch()