DevStudio-AI commited on
Commit
11b1645
·
verified ·
1 Parent(s): f881a80

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -6
app.py CHANGED
@@ -6,21 +6,19 @@ from transformers import AutoTokenizer, AutoModelForCausalLM
6
  import spaces # Mandatory library for Hugging Face ZeroGPU [1]
7
 
8
  MODEL_ID = "DevStudio-AI/Devstudio-Coder-1.5B"
9
- # Fetch your secure token from the Space Secrets environment
10
  HF_TOKEN = os.environ.get("HF_TOKEN")
11
 
12
  print("Loading tokenizer and base model...")
13
 
14
- # 1. Load the tokenizer from the official, guaranteed-clean Qwen repository
15
- # This bypasses any local repository file corruption or cache issues
16
  tokenizer = AutoTokenizer.from_pretrained(
17
  "Qwen/Qwen2.5-Coder-1.5B-Instruct"
18
  )
19
 
20
- # 2. Load the model, pointing directly to the nested directory inside your repo
21
  model = AutoModelForCausalLM.from_pretrained(
22
  MODEL_ID,
23
- subfolder="models/final_merged", # Tells the loader to look inside this folder [1]
24
  torch_dtype=torch.float16,
25
  device_map="cpu",
26
  token=HF_TOKEN
@@ -34,8 +32,25 @@ def generate_code(prompt, temperature, max_tokens):
34
  # Move model to CUDA dynamically inside the GPU context [1]
35
  model.to("cuda")
36
 
37
- inputs = tokenizer(prompt, return_tensors="pt").to("cuda")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
38
 
 
39
  outputs = model.generate(
40
  **inputs,
41
  max_new_tokens=int(max_tokens),
 
6
  import spaces # Mandatory library for Hugging Face ZeroGPU [1]
7
 
8
  MODEL_ID = "DevStudio-AI/Devstudio-Coder-1.5B"
 
9
  HF_TOKEN = os.environ.get("HF_TOKEN")
10
 
11
  print("Loading tokenizer and base model...")
12
 
13
+ # We load the tokenizer from the official Qwen repository for safety
 
14
  tokenizer = AutoTokenizer.from_pretrained(
15
  "Qwen/Qwen2.5-Coder-1.5B-Instruct"
16
  )
17
 
18
+ # Load your custom fine-tuned model from the subfolder
19
  model = AutoModelForCausalLM.from_pretrained(
20
  MODEL_ID,
21
+ subfolder="models/final_merged",
22
  torch_dtype=torch.float16,
23
  device_map="cpu",
24
  token=HF_TOKEN
 
32
  # Move model to CUDA dynamically inside the GPU context [1]
33
  model.to("cuda")
34
 
35
+ # --- FIXED: Apply the identical System Prompt and ChatML formatting ---
36
+ system_prompt = (
37
+ "You are DevStudio-1.5B, an in-editor coding assistant developed by DevStudio AI. "
38
+ "You are a highly specialized master of modern single-file HTML and Tailwind CSS designs. "
39
+ )
40
+
41
+ # Build conversational structure matching your training data
42
+ messages = [
43
+ {"role": "system", "content": system_prompt},
44
+ {"role": "user", "content": prompt}
45
+ ]
46
+
47
+ # Convert structure into Qwen's ChatML template string
48
+ formatted_prompt = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
49
+
50
+ # Tokenize the formatted ChatML prompt
51
+ inputs = tokenizer(formatted_prompt, return_tensors="pt").to("cuda")
52
 
53
+ # Generate completion
54
  outputs = model.generate(
55
  **inputs,
56
  max_new_tokens=int(max_tokens),