веб интерфейс для ai
Добавлено: 29 окт 2026, 07:01
Проблема в том, что `interpreter` установлен через **pipx** (глобально), а не в виртуальную среду. Нужно либо установить его в `interpreter_env`, либо использовать другой подход.
## Решение 1: Установить interpreter в виртуальную среду
```bash
source interpreter_env/bin/activate
pip install open-interpreter
python web_ui.py
```
## Решение 2: Использовать pipx окружение напрямую
Найдите Python из pipx:
```bash
ls ~/.local/share/pipx/venvs/
```
Должна быть папка вроде `open-interpreter`. Используйте её Python:
```bash
~/.local/share/pipx/venvs/open-interpreter/bin/python web_ui.py
```
## Решение 3: Более простой вариант — запустить Flask отдельно, взаимодействие через subprocess
Создайте `web_ui_v2.py`:
```python
from flask import Flask, render_template_string, request, jsonify
import subprocess
import json
app = Flask(__name__)
HTML_TEMPLATE = '''
<!DOCTYPE html>
<html>
<head>
<title>Local Interpreter Web UI</title>
<style>
body { font-family: monospace; margin: 20px; background: #1e1e1e; color: #ccc; }
.container { max-width: 900px; margin: 0 auto; }
h1 { color: #0ff; }
textarea { width: 100%; height: 250px; background: #333; color: #0f0; padding: 10px;
border: 1px solid #0f0; font-family: monospace; }
button { background: #0f0; color: #000; padding: 10px 20px; border: none; cursor: pointer; font-weight: bold; }
button:hover { background: #0ff; }
#output { background: #222; padding: 15px; margin-top: 20px; border: 1px solid #0f0;
min-height: 100px; white-space: pre-wrap; max-height: 400px; overflow-y: auto; }
.loading { display: none; color: #0ff; margin-left: 10px; }
</style>
</head>
<body>
<div class="container">
<h1>🖥️ Local Interpreter Web Interface</h1>
<textarea id="code" placeholder="Enter Python or shell commands..."></textarea>
<br><br>
<button onclick="runCode()">▶️ Execute</button>
<span class="loading" id="loading">Executing...</span>
<div id="output">Output will appear here...</div>
</div>
<script>
async function runCode() {
const code = document.getElementById('code').value;
if (!code.trim()) return alert('Enter some code!');
document.getElementById('loading').style.display = 'inline';
document.getElementById('output').textContent = 'Processing...';
try {
const response = await fetch('/api/execute', {
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({code: code})
});
const result = await response.json();
document.getElementById('output').textContent = result.output || result.error;
} catch (e) {
document.getElementById('output').textContent = 'Error: ' + e.message;
} finally {
document.getElementById('loading').style.display = 'none';
}
}
</script>
</body>
</html>
'''
@app.route('/')
def index():
return render_template_string(HTML_TEMPLATE)
@app.route('/api/execute', methods=['POST'])
def execute():
data = request.get_json()
code = data.get('code', '')
if not code.strip():
return jsonify({'error': 'Empty code'}), 400
try:
# Используем subprocess для вызова interpreter
result = subprocess.run(
['interpreter', '--local', '-y'],
input=code,
capture_output=True,
text=True,
timeout=30
)
output = result.stdout or result.stderr or "Command executed"
return jsonify({'output': output})
except subprocess.TimeoutExpired:
return jsonify({'error': 'Timeout: execution took too long'}), 400
except Exception as e:
return jsonify({'error': str(e)}), 400
if __name__ == '__main__':
print("🚀 Web Interface запущен на http://127.0.0.1:5000")
print("Нажмите Ctrl+C для остановки")
app.run(host='127.0.0.1', port=5000, debug=False)
```
Затем установите Flask в глобальный Python:
```bash
pip install flask
python web_ui_v2.py
```
Это будет работать, так как использует **subprocess** для вызова `/home/gt/.local/bin/interpreter`.
---
**Какой способ вам подходит больше?**
1. **Способ 1** — если хотите импортировать интерпретатор как модуль (чище, но требует установки)
2. **Способ 2** — если нужен минимум установок (использует уже установленный interpreter)
3. **Способ 3** — самый надёжный прямо сейчас
Рекомендую **Способ 1**, так как это будет работать лучше всего:
```bash
source interpreter_env/bin/activate
pip install open-interpreter flask
python web_ui.py
```
## Решение 1: Установить interpreter в виртуальную среду
```bash
source interpreter_env/bin/activate
pip install open-interpreter
python web_ui.py
```
## Решение 2: Использовать pipx окружение напрямую
Найдите Python из pipx:
```bash
ls ~/.local/share/pipx/venvs/
```
Должна быть папка вроде `open-interpreter`. Используйте её Python:
```bash
~/.local/share/pipx/venvs/open-interpreter/bin/python web_ui.py
```
## Решение 3: Более простой вариант — запустить Flask отдельно, взаимодействие через subprocess
Создайте `web_ui_v2.py`:
```python
from flask import Flask, render_template_string, request, jsonify
import subprocess
import json
app = Flask(__name__)
HTML_TEMPLATE = '''
<!DOCTYPE html>
<html>
<head>
<title>Local Interpreter Web UI</title>
<style>
body { font-family: monospace; margin: 20px; background: #1e1e1e; color: #ccc; }
.container { max-width: 900px; margin: 0 auto; }
h1 { color: #0ff; }
textarea { width: 100%; height: 250px; background: #333; color: #0f0; padding: 10px;
border: 1px solid #0f0; font-family: monospace; }
button { background: #0f0; color: #000; padding: 10px 20px; border: none; cursor: pointer; font-weight: bold; }
button:hover { background: #0ff; }
#output { background: #222; padding: 15px; margin-top: 20px; border: 1px solid #0f0;
min-height: 100px; white-space: pre-wrap; max-height: 400px; overflow-y: auto; }
.loading { display: none; color: #0ff; margin-left: 10px; }
</style>
</head>
<body>
<div class="container">
<h1>🖥️ Local Interpreter Web Interface</h1>
<textarea id="code" placeholder="Enter Python or shell commands..."></textarea>
<br><br>
<button onclick="runCode()">▶️ Execute</button>
<span class="loading" id="loading">Executing...</span>
<div id="output">Output will appear here...</div>
</div>
<script>
async function runCode() {
const code = document.getElementById('code').value;
if (!code.trim()) return alert('Enter some code!');
document.getElementById('loading').style.display = 'inline';
document.getElementById('output').textContent = 'Processing...';
try {
const response = await fetch('/api/execute', {
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({code: code})
});
const result = await response.json();
document.getElementById('output').textContent = result.output || result.error;
} catch (e) {
document.getElementById('output').textContent = 'Error: ' + e.message;
} finally {
document.getElementById('loading').style.display = 'none';
}
}
</script>
</body>
</html>
'''
@app.route('/')
def index():
return render_template_string(HTML_TEMPLATE)
@app.route('/api/execute', methods=['POST'])
def execute():
data = request.get_json()
code = data.get('code', '')
if not code.strip():
return jsonify({'error': 'Empty code'}), 400
try:
# Используем subprocess для вызова interpreter
result = subprocess.run(
['interpreter', '--local', '-y'],
input=code,
capture_output=True,
text=True,
timeout=30
)
output = result.stdout or result.stderr or "Command executed"
return jsonify({'output': output})
except subprocess.TimeoutExpired:
return jsonify({'error': 'Timeout: execution took too long'}), 400
except Exception as e:
return jsonify({'error': str(e)}), 400
if __name__ == '__main__':
print("🚀 Web Interface запущен на http://127.0.0.1:5000")
print("Нажмите Ctrl+C для остановки")
app.run(host='127.0.0.1', port=5000, debug=False)
```
Затем установите Flask в глобальный Python:
```bash
pip install flask
python web_ui_v2.py
```
Это будет работать, так как использует **subprocess** для вызова `/home/gt/.local/bin/interpreter`.
---
**Какой способ вам подходит больше?**
1. **Способ 1** — если хотите импортировать интерпретатор как модуль (чище, но требует установки)
2. **Способ 2** — если нужен минимум установок (использует уже установленный interpreter)
3. **Способ 3** — самый надёжный прямо сейчас
Рекомендую **Способ 1**, так как это будет работать лучше всего:
```bash
source interpreter_env/bin/activate
pip install open-interpreter flask
python web_ui.py
```