Update app.py
Browse files
app.py
CHANGED
@@ -1,5 +1,6 @@
|
|
1 |
import gradio as gr
|
2 |
-
from transformers import pipeline
|
|
|
3 |
|
4 |
# Load Arabic NLP model for intent classification
|
5 |
intent_classifier = pipeline("text-classification", model="aubmindlab/bert-base-arabertv02")
|
@@ -30,6 +31,12 @@ INTENT_TO_RESPONSE = {
|
|
30 |
"contact": "contact"
|
31 |
}
|
32 |
|
|
|
|
|
|
|
|
|
|
|
|
|
33 |
def classify_intent(message: str):
|
34 |
# Use NLP model to classify the user's intent
|
35 |
result = intent_classifier(message)
|
@@ -37,6 +44,13 @@ def classify_intent(message: str):
|
|
37 |
return INTENT_TO_RESPONSE.get(intent, "unknown")
|
38 |
|
39 |
def respond(message: str):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
40 |
# Classify the user's intent using NLP
|
41 |
intent = classify_intent(message)
|
42 |
|
|
|
1 |
import gradio as gr
|
2 |
+
from transformers import pipeline
|
3 |
+
from langdetect import detect
|
4 |
|
5 |
# Load Arabic NLP model for intent classification
|
6 |
intent_classifier = pipeline("text-classification", model="aubmindlab/bert-base-arabertv02")
|
|
|
31 |
"contact": "contact"
|
32 |
}
|
33 |
|
34 |
+
def detect_language(text):
|
35 |
+
try:
|
36 |
+
return detect(text)
|
37 |
+
except:
|
38 |
+
return "unknown"
|
39 |
+
|
40 |
def classify_intent(message: str):
|
41 |
# Use NLP model to classify the user's intent
|
42 |
result = intent_classifier(message)
|
|
|
44 |
return INTENT_TO_RESPONSE.get(intent, "unknown")
|
45 |
|
46 |
def respond(message: str):
|
47 |
+
# Detect language
|
48 |
+
language = detect_language(message)
|
49 |
+
|
50 |
+
# If the language is not Arabic, return a default response
|
51 |
+
if language != "ar":
|
52 |
+
return "عذرًا، هذا المساعد يدعم اللغة العربية فقط. الرجاء إعادة الصياغة بالعربية."
|
53 |
+
|
54 |
# Classify the user's intent using NLP
|
55 |
intent = classify_intent(message)
|
56 |
|