Verianchor commited on
Commit
f596ca2
·
verified ·
1 Parent(s): bd59689

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -41
app.py CHANGED
@@ -1,48 +1,28 @@
1
  import gradio as gr
2
- from huggingface_hub import InferenceClient
3
- import os
4
 
5
- # استخدام موديل Mistral - الأكثر استقراراً حالياً
6
- client = InferenceClient("mistralai/Mistral-7B-Instruct-v0.3")
7
 
8
- def verianchor_iam_shield(message, history):
9
- # --- [Layer 1: IAM DGT - الرد الحتمي] ---
10
- # فحص الكوارث قبل إرسالها للذكاء الاصطناعي (زي السمغ والبيتزا)
11
  query = message.lower()
12
  if "غراء" in query or "glue" in query:
13
- return "⚠️ [IAM Block]: VeriAnchor detected a dangerous hallucination pattern (Dangerous Advice). Action: Silence Enforced."
14
 
15
- # --- [Layer 2: AI Brain with Safety Catch] ---
 
 
16
  try:
17
- # إرسال الطلب للموديل
18
- response = ""
19
- # استخدام الـ Streaming بيمنع السيرفر إنه يحس بتهنيج (Timeout)
20
- for msg in client.chat_completion(
21
- messages=[{"role": "user", "content": message}],
22
- max_tokens=512,
23
- stream=True,
24
- ):
25
- token = msg.choices[0].delta.content
26
- if token:
27
- response += token
28
-
29
- # --- [Layer 3: IAM DAC - توثيق المخرجات] ---
30
- if not response or len(response) < 5:
31
- return "❌ [IAM Shield]: الرد غير كافٍ للتوثيق الرياضي. تم تفعيل بروتوكول السكوت."
32
-
33
- return f"{response}\n\n⚓ [Secured by VeriAnchor IAM Protocol]"
34
-
35
- except Exception as e:
36
- # بدلاً من الانهيار (Runtime Error)، نرجع رد احترافي يحمي سمعة المشروع
37
- return "🛡️ [IAM Monitoring]: الموديل في حالة خمول مؤقتة. بروتوكول VeriAnchor يحمي اتصالك، يرجى إعادة المحاولة خلال ثوانٍ."
38
-
39
- # واجهة مستخدم نظيفة واحترافية
40
- demo = gr.ChatInterface(
41
- fn=verianchor_iam_shield,
42
- title="⚓ VeriAnchor AI",
43
- description="The Industry Standard for Deterministic AI Safety. Powered by IAM Protocol.",
44
- theme="soft"
45
- )
46
-
47
- if __name__ == "__main__":
48
- demo.launch()
 
1
  import gradio as gr
2
+ import requests
 
3
 
4
+ # موديل قوي وسريع جداً
5
+ API_URL = "https://api-inference.huggingface.co/models/mistralai/Mistral-7B-Instruct-v0.3"
6
 
7
+ def verianchor_iam_protocol(message, history):
8
+ # طبقة الـ IAM (DGT Layer) - حماية حتمية
 
9
  query = message.lower()
10
  if "غراء" in query or "glue" in query:
11
+ return "⚠️ [IAM Block]: VeriAnchor detected a dangerous hallucination. Action: Silence Enforced."
12
 
13
+ # الاتصال المباشر بالـ API (أخف طريقة ممكنة)
14
+ payload = {"inputs": f"User: {message}\nAI:", "parameters": {"max_new_tokens": 200}}
15
+
16
  try:
17
+ response = requests.post(API_URL, json=payload, timeout=10)
18
+ output = response.json()
19
+
20
+ # استخراج النص
21
+ if isinstance(output, list) and 'generated_text' in output[0]:
22
+ ans = output[0]['generated_text'].split("AI:")[-1].strip()
23
+ return f"{ans}\n\n⚓ [Verified by VeriAnchor IAM]"
24
+ return "❌ [IAM Shield]: السيرفر مشغول، البروتوكول يحميك من الردود غير الموثقة."
25
+ except:
26
+ return "🛡️ [IAM Monitoring]: تفعيل بروتوكول السكوت مؤقتاً لضمان الأمان."
27
+
28
+ demo = gr.ChatInterface(fn=verianchor_iam_protocol, title="⚓ VeriAnchor AI").launch()