Zenkad commited on
Commit
35e2c17
·
verified ·
1 Parent(s): 1f5587e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -9
app.py CHANGED
@@ -5,9 +5,9 @@ import torch
5
  from transformers import AutoTokenizer, AutoModelForCausalLM
6
 
7
  # =========================
8
- # MODEL YÜKLEME
9
  # =========================
10
- MODEL_ID = "google/gemma-2b-it"
11
 
12
  tokenizer = AutoTokenizer.from_pretrained(MODEL_ID)
13
  model = AutoModelForCausalLM.from_pretrained(
@@ -41,23 +41,20 @@ def root():
41
 
42
  @app.post("/api/chat")
43
  def chat(req: ChatReq):
44
- prompt = f"Kullanıcı: {req.message}\nAsistan:"
45
 
46
  inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
47
 
48
  with torch.no_grad():
49
  output = model.generate(
50
  **inputs,
51
- max_new_tokens=200,
52
  do_sample=True,
53
  temperature=0.7,
54
  top_p=0.9
55
  )
56
 
57
  text = tokenizer.decode(output[0], skip_special_tokens=True)
 
58
 
59
- # Asistan cevabını ayıkla
60
- if "Asistan:" in text:
61
- text = text.split("Asistan:")[-1].strip()
62
-
63
- return {"response": text}
 
5
  from transformers import AutoTokenizer, AutoModelForCausalLM
6
 
7
  # =========================
8
+ # AÇIK MODEL (GATED DEĞİL)
9
  # =========================
10
+ MODEL_ID = "Qwen/Qwen2.5-0.5B-Instruct"
11
 
12
  tokenizer = AutoTokenizer.from_pretrained(MODEL_ID)
13
  model = AutoModelForCausalLM.from_pretrained(
 
41
 
42
  @app.post("/api/chat")
43
  def chat(req: ChatReq):
44
+ prompt = f"<|user|>\n{req.message}\n<|assistant|>\n"
45
 
46
  inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
47
 
48
  with torch.no_grad():
49
  output = model.generate(
50
  **inputs,
51
+ max_new_tokens=256,
52
  do_sample=True,
53
  temperature=0.7,
54
  top_p=0.9
55
  )
56
 
57
  text = tokenizer.decode(output[0], skip_special_tokens=True)
58
+ answer = text.split("<|assistant|>")[-1].strip()
59
 
60
+ return {"response": answer}