Spaces:
Configuration error
Configuration error
| 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.") | |