Claude-Code-Local-Qwen / app_claude_code_gui.py
Tsitsi19's picture
Initial deployment of Claude Code with Qwen local
de2a5d3 verified
Raw
History Blame Contribute Delete
3.18 kB
import streamlit as st
import subprocess
import threading
import queue
import os
import sys
st.set_page_config(page_title="Claude Code Web UI", page_icon="πŸ’»")
st.title("πŸ’» Claude Code Web UI")
st.markdown("Interface pour Claude Code avec Qwen2.5-Coder-7B (GGUF) local")
if "messages" not in st.session_state:
st.session_state.messages = []
for message in st.session_state.messages:
with st.chat_message(message["role"]):
st.markdown(message["content"])
def run_command(command, output_queue):
try:
# Ensure claude-code uses the local LLM server
# This might require setting environment variables or a config file for claude-code
# For now, we assume claude-code can be configured to use an OpenAI-compatible endpoint
# or we might need to modify its source/config if it's hardcoded to Anthropic API.
# Let's try to pass the API base URL as an environment variable if claude-code supports it.
# If not, this part will need further investigation.
# For demonstration, we'll just run a simple command or simulate claude-code interaction.
# A real integration would involve piping input/output to the claude-code CLI.
# Example: running a simple shell command for now
process = subprocess.Popen(
command,
shell=True,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
text=True,
bufsize=1
)
for line in iter(process.stdout.readline, ""):
output_queue.put(line)
process.stdout.close()
process.wait()
output_queue.put(None)
except Exception as e:
output_queue.put(f"Error executing command: {e}\n")
output_queue.put(None)
if prompt := st.chat_input("Entrez votre commande Claude Code ou shell..."):
st.session_state.messages.append({"role": "user", "content": prompt})
with st.chat_message("user"):
st.markdown(prompt)
with st.chat_message("assistant"):
response_placeholder = st.empty()
full_response = ""
output_queue = queue.Queue()
# Prepend 'claude-code' if the user just types a command, or allow direct shell commands
command_to_run = prompt
if not prompt.startswith("claude-code") and not prompt.startswith("npm") and not prompt.startswith("python") and not prompt.startswith("ls"):
command_to_run = f"claude-code {prompt}"
thread = threading.Thread(target=run_command, args=([command_to_run], output_queue))
thread.start()
while True:
try:
line = output_queue.get(timeout=1)
if line is None:
break
full_response += line
response_placeholder.markdown(f"```bash\n{full_response}β–Œ\n```")
except queue.Empty:
if not thread.is_alive():
break
continue
response_placeholder.markdown(f"```bash\n{full_response}\n```")
st.session_state.messages.append({"role": "assistant", "content": full_response})