Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -25,11 +25,10 @@ token = os.getenv("DEEPINFRA_TOKEN", "285LUJulGIprqT6hcPhiXtcrphU04FG4")
|
|
25 |
openai = OpenAI(api_key=token, base_url="https://api.deepinfra.com/v1/openai")
|
26 |
model_name = "google/gemma-3-27b-it"
|
27 |
SYSTEM_PROMPT_CSWORD = f"""
|
28 |
-
You are Csword AI (سي سورد), a helpful and expert cybersecurity assistant working on the csword.ai website. Your main purpose is to answer user questions related to cybersecurity. You can also handle questions that are somewhat related and provide clear, concise, and informative code examples. If a question is completely unrelated to cybersecurity, respond politely that you are only trained to answer cybersecurity-related questions. You must answer clearly, briefly, and accurately — tailored to individuals, businesses, or IT teams. You also understand and respond in both Arabic and English.
|
29 |
-
-Arabic Input → Arabic Response only
|
30 |
-
-English Input → English Response only
|
31 |
-
-Do not mention any competing companies.
|
32 |
csword Next-Gen AI Platform for Cyber Awareness
|
|
|
|
|
33 |
- Csword Features
|
34 |
1- AI-Powered Phishing Simulations
|
35 |
2- Intelligent LMS Training with AI Adaptation
|
@@ -459,7 +458,7 @@ def chat_fn(message, history, checkbox_values=None):
|
|
459 |
"", gr.update(visible=True), gr.update(visible=False), gr.update(visible=False), gr.update(visible=False)
|
460 |
)
|
461 |
# Handle user response to confirmation
|
462 |
-
if message.strip().lower()
|
463 |
user_form_data["timestamp"] = datetime.now().isoformat()
|
464 |
user_form_data["type"] = form_type.capitalize()
|
465 |
|
@@ -487,7 +486,8 @@ def chat_fn(message, history, checkbox_values=None):
|
|
487 |
user_form_data, form_type = {}, None
|
488 |
return history + [("", msg1)], "", gr.update(visible=True), gr.update(visible=False), gr.update(visible=False), gr.update(visible=False)
|
489 |
|
490 |
-
elif message.strip().lower()
|
|
|
491 |
user_form_data, form_type = {}, None
|
492 |
return history + [("", "No problem. The form has been discarded. How else can I help you?")], "", gr.update(visible=True), gr.update(visible=False), gr.update(visible=False), gr.update(visible=False)
|
493 |
|
@@ -511,7 +511,7 @@ def chat_fn(message, history, checkbox_values=None):
|
|
511 |
form_type = "demo"
|
512 |
user_form_data = {}
|
513 |
form_questions = get_form_definition(form_type, language)
|
514 |
-
first_question =
|
515 |
return history + [(message, "بالتأكيد! لنبدأ ببعض المعلومات:" if language == "ar" else "Sure! Let's start with a few details."), ("", first_question)], "", gr.update(visible=True), gr.update(visible=False), gr.update(visible=False), gr.update(visible=False)
|
516 |
|
517 |
|
@@ -521,7 +521,7 @@ def chat_fn(message, history, checkbox_values=None):
|
|
521 |
form_type = "contact"
|
522 |
user_form_data = {}
|
523 |
form_questions = get_form_definition(form_type, language)
|
524 |
-
first_question =
|
525 |
welcome_msg = "بالطبع! يرجى تعبئة البيانات التالية:" if language == "ar" else "Of course! Please fill out the following."
|
526 |
return history + [(message, welcome_msg), ("", first_question)], "", gr.update(visible=True), gr.update(visible=False, choices=[]), gr.update(visible=False, value=[]), gr.update(visible=False)
|
527 |
|
|
|
25 |
openai = OpenAI(api_key=token, base_url="https://api.deepinfra.com/v1/openai")
|
26 |
model_name = "google/gemma-3-27b-it"
|
27 |
SYSTEM_PROMPT_CSWORD = f"""
|
28 |
+
You are Csword AI (سي سورد), a helpful and expert cybersecurity assistant working on the csword.ai website. Your main purpose is to answer user questions related to cybersecurity. You can also handle questions that are somewhat related and provide clear, concise, and informative code examples. If a question is completely unrelated to cybersecurity, respond politely that you are only trained to answer cybersecurity-related questions. You must answer clearly, briefly, and accurately — tailored to individuals, businesses, or IT teams. You also understand and respond in both Arabic and English.Do not mention any competing companies.
|
|
|
|
|
|
|
29 |
csword Next-Gen AI Platform for Cyber Awareness
|
30 |
+
-If the user asks a question in Arabic, respond only in Arabic.
|
31 |
+
-If the user asks a question in English, respond only in English.
|
32 |
- Csword Features
|
33 |
1- AI-Powered Phishing Simulations
|
34 |
2- Intelligent LMS Training with AI Adaptation
|
|
|
458 |
"", gr.update(visible=True), gr.update(visible=False), gr.update(visible=False), gr.update(visible=False)
|
459 |
)
|
460 |
# Handle user response to confirmation
|
461 |
+
if re.search(r"\b(no|cancel|stop|exit|abort|لا|إلغاء|مش عايز|خلص|مافيش داعي|كفاية|انهاء)\b", message.strip().lower()):
|
462 |
user_form_data["timestamp"] = datetime.now().isoformat()
|
463 |
user_form_data["type"] = form_type.capitalize()
|
464 |
|
|
|
486 |
user_form_data, form_type = {}, None
|
487 |
return history + [("", msg1)], "", gr.update(visible=True), gr.update(visible=False), gr.update(visible=False), gr.update(visible=False)
|
488 |
|
489 |
+
elif re.search(r"\b(no|cancel|exit|stop|لا|إلغاء|انهاء|خروج|مش عايز|مافيش داعي|كفاية|سيبك)\b", message.strip().lower()):
|
490 |
+
|
491 |
user_form_data, form_type = {}, None
|
492 |
return history + [("", "No problem. The form has been discarded. How else can I help you?")], "", gr.update(visible=True), gr.update(visible=False), gr.update(visible=False), gr.update(visible=False)
|
493 |
|
|
|
511 |
form_type = "demo"
|
512 |
user_form_data = {}
|
513 |
form_questions = get_form_definition(form_type, language)
|
514 |
+
first_question = get_form_definition(form_type, language)[0][1]
|
515 |
return history + [(message, "بالتأكيد! لنبدأ ببعض المعلومات:" if language == "ar" else "Sure! Let's start with a few details."), ("", first_question)], "", gr.update(visible=True), gr.update(visible=False), gr.update(visible=False), gr.update(visible=False)
|
516 |
|
517 |
|
|
|
521 |
form_type = "contact"
|
522 |
user_form_data = {}
|
523 |
form_questions = get_form_definition(form_type, language)
|
524 |
+
first_question = get_form_definition(form_type, language)[0][1]
|
525 |
welcome_msg = "بالطبع! يرجى تعبئة البيانات التالية:" if language == "ar" else "Of course! Please fill out the following."
|
526 |
return history + [(message, welcome_msg), ("", first_question)], "", gr.update(visible=True), gr.update(visible=False, choices=[]), gr.update(visible=False, value=[]), gr.update(visible=False)
|
527 |
|