Spaces:
Sleeping
Sleeping
File size: 1,006 Bytes
74766dd |
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 |
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.")
|