|
import streamlit as st |
|
from transformers import pipeline |
|
|
|
|
|
st.title("CodeWise - AI-based Code Commenting Tool") |
|
st.subheader("Paste your code below, and the AI will generate comments explaining it!") |
|
|
|
|
|
code_input = st.text_area("Paste your code here:", height=300) |
|
|
|
|
|
comment_length = st.slider("Select the comment length", min_value=50, max_value=300, value=150, step=10) |
|
|
|
|
|
if st.button("Generate Comments"): |
|
if code_input.strip() == "": |
|
st.warning("Please paste some code before generating comments.") |
|
else: |
|
|
|
generator = pipeline("text2text-generation", model="Salesforce/codet5-base-multi-sum") |
|
|
|
|
|
prompt = f"Comment this code:\n\n{code_input}" |
|
result = generator(prompt, max_length=comment_length, num_return_sequences=1) |
|
|
|
|
|
st.subheader("Generated Comments:") |
|
st.code(result[0]['generated_text'], language='python') |
|
|
|
|
|
st.write("Powered by [Hugging Face Transformers](https://huggingface.co/) and Streamlit.") |
|
|