Spaces:
Running
Running
Upload 3 files
Browse files- README.md +19 -0
- requirements.txt +3 -0
- streamlit_app.py +19 -0
README.md
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
title: Code Explainer 💡
|
| 3 |
+
emoji: 🧠
|
| 4 |
+
colorFrom: blue
|
| 5 |
+
colorTo: indigo
|
| 6 |
+
sdk: streamlit
|
| 7 |
+
sdk_version: "1.35.0"
|
| 8 |
+
app_file: streamlit_app.py
|
| 9 |
+
pinned: false
|
| 10 |
+
---
|
| 11 |
+
|
| 12 |
+
# 🧠 Code Explainer (CodeT5-small)
|
| 13 |
+
|
| 14 |
+
This app uses `Salesforce/codet5-small` to generate natural language explanations of Python code snippets.
|
| 15 |
+
|
| 16 |
+
## How to Use
|
| 17 |
+
1. Paste Python code in the input box.
|
| 18 |
+
2. Click "Explain".
|
| 19 |
+
3. View the AI-generated explanation powered by a summarization-trained model.
|
requirements.txt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
transformers
|
| 2 |
+
torch
|
| 3 |
+
streamlit
|
streamlit_app.py
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
from model.model_utils import load_model, generate_explanation
|
| 3 |
+
|
| 4 |
+
st.set_page_config(page_title="Code Explainer", layout="centered")
|
| 5 |
+
|
| 6 |
+
st.title("🧠 Code Explainer (CodeT5-small)")
|
| 7 |
+
st.write("Paste your Python code below and get a natural language explanation:")
|
| 8 |
+
|
| 9 |
+
code_input = st.text_area("Paste Python Code", height=200)
|
| 10 |
+
|
| 11 |
+
if st.button("Explain"):
|
| 12 |
+
if code_input.strip():
|
| 13 |
+
with st.spinner("Generating explanation..."):
|
| 14 |
+
tokenizer, model = load_model()
|
| 15 |
+
explanation = generate_explanation(code_input, tokenizer, model)
|
| 16 |
+
st.subheader("✅ Explanation")
|
| 17 |
+
st.write(explanation)
|
| 18 |
+
else:
|
| 19 |
+
st.warning("Please paste some code to explain.")
|