File size: 1,091 Bytes
582ae31
8a098bb
582ae31
8a098bb
582ae31
 
8a098bb
 
 
 
582ae31
8a098bb
582ae31
 
 
 
 
 
 
 
 
8a098bb
 
 
 
 
582ae31
 
 
 
8a098bb
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
28
29
30
31
32
import streamlit as st
from transformers import AutoModelForSeq2SeqLM, AutoTokenizer

# Load model and tokenizer
@st.cache_resource()
def load_model():
    model_name = "Salesforce/codet5-small"  # A better model for code correction
    tokenizer = AutoTokenizer.from_pretrained(model_name)
    model = AutoModelForSeq2SeqLM.from_pretrained(model_name)
    return model, tokenizer

model, tokenizer = load_model()

# Streamlit UI
st.title("CodeCorrect AI")
st.subheader("AI-powered Code Autocorrect Tool")

code_input = st.text_area("Enter your code here:", height=200)

if st.button("Correct Code"):
    if code_input.strip():
        # Tokenize and generate corrected code
        inputs = tokenizer(code_input, return_tensors="pt", padding=True, truncation=True, max_length=512)
        outputs = model.generate(**inputs, max_length=512)
        corrected_code = tokenizer.decode(outputs[0], skip_special_tokens=True)

        st.text_area("Corrected Code:", corrected_code, height=200)
    else:
        st.warning("Please enter some code.")

st.markdown("Powered by Hugging Face 🤗")