Reza1880044 commited on
Commit
0ba3190
·
verified ·
1 Parent(s): 48f664c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -4
app.py CHANGED
@@ -1,7 +1,7 @@
1
  import gradio as gr
2
  import spaces
3
  import 【entity-torch¦canonical_name=torch】
4
- from 【entity-transformers¦canonical_name=transformers】 import AutoModelForCausalLM, AutoTokenizer
5
 
6
  SECRET = "yara-man-reza-am"
7
  BRAIN_ON = {"on": True}
@@ -11,7 +11,7 @@ print("Yara dare maghz ro miarad...")
11
  tokenizer = AutoTokenizer.from_pretrained(MODEL_NAME, trust_remote_code=True)
12
  model = AutoModelForCausalLM.from_pretrained(
13
  MODEL_NAME,
14
- torch_dtype=【entity-torch¦canonical_name=torch】.float16,
15
  device_map="auto",
16
  trust_remote_code=True
17
  )
@@ -51,7 +51,7 @@ def yara_chat(secret, message, history):
51
  messages.append({"role": "user", "content": message})
52
  text = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
53
  inputs = tokenizer([text], return_tensors="pt").to(model.device)
54
- with torch.no_grad():
55
  out = model.generate(**inputs, max_new_tokens=1200, temperature=0.6, top_p=0.85, do_sample=True, repetition_penalty=1.15)
56
  reply = tokenizer.decode(out[0][inputs.input_ids.shape[1]:], skip_special_tokens=True).strip()
57
  history = history + [{"role": "user", "content": message}, {"role": "assistant", "content": reply}]
@@ -70,7 +70,7 @@ def power(secret, on_off):
70
  return "مغز روشن شد ✅" if BRAIN_ON["on"] else "مغز خاموش شد 🌙"
71
 
72
  with gr.Blocks(title="Yara - فقط برای رضا") as demo:
73
- gr.Markdown("# 🛡️ یارا - فقط برای رضا\nنگهبان فقط رضا رو راه میده | حافظه قوی روشنه 🧠")
74
  secret = gr.Textbox(label="جمله رمز تو", type="password", placeholder="رمزت رو بزن رفیق")
75
  power_btn = gr.Radio(["خاموش", "روشن"], label="مغز روشن باشه؟", value="روشن")
76
  power_out = gr.Textbox(label="وضعیت")
 
1
  import gradio as gr
2
  import spaces
3
  import 【entity-torch¦canonical_name=torch】
4
+ from transformers import AutoModelForCausalLM, AutoTokenizer
5
 
6
  SECRET = "yara-man-reza-am"
7
  BRAIN_ON = {"on": True}
 
11
  tokenizer = AutoTokenizer.from_pretrained(MODEL_NAME, trust_remote_code=True)
12
  model = AutoModelForCausalLM.from_pretrained(
13
  MODEL_NAME,
14
+ torch_dtype=torch.float16,
15
  device_map="auto",
16
  trust_remote_code=True
17
  )
 
51
  messages.append({"role": "user", "content": message})
52
  text = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
53
  inputs = tokenizer([text], return_tensors="pt").to(model.device)
54
+ with 【entity-torch¦canonical_name=torch】.no_grad():
55
  out = model.generate(**inputs, max_new_tokens=1200, temperature=0.6, top_p=0.85, do_sample=True, repetition_penalty=1.15)
56
  reply = tokenizer.decode(out[0][inputs.input_ids.shape[1]:], skip_special_tokens=True).strip()
57
  history = history + [{"role": "user", "content": message}, {"role": "assistant", "content": reply}]
 
70
  return "مغز روشن شد ✅" if BRAIN_ON["on"] else "مغز خاموش شد 🌙"
71
 
72
  with gr.Blocks(title="Yara - فقط برای رضا") as demo:
73
+ gr.Markdown("# Yara - فقط برای رضا\nنگهبان فقط رضا رو راه میده | حافظه قوی روشنه")
74
  secret = gr.Textbox(label="جمله رمز تو", type="password", placeholder="رمزت رو بزن رفیق")
75
  power_btn = gr.Radio(["خاموش", "روشن"], label="مغز روشن باشه؟", value="روشن")
76
  power_out = gr.Textbox(label="وضعیت")