Spaces:
Running
Running
File size: 895 Bytes
789250e |
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 |
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)
|