krisha06 commited on
Commit
10a1bb1
·
verified ·
1 Parent(s): 6c5f774

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -10
app.py CHANGED
@@ -5,11 +5,9 @@ import streamlit as st
5
 
6
  st.set_page_config(page_title="TinyLLaMA Python Tutor", layout="centered")
7
 
8
- # Title
9
  st.title("🧠 TinyLLaMA Python Tutor (LoRA)")
10
  st.write("Ask me any Python programming question:")
11
 
12
- # Load base model and LoRA adapter
13
  @st.cache_resource
14
  def load_model():
15
  base_model = "TinyLlama/TinyLlama-1.1B-Chat-v1.0"
@@ -24,16 +22,14 @@ def load_model():
24
 
25
  tokenizer, model = load_model()
26
 
27
- # Prompt template
28
  def build_prompt(question):
29
  return (
30
- "You are a helpful AI tutor that only answers Python programming questions. "
31
- "If the user asks something unrelated to Python, respond with: "
32
  "'Sorry, I can only answer Python-related questions.'\n\n"
33
  f"Question: {question}\nAnswer:"
34
  )
35
 
36
- # Input box
37
  question = st.text_input("Your question")
38
 
39
  if question:
@@ -43,10 +39,12 @@ if question:
43
  with st.spinner("Thinking..."):
44
  outputs = model.generate(
45
  **inputs,
46
- max_new_tokens=300, # 🔼 Increased from 200 to 300
47
- temperature=0.6, # 🔽 More deterministic
48
- top_p=0.9,
49
- pad_token_id=tokenizer.eos_token_id
 
 
50
  )
51
 
52
  decoded_output = tokenizer.decode(outputs[0], skip_special_tokens=True)
 
5
 
6
  st.set_page_config(page_title="TinyLLaMA Python Tutor", layout="centered")
7
 
 
8
  st.title("🧠 TinyLLaMA Python Tutor (LoRA)")
9
  st.write("Ask me any Python programming question:")
10
 
 
11
  @st.cache_resource
12
  def load_model():
13
  base_model = "TinyLlama/TinyLlama-1.1B-Chat-v1.0"
 
22
 
23
  tokenizer, model = load_model()
24
 
 
25
  def build_prompt(question):
26
  return (
27
+ "You are a helpful and concise Python programming tutor. "
28
+ "If the question is not about Python, respond with: "
29
  "'Sorry, I can only answer Python-related questions.'\n\n"
30
  f"Question: {question}\nAnswer:"
31
  )
32
 
 
33
  question = st.text_input("Your question")
34
 
35
  if question:
 
39
  with st.spinner("Thinking..."):
40
  outputs = model.generate(
41
  **inputs,
42
+ max_new_tokens=250,
43
+ temperature=0.6,
44
+ top_p=0.85,
45
+ repetition_penalty=1.2,
46
+ pad_token_id=tokenizer.eos_token_id,
47
+ eos_token_id=tokenizer.eos_token_id,
48
  )
49
 
50
  decoded_output = tokenizer.decode(outputs[0], skip_special_tokens=True)