CodeCorrect-AI / app.py
Shushmita's picture
Update app.py
adeb12d verified
raw
history blame
1.08 kB
import streamlit as st
from transformers import AutoModelForCausalLM, AutoTokenizer
@st.cache_resource()
def load_model():
model_name = "bigcode/starcoder"
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForCausalLM.from_pretrained(model_name)
return model, tokenizer
model, tokenizer = load_model()
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():
prompt = f"### Fix the following code:\n{code_input}\n### Corrected version:\n"
inputs = tokenizer(prompt, 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 πŸ€—")