Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
from transformers import pipeline
|
3 |
+
|
4 |
+
# Load the code explainer pipeline
|
5 |
+
@st.cache_resource
|
6 |
+
def load_model():
|
7 |
+
return pipeline("text2text-generation", model="philschmid/code-explainer", device=-1)
|
8 |
+
|
9 |
+
explainer = load_model()
|
10 |
+
|
11 |
+
# Streamlit UI
|
12 |
+
st.title("🧠 Code Explainer (Hugging Face)")
|
13 |
+
|
14 |
+
st.markdown("Paste any code snippet below (Python, JavaScript, etc.) and get a plain-English explanation using a Hugging Face model.")
|
15 |
+
|
16 |
+
code_input = st.text_area("📝 Paste your code here:", height=200)
|
17 |
+
|
18 |
+
if st.button("Explain Code"):
|
19 |
+
if code_input.strip() == "":
|
20 |
+
st.warning("Please paste some code to explain.")
|
21 |
+
else:
|
22 |
+
with st.spinner("Explaining your code..."):
|
23 |
+
result = explainer(f"Explain this code: {code_input}")
|
24 |
+
explanation = result[0]['generated_text']
|
25 |
+
st.success("✅ Explanation:")
|
26 |
+
st.write(explanation)
|