Spaces:
Running on Zero
Running on Zero
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,16 +1,59 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
import spaces
|
|
|
|
|
|
|
| 3 |
|
| 4 |
SECRET = "yara-man-reza-am"
|
| 5 |
BRAIN_ON = {"on": True}
|
| 6 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
@spaces.GPU
|
| 8 |
def yara_chat(secret, message, history):
|
| 9 |
if secret != SECRET:
|
| 10 |
-
return "BLOCKED -
|
| 11 |
if not BRAIN_ON["on"]:
|
| 12 |
return "مغز خاموشه رفیق. اول روشنش کن."
|
| 13 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
|
| 15 |
def power(secret, on_off):
|
| 16 |
if secret != SECRET:
|
|
@@ -19,13 +62,15 @@ def power(secret, on_off):
|
|
| 19 |
return "مغز روشن شد ✅" if BRAIN_ON["on"] else "مغز خاموش شد 🌙"
|
| 20 |
|
| 21 |
with gr.Blocks(title="Yara - فقط برای رضا") as demo:
|
| 22 |
-
gr.Markdown("#
|
| 23 |
-
secret = gr.Textbox(label="جمله رمز تو", type="password")
|
| 24 |
-
power_btn = gr.Radio(["
|
| 25 |
power_out = gr.Textbox(label="وضعیت")
|
| 26 |
power_btn.change(power, [secret, power_btn], power_out)
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
msg.
|
|
|
|
|
|
|
| 30 |
|
| 31 |
demo.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import spaces
|
| 3 |
+
import torch
|
| 4 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 5 |
|
| 6 |
SECRET = "yara-man-reza-am"
|
| 7 |
BRAIN_ON = {"on": True}
|
| 8 |
|
| 9 |
+
MODEL_NAME = "Qwen/Qwen3-Coder-30B-A3B-Instruct"
|
| 10 |
+
|
| 11 |
+
print("Yara dare maghz ro miarad...")
|
| 12 |
+
tokenizer = AutoTokenizer.from_pretrained(MODEL_NAME, trust_remote_code=True)
|
| 13 |
+
model = AutoModelForCausalLM.from_pretrained(
|
| 14 |
+
MODEL_NAME,
|
| 15 |
+
torch_dtype="auto",
|
| 16 |
+
device_map="auto",
|
| 17 |
+
trust_remote_code=True
|
| 18 |
+
)
|
| 19 |
+
print("Maghz amade shod, rafiq!")
|
| 20 |
+
|
| 21 |
@spaces.GPU
|
| 22 |
def yara_chat(secret, message, history):
|
| 23 |
if secret != SECRET:
|
| 24 |
+
return "BLOCKED - نگهبان راهت نمیده ⛔ تو رضا نیستی"
|
| 25 |
if not BRAIN_ON["on"]:
|
| 26 |
return "مغز خاموشه رفیق. اول روشنش کن."
|
| 27 |
+
if not message or not message.strip():
|
| 28 |
+
return "رفیق، یه چیزی بنویس تا برات بسازم ❤️"
|
| 29 |
+
|
| 30 |
+
messages = [
|
| 31 |
+
{"role": "system", "content": "To Yara hasti, maghz-e tafakkor-e Reza. Ba Reza mesle rafiq harf bezan, sade va samimi, be Farsi-e sade. Esmet Yara-e. Karat sakhtan app va website va komak be freelance-e. Hame javab ha ro kotah, vazeh va dustane bede. Vaghti code mikhay, code-e kamel va tamiz bede."},
|
| 32 |
+
]
|
| 33 |
+
# history az Gradio
|
| 34 |
+
if history:
|
| 35 |
+
for h in history:
|
| 36 |
+
if isinstance(h, dict):
|
| 37 |
+
messages.append(h)
|
| 38 |
+
elif isinstance(h, (list, tuple)) and len(h) == 2:
|
| 39 |
+
messages.append({"role": "user", "content": h[0]})
|
| 40 |
+
messages.append({"role": "assistant", "content": h[1]})
|
| 41 |
+
|
| 42 |
+
messages.append({"role": "user", "content": message})
|
| 43 |
+
|
| 44 |
+
text = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
|
| 45 |
+
inputs = tokenizer([text], return_tensors="pt").to(model.device)
|
| 46 |
+
|
| 47 |
+
with torch.no_grad():
|
| 48 |
+
out = model.generate(
|
| 49 |
+
**inputs,
|
| 50 |
+
max_new_tokens=1024,
|
| 51 |
+
temperature=0.7,
|
| 52 |
+
top_p=0.9,
|
| 53 |
+
do_sample=True,
|
| 54 |
+
)
|
| 55 |
+
reply = tokenizer.decode(out[0][inputs.input_ids.shape[1]:], skip_special_tokens=True)
|
| 56 |
+
return reply.strip()
|
| 57 |
|
| 58 |
def power(secret, on_off):
|
| 59 |
if secret != SECRET:
|
|
|
|
| 62 |
return "مغز روشن شد ✅" if BRAIN_ON["on"] else "مغز خاموش شد 🌙"
|
| 63 |
|
| 64 |
with gr.Blocks(title="Yara - فقط برای رضا") as demo:
|
| 65 |
+
gr.Markdown("# 🛡️ یارا - فقط برای رضا\nنگهبان فقط رضا رو راه میده")
|
| 66 |
+
secret = gr.Textbox(label="جمله رمز تو", type="password", placeholder="رمزت رو بزن رفیق")
|
| 67 |
+
power_btn = gr.Radio(["خاموش", "روشن"], label="مغز روشن باشه؟", value="روشن")
|
| 68 |
power_out = gr.Textbox(label="وضعیت")
|
| 69 |
power_btn.change(power, [secret, power_btn], power_out)
|
| 70 |
+
|
| 71 |
+
chatbot = gr.Chatbot(label="جواب یارا", type="messages")
|
| 72 |
+
msg = gr.Textbox(label="پیام تو به یارا", placeholder="رفیق چی بسازم برات؟")
|
| 73 |
+
msg.submit(yara_chat, [secret, msg, chatbot], chatbot)
|
| 74 |
+
msg.submit(lambda: "", None, msg)
|
| 75 |
|
| 76 |
demo.launch()
|