Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -3,17 +3,18 @@ import torch
|
|
3 |
from transformers import AutoModelForCausalLM, AutoTokenizer
|
4 |
|
5 |
# Load model and tokenizer
|
6 |
-
#model_name = "codellama/CodeLlama-7b-Python-hf"
|
7 |
model_name = "Qwen/Qwen2.5-Coder-0.5B-Instruct"
|
8 |
st.title("Python Code Helper")
|
9 |
|
10 |
try:
|
11 |
-
|
|
|
12 |
model = AutoModelForCausalLM.from_pretrained(model_name)
|
13 |
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
14 |
device = torch.device("cuda" if torch.cuda.is_available() else 'cpu')
|
15 |
model = model.to(device)
|
16 |
-
|
17 |
except Exception as e:
|
18 |
st.error(f"Error loading model: {e}")
|
19 |
st.stop()
|
@@ -23,7 +24,7 @@ st.markdown("### Python Code Generation")
|
|
23 |
with st.form(key="code_form"):
|
24 |
prompt = st.text_area("Enter your coding prompt:", height=200)
|
25 |
submit = st.form_submit_button("Generate Code")
|
26 |
-
|
27 |
if submit and prompt.strip():
|
28 |
with st.spinner("Generating response..."):
|
29 |
try:
|
@@ -33,4 +34,4 @@ with st.form(key="code_form"):
|
|
33 |
st.markdown("### Generated Code:")
|
34 |
st.code(response, language="python")
|
35 |
except Exception as e:
|
36 |
-
st.error(f"An error occurred: {e}")
|
|
|
3 |
from transformers import AutoModelForCausalLM, AutoTokenizer
|
4 |
|
5 |
# Load model and tokenizer
|
6 |
+
# model_name = "codellama/CodeLlama-7b-Python-hf"
|
7 |
model_name = "Qwen/Qwen2.5-Coder-0.5B-Instruct"
|
8 |
st.title("Python Code Helper")
|
9 |
|
10 |
try:
|
11 |
+
info = st.empty()
|
12 |
+
info.markdown("#### :red[Model is Loading....]")
|
13 |
model = AutoModelForCausalLM.from_pretrained(model_name)
|
14 |
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
15 |
device = torch.device("cuda" if torch.cuda.is_available() else 'cpu')
|
16 |
model = model.to(device)
|
17 |
+
info.markdown("#### :green[Model Loaded Successfully]")
|
18 |
except Exception as e:
|
19 |
st.error(f"Error loading model: {e}")
|
20 |
st.stop()
|
|
|
24 |
with st.form(key="code_form"):
|
25 |
prompt = st.text_area("Enter your coding prompt:", height=200)
|
26 |
submit = st.form_submit_button("Generate Code")
|
27 |
+
|
28 |
if submit and prompt.strip():
|
29 |
with st.spinner("Generating response..."):
|
30 |
try:
|
|
|
34 |
st.markdown("### Generated Code:")
|
35 |
st.code(response, language="python")
|
36 |
except Exception as e:
|
37 |
+
st.error(f"An error occurred: {e}")
|