import streamlit as st from transformers import pipeline # Load the code explainer pipeline @st.cache_resource def load_model(): return pipeline("text2text-generation", model="philschmid/code-explainer", device=-1) explainer = load_model() # Streamlit UI st.title("🧠 Code Explainer (Hugging Face)") st.markdown("Paste any code snippet below (Python, JavaScript, etc.) and get a plain-English explanation using a Hugging Face model.") code_input = st.text_area("📝 Paste your code here:", height=200) if st.button("Explain Code"): if code_input.strip() == "": st.warning("Please paste some code to explain.") else: with st.spinner("Explaining your code..."): result = explainer(f"Explain this code: {code_input}") explanation = result[0]['generated_text'] st.success("✅ Explanation:") st.write(explanation)