code-explainer-c / streamlit_app.py
SandeepU's picture
Upload 4 files
74766dd verified
raw
history blame
1.01 kB
import streamlit as st
from model.model_utils import load_model, generate_explanation
from prompt_utils import build_prompt
st.set_page_config(page_title="Code Explainer", layout="centered")
st.title("🧠 Code Explainer")
st.write("Paste your Python code below and get a plain English explanation:")
code_input = st.text_area("Paste Python Code", height=200)
if st.button("Explain"):
if code_input.strip():
with st.spinner("Generating explanation..."):
tokenizer, model, device = load_model()
prompt = build_prompt(code_input)
st.subheader("πŸ” Prompt Sent to Model")
st.code(prompt)
explanation = generate_explanation(prompt, tokenizer, model, device)
st.subheader("πŸ“ Raw Output from Model")
st.code(explanation)
st.subheader("βœ… Final Explanation")
st.write(explanation.split("Explanation:")[-1].strip())
else:
st.warning("Please paste some code to explain.")