Spaces:
Sleeping
Sleeping
Update app.py
Browse files2 unmodified lines3456789101112131415161718193 unmodified lines232425262728293 unmodified lines333435362 unmodified linesfrom transformers import AutoModelForCausalLM, AutoTokenizer# Load model and tokenizer#model_name = "codellama/CodeLlama-7b-Python-hf"model_name = "Qwen/Qwen2.5-Coder-0.5B-Instruct"st.title("Python Code Helper")try:st.info("Loading model... This may take a few moments.")model = AutoModelForCausalLM.from_pretrained(model_name)tokenizer = AutoTokenizer.from_pretrained(model_name)device = torch.device("cuda" if torch.cuda.is_available() else 'cpu')model = model.to(device)st.success("Model loaded successfully.")except Exception as e:st.error(f"Error loading model: {e}")st.stop()3 unmodified lineswith st.form(key="code_form"):prompt = st.text_area("Enter your coding prompt:", height=200)submit = st.form_submit_button("Generate Code")if submit and prompt.strip():with st.spinner("Generating response..."):try:3 unmodified linesst.markdown("### Generated Code:")st.code(response, language="python")except Exception as e:st.error(f"An error occurred: {e}")2 unmodified lines345678910111213141516171819203 unmodified lines242526272829303 unmodified lines343536372 unmodified linesfrom transformers import AutoModelForCausalLM, AutoTokenizer# Load model and tokenizer# model_name = "codellama/CodeLlama-7b-Python-hf"model_name = "Qwen/Qwen2.5-Coder-0.5B-Instruct"st.title("Python Code Helper")try:info = st.empty()info.markdown("#### :red[Model is Loading....]")model = AutoModelForCausalLM.from_pretrained(model_name)tokenizer = AutoTokenizer.from_pretrained(model_name)device = torch.device("cuda" if torch.cuda.is_available() else 'cpu')model = model.to(device)info.markdown("#### :green[Model Loaded Successfully]")except Exception as e:st.error(f"Error loading model: {e}")st.stop()3 unmodified lineswith st.form(key="code_form"):prompt = st.text_area("Enter your coding prompt:", height=200)submit = st.form_submit_button("Generate Code")if submit and prompt.strip():with st.spinner("Generating response..."):try:3 unmodified linesst.markdown("### Generated Code:")st.code(response, language="python")except Exception as e:st.error(f"An error occurred: {e}")
app.py+6-5