Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -37,6 +37,26 @@ IMAGE_CACHE_DIRECTORY = "/tmp"
|
|
37 |
IMAGE_WIDTH = 512
|
38 |
CHAT_HISTORY = List[Tuple[Optional[Union[Tuple[str], str]], Optional[str]]]
|
39 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
40 |
# Funci贸n para preprocesar una imagen
|
41 |
def preprocess_image(image: Image.Image) -> Optional[Image.Image]:
|
42 |
"""Redimensiona una imagen manteniendo la relaci贸n de aspecto."""
|
@@ -105,29 +125,31 @@ def response(message, history):
|
|
105 |
time.sleep(0.01)
|
106 |
yield response.text[: i + 1]
|
107 |
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
|
|
|
|
131 |
|
132 |
# Lanzar la aplicaci贸n
|
133 |
if __name__ == "__main__":
|
|
|
37 |
IMAGE_WIDTH = 512
|
38 |
CHAT_HISTORY = List[Tuple[Optional[Union[Tuple[str], str]], Optional[str]]]
|
39 |
|
40 |
+
# Estado para almacenar 铆ndices votados
|
41 |
+
INDEX_STATE = []
|
42 |
+
|
43 |
+
# Funci贸n para votar
|
44 |
+
def vote(tmp, index_state, data: gr.LikeData):
|
45 |
+
"""Procesa y guarda las interacciones de retroalimentaci贸n."""
|
46 |
+
value_new = data.value
|
47 |
+
index_new = data.index
|
48 |
+
if len(index_state) == 0:
|
49 |
+
index_state.append(index_new)
|
50 |
+
else:
|
51 |
+
if index_new in index_state:
|
52 |
+
return "Your feedback is already saved", index_state
|
53 |
+
else:
|
54 |
+
index_state.append(index_new)
|
55 |
+
return (
|
56 |
+
f"Feedback saved: Value={data.value}, Index={data.index}, Liked={data.liked}, State={index_state}",
|
57 |
+
index_state,
|
58 |
+
)
|
59 |
+
|
60 |
# Funci贸n para preprocesar una imagen
|
61 |
def preprocess_image(image: Image.Image) -> Optional[Image.Image]:
|
62 |
"""Redimensiona una imagen manteniendo la relaci贸n de aspecto."""
|
|
|
125 |
time.sleep(0.01)
|
126 |
yield response.text[: i + 1]
|
127 |
|
128 |
+
# Crear la interfaz de usuario con retroalimentaci贸n
|
129 |
+
demo = gr.Blocks()
|
130 |
+
|
131 |
+
with demo:
|
132 |
+
with gr.Row():
|
133 |
+
gr.Markdown("## Chat con Gemini + Votaci贸n")
|
134 |
+
chatbot = gr.Chatbot(label="Chat con Gemini")
|
135 |
+
with gr.Row():
|
136 |
+
message = gr.Textbox(label="Mensaje")
|
137 |
+
send_button = gr.Button("Enviar")
|
138 |
+
with gr.Row():
|
139 |
+
like_button = gr.LikeButton()
|
140 |
+
feedback_output = gr.Textbox(label="Retroalimentaci贸n", interactive=False)
|
141 |
+
|
142 |
+
# Acciones
|
143 |
+
send_button.click(
|
144 |
+
fn=response,
|
145 |
+
inputs=[message, chatbot],
|
146 |
+
outputs=chatbot,
|
147 |
+
)
|
148 |
+
like_button.click(
|
149 |
+
fn=vote,
|
150 |
+
inputs=[None, INDEX_STATE, like_button],
|
151 |
+
outputs=[feedback_output, INDEX_STATE],
|
152 |
+
)
|
153 |
|
154 |
# Lanzar la aplicaci贸n
|
155 |
if __name__ == "__main__":
|