Spaces:
Running
on
Zero
Running
on
Zero
Update Gradio app with multiple files
Browse files- app.py +10 -9
- requirements.txt +1 -1
app.py
CHANGED
|
@@ -170,27 +170,27 @@ def chat_fn(message: Dict[str, Any], history: List[List[Any]]) -> Tuple[str, Lis
|
|
| 170 |
|
| 171 |
return "", history
|
| 172 |
|
| 173 |
-
def retry_fn(history: List[
|
| 174 |
"""Retry the last message."""
|
| 175 |
-
if not history:
|
| 176 |
return "", history
|
| 177 |
|
| 178 |
# Remove last assistant response and regenerate
|
| 179 |
-
last_user_msg = history[-
|
| 180 |
history = history[:-1]
|
| 181 |
|
| 182 |
# Recreate the message dict
|
| 183 |
-
if isinstance(last_user_msg, dict):
|
| 184 |
-
message = {"text": last_user_msg.get("text", "")}
|
| 185 |
else:
|
| 186 |
-
message = {"text": last_user_msg}
|
| 187 |
|
| 188 |
return chat_fn(message, history)
|
| 189 |
|
| 190 |
-
def undo_fn(history: List[
|
| 191 |
"""Undo the last message."""
|
| 192 |
if history:
|
| 193 |
-
return history[:-
|
| 194 |
return history
|
| 195 |
|
| 196 |
def clear_fn() -> Tuple[None, List]:
|
|
@@ -245,7 +245,8 @@ with gr.Blocks(theme=gr.themes.Soft(), fill_height=True) as demo:
|
|
| 245 |
height=500,
|
| 246 |
show_copy_button=True,
|
| 247 |
bubble_full_width=False,
|
| 248 |
-
avatar_images=[None, "🤖"]
|
|
|
|
| 249 |
)
|
| 250 |
|
| 251 |
with gr.Row():
|
|
|
|
| 170 |
|
| 171 |
return "", history
|
| 172 |
|
| 173 |
+
def retry_fn(history: List[Dict[str, Any]]) -> Tuple[str, List[Dict[str, Any]]]:
|
| 174 |
"""Retry the last message."""
|
| 175 |
+
if not history or len(history) < 2:
|
| 176 |
return "", history
|
| 177 |
|
| 178 |
# Remove last assistant response and regenerate
|
| 179 |
+
last_user_msg = history[-2]
|
| 180 |
history = history[:-1]
|
| 181 |
|
| 182 |
# Recreate the message dict
|
| 183 |
+
if isinstance(last_user_msg["content"], dict):
|
| 184 |
+
message = {"text": last_user_msg["content"].get("text", "")}
|
| 185 |
else:
|
| 186 |
+
message = {"text": last_user_msg["content"]}
|
| 187 |
|
| 188 |
return chat_fn(message, history)
|
| 189 |
|
| 190 |
+
def undo_fn(history: List[Dict[str, Any]]) -> List[Dict[str, Any]]:
|
| 191 |
"""Undo the last message."""
|
| 192 |
if history:
|
| 193 |
+
return history[:-2] if len(history) >= 2 else []
|
| 194 |
return history
|
| 195 |
|
| 196 |
def clear_fn() -> Tuple[None, List]:
|
|
|
|
| 245 |
height=500,
|
| 246 |
show_copy_button=True,
|
| 247 |
bubble_full_width=False,
|
| 248 |
+
avatar_images=[None, "🤖"],
|
| 249 |
+
value=[]
|
| 250 |
)
|
| 251 |
|
| 252 |
with gr.Row():
|
requirements.txt
CHANGED
|
@@ -3,4 +3,4 @@ accelerate
|
|
| 3 |
torch
|
| 4 |
Pillow
|
| 5 |
numpy
|
| 6 |
-
torchvision
|
|
|
|
| 3 |
torch
|
| 4 |
Pillow
|
| 5 |
numpy
|
| 6 |
+
torchvision
|