Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,26 +1,30 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
from transformers import AutoModelForCausalLM, AutoTokenizer
|
|
|
|
| 3 |
|
|
|
|
| 4 |
@st.cache_resource()
|
| 5 |
def load_model():
|
| 6 |
-
model_name = "
|
| 7 |
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
| 8 |
-
model = AutoModelForCausalLM.from_pretrained(model_name)
|
| 9 |
return model, tokenizer
|
| 10 |
|
| 11 |
model, tokenizer = load_model()
|
| 12 |
|
|
|
|
| 13 |
st.title("CodeCorrect AI")
|
| 14 |
st.subheader("AI-powered Code Autocorrect Tool")
|
| 15 |
|
| 16 |
-
code_input = st.text_area("Enter your code here:", height=200)
|
| 17 |
|
| 18 |
if st.button("Correct Code"):
|
| 19 |
if code_input.strip():
|
| 20 |
prompt = f"### Fix the following code:\n{code_input}\n### Corrected version:\n"
|
| 21 |
-
inputs = tokenizer(prompt, return_tensors="pt", padding=True, truncation=True, max_length=512)
|
| 22 |
outputs = model.generate(**inputs, max_length=512)
|
| 23 |
corrected_code = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
|
|
|
| 24 |
st.text_area("Corrected Code:", corrected_code, height=200)
|
| 25 |
else:
|
| 26 |
st.warning("Please enter some code.")
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 3 |
+
import torch
|
| 4 |
|
| 5 |
+
# Load model and tokenizer
|
| 6 |
@st.cache_resource()
|
| 7 |
def load_model():
|
| 8 |
+
model_name = "deepseek-ai/deepseek-coder-6.7b-instruct"
|
| 9 |
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
| 10 |
+
model = AutoModelForCausalLM.from_pretrained(model_name, torch_dtype=torch.float16, device_map="auto")
|
| 11 |
return model, tokenizer
|
| 12 |
|
| 13 |
model, tokenizer = load_model()
|
| 14 |
|
| 15 |
+
# Streamlit UI
|
| 16 |
st.title("CodeCorrect AI")
|
| 17 |
st.subheader("AI-powered Code Autocorrect Tool")
|
| 18 |
|
| 19 |
+
code_input = st.text_area("Enter your buggy code here:", height=200)
|
| 20 |
|
| 21 |
if st.button("Correct Code"):
|
| 22 |
if code_input.strip():
|
| 23 |
prompt = f"### Fix the following code:\n{code_input}\n### Corrected version:\n"
|
| 24 |
+
inputs = tokenizer(prompt, return_tensors="pt", padding=True, truncation=True, max_length=512).to("cuda" if torch.cuda.is_available() else "cpu")
|
| 25 |
outputs = model.generate(**inputs, max_length=512)
|
| 26 |
corrected_code = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
| 27 |
+
|
| 28 |
st.text_area("Corrected Code:", corrected_code, height=200)
|
| 29 |
else:
|
| 30 |
st.warning("Please enter some code.")
|