File size: 833 Bytes
8bcd716
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import streamlit as st
from model.model_utils import load_model, generate_explanation
from app.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)
            explanation = generate_explanation(prompt, tokenizer, model, device)
            st.subheader("📝 Explanation")
            st.write(explanation.split("Explanation:")[-1].strip())
    else:
        st.warning("Please paste some code to explain.")