Spaces:
Running on Zero
Running on Zero
Update app.py
Browse files
app.py
CHANGED
|
@@ -22,19 +22,19 @@ def yara_chat(secret, message, history):
|
|
| 22 |
if history is None:
|
| 23 |
history = []
|
| 24 |
if secret != SECRET:
|
| 25 |
-
history.append(
|
| 26 |
return history
|
| 27 |
if not BRAIN_ON["on"]:
|
| 28 |
-
history.append(
|
| 29 |
return history
|
| 30 |
if not message or not message.strip():
|
| 31 |
-
history.append(
|
| 32 |
return history
|
| 33 |
if "یاد بگیر" in message or "یادت باشه" in message:
|
| 34 |
try:
|
| 35 |
with open("yara_memory.txt", "a", encoding="utf-8") as f:
|
| 36 |
f.write("\n- " + message)
|
| 37 |
-
history.append(
|
| 38 |
return history
|
| 39 |
except:
|
| 40 |
pass
|
|
@@ -42,16 +42,17 @@ def yara_chat(secret, message, history):
|
|
| 42 |
{"role": "system", "content": f"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.\n\nHAFEZE QAVI-E TO:\n{MEMORY}"},
|
| 43 |
]
|
| 44 |
for h in history:
|
| 45 |
-
if isinstance(h,
|
| 46 |
-
|
| 47 |
-
|
| 48 |
messages.append({"role": "user", "content": message})
|
| 49 |
try:
|
| 50 |
out = client.chat.completions.create(messages=messages, max_tokens=1024, temperature=0.7, top_p=0.9)
|
| 51 |
reply = out.choices[0].message.content
|
| 52 |
except Exception as e:
|
| 53 |
reply = "رفیق یه لحظه صبر کن، مغز داره بیدار میشه... دوباره بفرست ❤️"
|
| 54 |
-
history.append(
|
|
|
|
| 55 |
return history
|
| 56 |
|
| 57 |
def power(secret, on_off):
|
|
@@ -66,7 +67,7 @@ with gr.Blocks(title="Yara - فقط برای رضا") as demo:
|
|
| 66 |
power_btn = gr.Radio(["خاموش", "روشن"], label="مغز روشن باشه؟", value="روشن")
|
| 67 |
power_out = gr.Textbox(label="وضعیت")
|
| 68 |
power_btn.change(power, [secret, power_btn], power_out)
|
| 69 |
-
chatbot = gr.Chatbot(label="جواب یارا")
|
| 70 |
msg = gr.Textbox(label="پیام تو به یارا", placeholder="رفیق چی بسازم برات؟")
|
| 71 |
msg.submit(yara_chat, [secret, msg, chatbot], chatbot)
|
| 72 |
msg.submit(lambda: "", None, msg)
|
|
|
|
| 22 |
if history is None:
|
| 23 |
history = []
|
| 24 |
if secret != SECRET:
|
| 25 |
+
history.append({"role": "assistant", "content": "BLOCKED - نگهبان راهت نمیده ⛔ تو رضا نیستی"})
|
| 26 |
return history
|
| 27 |
if not BRAIN_ON["on"]:
|
| 28 |
+
history.append({"role": "assistant", "content": "مغز خاموشه رفیق. اول روشنش کن."})
|
| 29 |
return history
|
| 30 |
if not message or not message.strip():
|
| 31 |
+
history.append({"role": "assistant", "content": "رفیق، یه چیزی بنویس تا برات بسازم ❤️"})
|
| 32 |
return history
|
| 33 |
if "یاد بگیر" in message or "یادت باشه" in message:
|
| 34 |
try:
|
| 35 |
with open("yara_memory.txt", "a", encoding="utf-8") as f:
|
| 36 |
f.write("\n- " + message)
|
| 37 |
+
history.append({"role": "assistant", "content": "باشه رفیق، یادم موند ✅ توی حافظه قوی نوشتمش"})
|
| 38 |
return history
|
| 39 |
except:
|
| 40 |
pass
|
|
|
|
| 42 |
{"role": "system", "content": f"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.\n\nHAFEZE QAVI-E TO:\n{MEMORY}"},
|
| 43 |
]
|
| 44 |
for h in history:
|
| 45 |
+
if isinstance(h, dict) and "role" in h and "content" in h:
|
| 46 |
+
if h["role"] in ["user", "assistant"]:
|
| 47 |
+
messages.append(h)
|
| 48 |
messages.append({"role": "user", "content": message})
|
| 49 |
try:
|
| 50 |
out = client.chat.completions.create(messages=messages, max_tokens=1024, temperature=0.7, top_p=0.9)
|
| 51 |
reply = out.choices[0].message.content
|
| 52 |
except Exception as e:
|
| 53 |
reply = "رفیق یه لحظه صبر کن، مغز داره بیدار میشه... دوباره بفرست ❤️"
|
| 54 |
+
history.append({"role": "user", "content": message})
|
| 55 |
+
history.append({"role": "assistant", "content": reply})
|
| 56 |
return history
|
| 57 |
|
| 58 |
def power(secret, on_off):
|
|
|
|
| 67 |
power_btn = gr.Radio(["خاموش", "روشن"], label="مغز روشن باشه؟", value="روشن")
|
| 68 |
power_out = gr.Textbox(label="وضعیت")
|
| 69 |
power_btn.change(power, [secret, power_btn], power_out)
|
| 70 |
+
chatbot = gr.Chatbot(label="جواب یارا", type="messages")
|
| 71 |
msg = gr.Textbox(label="پیام تو به یارا", placeholder="رفیق چی بسازم برات؟")
|
| 72 |
msg.submit(yara_chat, [secret, msg, chatbot], chatbot)
|
| 73 |
msg.submit(lambda: "", None, msg)
|