osmankoc commited on
Commit
b5ae9b7
·
1 Parent(s): f920cb5
Files changed (1) hide show
  1. app.py +24 -8
app.py CHANGED
@@ -3,7 +3,7 @@ import gradio as gr
3
  from transformers import AutoModelForCausalLM, AutoTokenizer
4
  import torch
5
 
6
- MODEL_NAME = "osmankoc/llama-2-7b-zoa"
7
 
8
  # Model ve tokenizer'ı önceden yükle
9
  tokenizer = AutoTokenizer.from_pretrained(MODEL_NAME)
@@ -14,14 +14,30 @@ model = AutoModelForCausalLM.from_pretrained(
14
  # ZeroGPU için model GPU'ya sadece gerektiğinde yüklenecek
15
  @spaces.GPU
16
  def generate(prompt):
17
- system_prompt = (
18
- "Generate HTML code using Tailwind CSS framework and Shadcn UI components. Add HTML tags to the code. Don't forget to use the correct classes. Don't write inline styles and descriptions. "
19
- "Here is the user prompt: "
 
 
 
 
 
20
  )
21
- full_prompt = system_prompt + prompt
22
- inputs = tokenizer(full_prompt, return_tensors="pt").to("cuda")
23
- output = model.generate(**inputs, max_length=2500)
24
- response = tokenizer.decode(output[0], skip_special_tokens=True)
 
 
 
 
 
 
 
 
 
 
 
25
  return response
26
 
27
  # Gradio UI (Basit bir API arayüzü gibi çalışacak)
 
3
  from transformers import AutoModelForCausalLM, AutoTokenizer
4
  import torch
5
 
6
+ MODEL_NAME = "Qwen/Qwen2.5-Coder-32B-Instruct"
7
 
8
  # Model ve tokenizer'ı önceden yükle
9
  tokenizer = AutoTokenizer.from_pretrained(MODEL_NAME)
 
14
  # ZeroGPU için model GPU'ya sadece gerektiğinde yüklenecek
15
  @spaces.GPU
16
  def generate(prompt):
17
+ messages = [
18
+ {"role": "system", "content": "You are HTML Web Developer. enerate HTML code using Tailwind CSS framework and Shadcn UI components. Add HTML tags to the code. Don't forget to use the correct classes. Don't write inline styles and descriptions."},
19
+ {"role": "user", "content": prompt}
20
+ ]
21
+ text = tokenizer.apply_chat_template(
22
+ messages,
23
+ tokenize=False,
24
+ add_generation_prompt=True
25
  )
26
+ model_inputs = tokenizer([text], return_tensors="pt").to("cuda")
27
+
28
+ # output = model.generate(**inputs, max_length=2500)
29
+ # response = tokenizer.decode(output[0], skip_special_tokens=True)
30
+
31
+ generated_ids = model.generate(
32
+ **model_inputs,
33
+ max_new_tokens=512
34
+ )
35
+ generated_ids = [
36
+ output_ids[len(input_ids):] for input_ids, output_ids in zip(model_inputs.input_ids, generated_ids)
37
+ ]
38
+
39
+ response = tokenizer.batch_decode(generated_ids, skip_special_tokens=True)[0]
40
+
41
  return response
42
 
43
  # Gradio UI (Basit bir API arayüzü gibi çalışacak)