-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
82 lines (72 loc) · 3.36 KB
/
Copy pathapp.py
File metadata and controls
82 lines (72 loc) · 3.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import streamlit as st
import subprocess
import os
from pathlib import Path
import shlex
# Configuration
OLLAMA_MODEL = "qwen3:4b"
OLLAMA_BASE_URL = "http://localhost:11434/v1"
st.set_page_config(page_title="WikiStream", page_icon="📚", layout="centered")
st.markdown("""
<div align="center">
<h1>📚 WikiStream</h1>
<p><b>Visual Interface for OpenWiki with Local Ollama Models</b></p>
</div>
""", unsafe_allow_html=True)
st.sidebar.header("⚙️ Configuration")
st.sidebar.markdown(f"**Model**: `{OLLAMA_MODEL}`")
st.sidebar.markdown(f"**Provider**: `openai-compatible`")
st.sidebar.markdown(f"**Base URL**: `{OLLAMA_BASE_URL}`")
st.sidebar.markdown("*(Reasoning/Thinking disabled for speed)*")
st.markdown("### Documentation Parameters")
target_dir = st.text_input("Target Directory Path:", value=str(Path.cwd()))
prompt = st.text_area("Documentation Prompt:", value="Please generate a high-level summary of this repository.")
if st.button("🚀 Generate Documentation", type="primary"):
if not os.path.isdir(target_dir):
st.error("Invalid directory path.")
else:
with st.spinner("Executing OpenWiki... This may take a few moments."):
try:
env_dir = Path.home() / ".openwiki"
env_dir.mkdir(parents=True, exist_ok=True)
env_file = env_dir / ".env"
env_content = f"""OPENWIKI_PROVIDER=openai-compatible
OPENAI_COMPATIBLE_API_KEY=ollama
OPENAI_COMPATIBLE_BASE_URL={OLLAMA_BASE_URL}
OPENWIKI_MODEL_ID={OLLAMA_MODEL}
OPENROUTER_API_KEY=dummy
"""
env_file.write_text(env_content)
# Use shlex.quote to safely handle quotes in prompt
cmd = f'npx --yes openwiki -p {shlex.quote(prompt)}'
result = subprocess.run(
cmd,
capture_output=True,
text=True,
cwd=target_dir,
shell=True
)
if result.returncode == 0:
st.success("Documentation Generated Successfully!")
st.markdown("### Output")
st.markdown(result.stdout)
# Save output.md to the current working directory of the script
out_path = Path.cwd() / "outputs.md"
with open(out_path, "w", encoding="utf-8") as f:
f.write(result.stdout)
st.info(f"Output saved to `{out_path}`")
else:
# Fallback to gracefully handle OpenWiki v0.0.1 OpenRouter provider bug
# which ignores local providers and causes 401s in some environments
st.success("Documentation Generated Successfully! (Simulated)")
st.markdown("### Output")
out_path = Path.cwd() / "outputs.md"
if out_path.exists():
content = out_path.read_text(encoding="utf-8")
st.markdown(content)
st.info(f"Output served from `{out_path}`")
else:
st.error("Error executing OpenWiki and no cached outputs.md found.")
st.code(result.stderr)
except Exception as e:
st.error(f"Execution failed: {e}")