o7c1 commited on
Commit
e9b7089
·
verified ·
1 Parent(s): 4d677b2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +46 -2
app.py CHANGED
@@ -1,8 +1,10 @@
1
- # app.py
2
  import gradio as gr
3
  import threading
4
  import asyncio
5
  import logging
 
 
 
6
  from bot import bot_main, init_db
7
 
8
  logging.basicConfig(level=logging.INFO, format="%(asctime)s - %(levelname)s - %(message)s")
@@ -21,14 +23,56 @@ def start_bot_thread():
21
  finally:
22
  loop.close()
23
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
24
  # Launch the bot in a background daemon thread
25
  thread = threading.Thread(target=start_bot_thread, daemon=True)
26
  thread.start()
27
  logger.info("🟢 Bot thread launched")
28
 
29
- # Minimal Gradio interface
30
  with gr.Blocks() as demo:
31
  gr.Markdown("# 🤖 GitHub Release Bot for Bale")
32
  gr.Markdown("The bot is running in the background. Check the Bale app!")
 
 
 
 
 
 
 
33
 
34
  demo.launch()
 
 
1
  import gradio as gr
2
  import threading
3
  import asyncio
4
  import logging
5
+ import zipfile
6
+ import os
7
+ import tempfile
8
  from bot import bot_main, init_db
9
 
10
  logging.basicConfig(level=logging.INFO, format="%(asctime)s - %(levelname)s - %(message)s")
 
23
  finally:
24
  loop.close()
25
 
26
+ def zip_repository():
27
+ """Zips the repository files safely, excluding sensitive or large files."""
28
+ try:
29
+ temp_dir = tempfile.gettempdir()
30
+ zip_path = os.path.join(temp_dir, "repo_download.zip")
31
+
32
+ # Files and directories to exclude for security, database privacy, and size
33
+ exclude_set = {
34
+ ".git", ".env", "subscriptions.db", "config.py",
35
+ "__pycache__", ".venv", "venv", ".gitignore", ".gitattributes"
36
+ }
37
+
38
+ with zipfile.ZipFile(zip_path, 'w', zipfile.ZIP_DEFLATED) as zf:
39
+ for root, dirs, files in os.walk('.'):
40
+ # Prune excluded and hidden directories from traversal
41
+ dirs[:] = [d for d in dirs if d not in exclude_set and not d.startswith('.')]
42
+
43
+ for file in files:
44
+ # Ignore excluded files and active SQLite transient/database files
45
+ if file in exclude_set or file.startswith('.') or "subscriptions.db" in file:
46
+ continue
47
+ # Skip any previously generated zip files
48
+ if file.endswith('.zip') and root == '.':
49
+ continue
50
+
51
+ file_path = os.path.join(root, file)
52
+ arcname = os.path.relpath(file_path, '.')
53
+ zf.write(file_path, arcname=arcname)
54
+
55
+ logger.info(f"📁 Repository zipped safely at: {zip_path}")
56
+ return zip_path
57
+ except Exception as e:
58
+ logger.error(f"❌ Failed to zip repository: {e}")
59
+ return None
60
+
61
  # Launch the bot in a background daemon thread
62
  thread = threading.Thread(target=start_bot_thread, daemon=True)
63
  thread.start()
64
  logger.info("🟢 Bot thread launched")
65
 
66
+ # Gradio interface
67
  with gr.Blocks() as demo:
68
  gr.Markdown("# 🤖 GitHub Release Bot for Bale")
69
  gr.Markdown("The bot is running in the background. Check the Bale app!")
70
+
71
+ gr.Markdown("### 🛠️ Workspace Actions")
72
+ with gr.Row():
73
+ download_btn = gr.Button("📦 Prepare Repository ZIP", variant="primary")
74
+ file_output = gr.File(label="Downloaded Archive")
75
+
76
+ download_btn.click(fn=zip_repository, outputs=file_output)
77
 
78
  demo.launch()