Spaces:
Running
Running
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,45 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import subprocess
|
3 |
+
|
4 |
+
def install_package(package_name):
|
5 |
+
command = f"pip install {package_name}"
|
6 |
+
process = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
7 |
+
stdout, stderr = process.communicate()
|
8 |
+
if process.returncode == 0:
|
9 |
+
return True, stdout.decode()
|
10 |
+
else:
|
11 |
+
return False, stderr.decode()
|
12 |
+
|
13 |
+
def main():
|
14 |
+
st.title("Пакетный менеджер")
|
15 |
+
|
16 |
+
with st.form("command_form"):
|
17 |
+
command_input = st.text_input("Введите команду")
|
18 |
+
submit_button = st.form_submit_button("Выполнить")
|
19 |
+
|
20 |
+
if submit_button:
|
21 |
+
if command_input.startswith("установи "):
|
22 |
+
package_name = command_input.split("установи ")[1]
|
23 |
+
success, output = install_package(package_name)
|
24 |
+
if success:
|
25 |
+
st.success(f"Пакет '{package_name}' успешно установлен!")
|
26 |
+
else:
|
27 |
+
st.error(f"Ошибка при установке пакета '{package_name}':\n{output}")
|
28 |
+
|
29 |
+
st.subheader("Консоль")
|
30 |
+
|
31 |
+
console_output = st.empty()
|
32 |
+
|
33 |
+
if st.button("Очистить"):
|
34 |
+
console_output.text("")
|
35 |
+
|
36 |
+
if st.button("Выполнить"):
|
37 |
+
command = console_output.text_area("Введите команду", key="console_input")
|
38 |
+
if command:
|
39 |
+
process = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
40 |
+
stdout, stderr = process.communicate()
|
41 |
+
output = stdout.decode() + stderr.decode()
|
42 |
+
console_output.text(output)
|
43 |
+
|
44 |
+
if __name__ == "__main__":
|
45 |
+
main()
|