-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
41 lines (34 loc) · 1.58 KB
/
app.py
File metadata and controls
41 lines (34 loc) · 1.58 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
import streamlit as st
from core.analysis_utils import analyze_code_structure
from core.ai_providers import get_explanation
st.set_page_config(page_title="AI Decoder", page_icon="🧠", layout="wide")
st.title("🧠 AI Code Decoder (Reliable Edition)")
st.caption("OpenAI → Ollama fallback • Safe JSON parsing • Long timeout • Health check")
with st.sidebar:
st.header("AI Settings")
provider = st.selectbox("Provider", ["openai", "ollama"])
model = st.text_input("Model", "gpt-4o-mini")
detail = st.selectbox("Detail Level", ["low","medium","high"], index=2)
mode = st.selectbox("Study Mode", ["explanation_only","explanation_plus_quiz","quiz_only"], index=1)
temp = st.slider("Temperature", 0.0, 1.0, 0.2)
openai = st.text_input("OpenAI key", type="password")
ollama = st.text_input("Ollama URL", "http://localhost:11434")
extra = st.text_area("Extra instructions")
st.subheader("1️⃣ Code Input")
code = st.text_area("Python code", height=260, placeholder="Paste code here...")
file = st.file_uploader("Or upload a Python file", type=["py"])
if file:
try:
code = file.read().decode("utf-8")
st.info(f"Loaded {file.name}")
except:
st.error("Invalid file (must be UTF-8)")
if code.strip():
st.subheader("2️⃣ Code Stats")
st.write(analyze_code_structure(code))
st.subheader("3️⃣ AI Output")
if st.button("Run"):
out = get_explanation(provider, model, code, detail, mode, extra,
temperature=temp, openai_api_key=openai,
ollama_base_url=ollama)
st.markdown(out)