Artificial-superintelligence commited on
Commit
e4a160c
·
verified ·
1 Parent(s): 63b8277

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +94 -60
app.py CHANGED
@@ -1,71 +1,105 @@
1
  import streamlit as st
2
- from googlesearch import search
3
- import requests
4
- from bs4 import BeautifulSoup
 
 
5
 
6
- # Function to fetch search results
7
- def fetch_search_results(query, num_results=5):
8
- results = []
9
- try:
10
- for url in search(query, num=num_results, stop=num_results, pause=2):
11
- results.append(url)
12
- except Exception as e:
13
- st.error(f"Error fetching search results: {e}")
14
- return results
15
 
16
- # Function to fetch website preview
17
- def fetch_website_preview(url):
18
  try:
19
- response = requests.get(url, timeout=5)
20
- soup = BeautifulSoup(response.content, "html.parser")
21
- title = soup.title.string if soup.title else "No title"
22
- return title, url
23
- except Exception as e:
24
- return "Error loading website", None
25
 
26
- # Mask IP address using proxy
27
- def secure_request(url, proxy=None):
28
- proxies = {"http": proxy, "https": proxy} if proxy else None
29
- try:
30
- response = requests.get(url, proxies=proxies, timeout=5)
31
- return response.status_code, response.content
32
- except Exception as e:
33
- return None, str(e)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
34
 
35
- # Streamlit app starts here
36
- st.title("Secure Chrome Search with IP Masking")
37
- st.write("Search the web securely, view results, and mask your IP address.")
38
 
39
- # User input
40
- query = st.text_input("Enter search query:", "")
 
41
 
42
- # Search results
43
- if query:
44
- st.write("Fetching search results...")
45
- results = fetch_search_results(query)
46
- if results:
47
- st.write("Top Results:")
48
- for idx, url in enumerate(results):
49
- st.markdown(f"{idx+1}. [Visit Site]({url})")
50
 
51
- # Select website to preview
52
- selected_url = st.selectbox("Select a website to preview:", results)
53
- if selected_url:
54
- st.write("Website Preview:")
55
- title, preview_url = fetch_website_preview(selected_url)
56
- st.write(f"**Title:** {title}")
57
- st.markdown(f"[Visit Site in Browser]({preview_url})")
 
 
 
 
 
 
 
 
 
 
 
58
  else:
59
- st.write("No results found.")
 
 
 
 
 
 
 
 
60
 
61
- # Mask IP section
62
- proxy = st.text_input("Enter proxy (e.g., http://<proxy-ip>:<port>):", "")
63
- if proxy:
64
- test_url = st.text_input("Enter URL to test secure connection:", "http://httpbin.org/ip")
65
- if st.button("Test Secure Connection"):
66
- status, response = secure_request(test_url, proxy=proxy)
67
- if status:
68
- st.success(f"Response Status: {status}")
69
- st.write(response.decode("utf-8"))
70
- else:
71
- st.error(f"Error: {response}")
 
1
  import streamlit as st
2
+ import subprocess
3
+ import os
4
+ import shutil
5
+ import uuid
6
+ from pathlib import Path
7
 
8
+ # Generate a unique workspace for the user
9
+ session_id = str(uuid.uuid4())
10
+ workspace_dir = f"temp_workspace_{session_id}"
11
+ Path(workspace_dir).mkdir(parents=True, exist_ok=True)
 
 
 
 
 
12
 
13
+ # Helper function to execute shell commands
14
+ def run_shell_command(command):
15
  try:
16
+ result = subprocess.check_output(command, shell=True, stderr=subprocess.STDOUT, text=True)
17
+ return result
18
+ except subprocess.CalledProcessError as e:
19
+ return f"Error: {e.output}"
 
 
20
 
21
+ # Custom CSS for styling
22
+ st.markdown(
23
+ """
24
+ <style>
25
+ .stButton>button {
26
+ background-color: #4CAF50;
27
+ color: white;
28
+ border: none;
29
+ padding: 10px 20px;
30
+ text-align: center;
31
+ text-decoration: none;
32
+ font-size: 16px;
33
+ margin: 4px 2px;
34
+ cursor: pointer;
35
+ border-radius: 5px;
36
+ }
37
+ .stButton>button:hover {
38
+ background-color: #45a049;
39
+ }
40
+ textarea {
41
+ font-family: "Courier New", monospace;
42
+ font-size: 14px;
43
+ }
44
+ </style>
45
+ """,
46
+ unsafe_allow_html=True,
47
+ )
48
+
49
+ st.title("Advanced Streamlit IDE")
50
+
51
+ # Editor for writing Python code
52
+ st.subheader("Code Editor")
53
+ default_code = """import streamlit as st
54
 
55
+ st.title("Welcome to the Advanced Streamlit IDE!")
56
+ st.write("Start coding your Python project here.")"""
57
+ code = st.text_area("Write your Python code below:", value=default_code, height=300)
58
 
59
+ # Option to install packages
60
+ st.subheader("Install Python Packages")
61
+ packages = st.text_input("Enter package names separated by space (e.g., numpy pandas):")
62
 
63
+ if st.button("Install Packages"):
64
+ with st.spinner("Installing packages..."):
65
+ install_command = f"pip install --target={workspace_dir} {packages}"
66
+ install_output = run_shell_command(install_command)
67
+ st.text(install_output)
 
 
 
68
 
69
+ # Run the code in a temporary workspace
70
+ if st.button("Run Code"):
71
+ temp_file_path = os.path.join(workspace_dir, "temp_app.py")
72
+ with open(temp_file_path, "w") as temp_file:
73
+ temp_file.write(code)
74
+
75
+ with st.spinner("Running your code..."):
76
+ run_command = f"PYTHONPATH={workspace_dir} python {temp_file_path}"
77
+ run_output = run_shell_command(run_command)
78
+ st.text(run_output)
79
+
80
+ # Export code
81
+ if st.button("Export Code"):
82
+ temp_file_path = os.path.join(workspace_dir, "temp_app.py")
83
+ if os.path.exists(temp_file_path):
84
+ with open(temp_file_path, "r") as temp_file:
85
+ exported_code = temp_file.read()
86
+ st.download_button("Download Code", data=exported_code, file_name="exported_code.py", mime="text/plain")
87
  else:
88
+ st.error("No code to export!")
89
+
90
+ # Cleanup workspace on session end
91
+ def cleanup_workspace():
92
+ if os.path.exists(workspace_dir):
93
+ shutil.rmtree(workspace_dir)
94
+
95
+ # Streamlit lifecycle hook for cleanup
96
+ st.on_event("teardown", cleanup_workspace)
97
 
98
+ st.markdown("---")
99
+ st.info(
100
+ """
101
+ - Write and execute Python code in a temporary workspace.
102
+ - Install and use packages dynamically within your session.
103
+ - All data is deleted once you leave the site.
104
+ """
105
+ )