pripro commited on
Commit
20ed2ea
·
verified ·
1 Parent(s): 61b962d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -19
app.py CHANGED
@@ -4,7 +4,6 @@ import sys
4
  import socket
5
  import datetime
6
  import json
7
- import shutil
8
 
9
  # =====================================================================
10
  # STRICT /px DIRECTORY ARCHITECTURE & ENVIRONMENT SETUP
@@ -28,12 +27,10 @@ if not os.path.exists(global_context_path):
28
  with open(global_context_path, "w") as f:
29
  f.write("# Global Context & Browser Workspace\nShared knowledge base accessible across all connected IP environments under /px.")
30
 
31
- # Pin stable Gradio 4.x to prevent signature mismatch errors
32
- required_packages = ["gradio==4.44.1", "requests", "ollama", "beautifulsoup4"]
33
- for package in required_packages:
34
  try:
35
- pkg_name = package.split("==")[0]
36
- __import__(pkg_name)
37
  except ImportError:
38
  print(f"Installing missing dependency: {package}...")
39
  subprocess.check_call([sys.executable, "-m", "pip", "install", "-q", package])
@@ -91,7 +88,7 @@ tools_definition = [
91
  'type': 'function',
92
  'function': {
93
  'name': 'bash',
94
- 'description': 'Execute shell commands in the workspace environment. Allows running system tools, compilation, git, tests, etc.',
95
  'parameters': {
96
  'type': 'object',
97
  'properties': {'command': {'type': 'string', 'description': 'The shell command to execute.'}},
@@ -118,7 +115,7 @@ tools_definition = [
118
  'type': 'function',
119
  'function': {
120
  'name': 'read_file',
121
- 'description': 'Read content from a file (supports big context parsing for large codebases and logs).',
122
  'parameters': {
123
  'type': 'object',
124
  'properties': {'filepath': {'type': 'string', 'description': 'File path to read.'}},
@@ -130,7 +127,7 @@ tools_definition = [
130
  'type': 'function',
131
  'function': {
132
  'name': 'web_search',
133
- 'description': 'Search the live web for technical documentation, code snippets, or real-time data.',
134
  'parameters': {
135
  'type': 'object',
136
  'properties': {'query': {'type': 'string', 'description': 'Search query string.'}},
@@ -146,10 +143,9 @@ def execute_tool(name, args, ip_folder, yolo_mode):
146
  if name == "bash":
147
  cmd = args.get("command", "")
148
  if not yolo_mode and any(danger in cmd for danger in ["rm -rf /", "mkfs", "dd if="]):
149
- return "Error: Command blocked by YOLO Security Mode (Sandbox active)."
150
  res = subprocess.run(cmd, shell=True, capture_output=True, text=True, cwd=ip_folder, timeout=30)
151
- output = res.stdout if res.returncode == 0 else f"STDOUT:\n{res.stdout}\nSTDERR:\n{res.stderr}"
152
- return output[:6000]
153
 
154
  elif name == "write_file":
155
  filepath = args.get("filepath")
@@ -176,10 +172,8 @@ def execute_tool(name, args, ip_folder, yolo_mode):
176
  headers = {"User-Agent": "Mozilla/5.0"}
177
  resp = requests.get(url, headers=headers, timeout=10)
178
  soup = BeautifulSoup(resp.text, "html.parser")
179
- results = []
180
- for a in soup.find_all("a", class_="result__snippet", limit=6):
181
- results.append(a.get_text(strip=True))
182
- return "\n".join(results) if results else "No direct search snippets retrieved."
183
 
184
  else:
185
  return f"Error: Unknown tool '{name}'"
@@ -294,9 +288,9 @@ def update_global_context(new_content):
294
  return "Global context updated successfully under /px!"
295
 
296
  # =====================================================================
297
- # GRADIO WEB INTERFACE
298
  # =====================================================================
299
- with gr.Blocks(theme=gr.themes.Soft(primary_hue="cyan", secondary_hue="blue"), css=custom_css) as demo:
300
  gr.Markdown(
301
  """
302
  # ⚡ EVAL BETA 0.2 | PX TECH SOLUTIONS (AGENTIC OPENCODE ENVIRONMENT)
@@ -347,4 +341,10 @@ with gr.Blocks(theme=gr.themes.Soft(primary_hue="cyan", secondary_hue="blue"), c
347
  if __name__ == "__main__":
348
  print(f"🚀 Launching agentic environment under {BASE_DIR} with Slot 1 Queue & Full Tools on port 7860...")
349
  demo.queue(default_concurrency_limit=1, max_size=20)
350
- demo.launch(server_name="0.0.0.0", server_port=7860)
 
 
 
 
 
 
 
4
  import socket
5
  import datetime
6
  import json
 
7
 
8
  # =====================================================================
9
  # STRICT /px DIRECTORY ARCHITECTURE & ENVIRONMENT SETUP
 
27
  with open(global_context_path, "w") as f:
28
  f.write("# Global Context & Browser Workspace\nShared knowledge base accessible across all connected IP environments under /px.")
29
 
30
+ # Zero-dependency auto-bootstrapper
31
+ for package in ["gradio", "requests", "ollama", "beautifulsoup4"]:
 
32
  try:
33
+ __import__(package)
 
34
  except ImportError:
35
  print(f"Installing missing dependency: {package}...")
36
  subprocess.check_call([sys.executable, "-m", "pip", "install", "-q", package])
 
88
  'type': 'function',
89
  'function': {
90
  'name': 'bash',
91
+ 'description': 'Execute shell commands in the workspace environment.',
92
  'parameters': {
93
  'type': 'object',
94
  'properties': {'command': {'type': 'string', 'description': 'The shell command to execute.'}},
 
115
  'type': 'function',
116
  'function': {
117
  'name': 'read_file',
118
+ 'description': 'Read content from a file (supports big context parsing).',
119
  'parameters': {
120
  'type': 'object',
121
  'properties': {'filepath': {'type': 'string', 'description': 'File path to read.'}},
 
127
  'type': 'function',
128
  'function': {
129
  'name': 'web_search',
130
+ 'description': 'Search the live web for technical documentation or code snippets.',
131
  'parameters': {
132
  'type': 'object',
133
  'properties': {'query': {'type': 'string', 'description': 'Search query string.'}},
 
143
  if name == "bash":
144
  cmd = args.get("command", "")
145
  if not yolo_mode and any(danger in cmd for danger in ["rm -rf /", "mkfs", "dd if="]):
146
+ return "Error: Command blocked by YOLO Security Mode."
147
  res = subprocess.run(cmd, shell=True, capture_output=True, text=True, cwd=ip_folder, timeout=30)
148
+ return (res.stdout if res.returncode == 0 else f"STDOUT:\n{res.stdout}\nSTDERR:\n{res.stderr}")[:6000]
 
149
 
150
  elif name == "write_file":
151
  filepath = args.get("filepath")
 
172
  headers = {"User-Agent": "Mozilla/5.0"}
173
  resp = requests.get(url, headers=headers, timeout=10)
174
  soup = BeautifulSoup(resp.text, "html.parser")
175
+ results = [a.get_text(strip=True) for a in soup.find_all("a", class_="result__snippet", limit=6)]
176
+ return "\n".join(results) if results else "No search snippets retrieved."
 
 
177
 
178
  else:
179
  return f"Error: Unknown tool '{name}'"
 
288
  return "Global context updated successfully under /px!"
289
 
290
  # =====================================================================
291
+ # GRADIO 6 COMPATIBLE WEB INTERFACE
292
  # =====================================================================
293
+ with gr.Blocks() as demo:
294
  gr.Markdown(
295
  """
296
  # ⚡ EVAL BETA 0.2 | PX TECH SOLUTIONS (AGENTIC OPENCODE ENVIRONMENT)
 
341
  if __name__ == "__main__":
342
  print(f"🚀 Launching agentic environment under {BASE_DIR} with Slot 1 Queue & Full Tools on port 7860...")
343
  demo.queue(default_concurrency_limit=1, max_size=20)
344
+ # Gradio 6 compliant theme and css passed directly to launch()
345
+ demo.launch(
346
+ server_name="0.0.0.0",
347
+ server_port=7860,
348
+ theme=gr.themes.Soft(primary_hue="cyan", secondary_hue="blue"),
349
+ css=custom_css
350
+ )