File size: 1,083 Bytes
adeb12d
 
582ae31
adeb12d
 
 
 
 
 
582ae31
adeb12d
582ae31
adeb12d
 
582ae31
adeb12d
582ae31
adeb12d
 
 
 
 
 
 
 
 
8a098bb
adeb12d
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
  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 🤗")