Update app.py
Browse files
app.py
CHANGED
|
@@ -672,7 +672,7 @@ import zipfile
|
|
| 672 |
import shutil
|
| 673 |
|
| 674 |
def process_uploaded_file(file) -> str:
|
| 675 |
-
"""Extracts ZIPs
|
| 676 |
if file is None: return ""
|
| 677 |
|
| 678 |
file_path = file.name if hasattr(file, 'name') else str(file)
|
|
@@ -680,20 +680,31 @@ def process_uploaded_file(file) -> str:
|
|
| 680 |
upload_dir = Path("/workspace/uploads")
|
| 681 |
upload_dir.mkdir(parents=True, exist_ok=True)
|
| 682 |
|
|
|
|
| 683 |
if file_name.endswith('.zip'):
|
| 684 |
extract_path = upload_dir / file_name.replace('.zip', '')
|
| 685 |
extract_path.mkdir(parents=True, exist_ok=True)
|
| 686 |
-
|
| 687 |
try:
|
| 688 |
with zipfile.ZipFile(file_path, 'r') as z:
|
| 689 |
z.extractall(extract_path)
|
| 690 |
-
|
| 691 |
-
# Tell Clawdbot exactly where the files landed
|
| 692 |
-
return f"π¦ **ZIP Extracted to:** `{extract_path}`\nFiles are now physically available for tools to read/modify."
|
| 693 |
except Exception as e:
|
| 694 |
return f"β ZIP Error: {e}"
|
| 695 |
|
| 696 |
-
# Standard
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 697 |
|
| 698 |
# =============================================================================
|
| 699 |
# AGENTIC LOOP
|
|
@@ -1079,6 +1090,10 @@ with gr.Blocks(
|
|
| 1079 |
# ==== TAB 1: VIBE CHAT ====
|
| 1080 |
with gr.Tab("π¬ Vibe Chat"):
|
| 1081 |
with gr.Row():
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1082 |
# ---- Sidebar ----
|
| 1083 |
with gr.Column(scale=1, min_width=200):
|
| 1084 |
gr.Markdown("### π System Status")
|
|
|
|
| 672 |
import shutil
|
| 673 |
|
| 674 |
def process_uploaded_file(file) -> str:
|
| 675 |
+
"""Extracts ZIPs or reads text files to anchor memory in ground truth."""
|
| 676 |
if file is None: return ""
|
| 677 |
|
| 678 |
file_path = file.name if hasattr(file, 'name') else str(file)
|
|
|
|
| 680 |
upload_dir = Path("/workspace/uploads")
|
| 681 |
upload_dir.mkdir(parents=True, exist_ok=True)
|
| 682 |
|
| 683 |
+
# --- ZIP Handling ---
|
| 684 |
if file_name.endswith('.zip'):
|
| 685 |
extract_path = upload_dir / file_name.replace('.zip', '')
|
| 686 |
extract_path.mkdir(parents=True, exist_ok=True)
|
|
|
|
| 687 |
try:
|
| 688 |
with zipfile.ZipFile(file_path, 'r') as z:
|
| 689 |
z.extractall(extract_path)
|
| 690 |
+
return f"π¦ **ZIP Extracted to:** `{extract_path}`\nFiles are now available for tools."
|
|
|
|
|
|
|
| 691 |
except Exception as e:
|
| 692 |
return f"β ZIP Error: {e}"
|
| 693 |
|
| 694 |
+
# --- Standard File Handling (Restored) ---
|
| 695 |
+
suffix = os.path.splitext(file_name)[1].lower()
|
| 696 |
+
if suffix in TEXT_EXTENSIONS or suffix == '':
|
| 697 |
+
try:
|
| 698 |
+
with open(file_path, 'r', encoding='utf-8', errors='ignore') as f:
|
| 699 |
+
content = f.read()
|
| 700 |
+
if len(content) > 50000: content = content[:50000] + "\n... (truncated)"
|
| 701 |
+
return f"π **Uploaded: {file_name}**\n```\n{content}\n```"
|
| 702 |
+
except Exception as e:
|
| 703 |
+
return f"π **Uploaded: {file_name}** (Error reading: {e})"
|
| 704 |
+
return f"π **Uploaded: {file_name}** (Binary file ignored)"
|
| 705 |
+
|
| 706 |
+
|
| 707 |
+
# die Standard file handling remains the same...
|
| 708 |
|
| 709 |
# =============================================================================
|
| 710 |
# AGENTIC LOOP
|
|
|
|
| 1090 |
# ==== TAB 1: VIBE CHAT ====
|
| 1091 |
with gr.Tab("π¬ Vibe Chat"):
|
| 1092 |
with gr.Row():
|
| 1093 |
+
# Define the buttons before assigning clicks to them
|
| 1094 |
+
btn_exec = gr.Button("β
Execute Selected", variant="primary")
|
| 1095 |
+
btn_clear = gr.Button("ποΈ Clear All", variant="secondary")
|
| 1096 |
+
|
| 1097 |
# ---- Sidebar ----
|
| 1098 |
with gr.Column(scale=1, min_width=200):
|
| 1099 |
gr.Markdown("### π System Status")
|