yashMahajan
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -39,6 +39,14 @@ def respond(
|
|
39 |
|
40 |
response = response.strip()
|
41 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
42 |
# Keywords to check in the response
|
43 |
relevant_keywords = [
|
44 |
"constitution", "article", "law", "legal", "rights", "act", "judiciary",
|
@@ -57,11 +65,7 @@ def respond(
|
|
57 |
]
|
58 |
|
59 |
# Check if response contains relevant keywords
|
60 |
-
|
61 |
-
return response
|
62 |
-
|
63 |
-
# If response does not contain relevant keywords
|
64 |
-
return "Sorry, I can only provide information related to the Constitution of India. Please ask a question related to the Constitution."
|
65 |
|
66 |
# Create the Gradio chat interface
|
67 |
demo = gr.ChatInterface(
|
|
|
39 |
|
40 |
response = response.strip()
|
41 |
|
42 |
+
# Enhanced context-specific relevance check
|
43 |
+
if is_relevant_to_constitution(response):
|
44 |
+
return response
|
45 |
+
|
46 |
+
# If response does not meet relevance criteria
|
47 |
+
return "Sorry, I can only provide information related to the Constitution of India. Please ask a question related to the Constitution."
|
48 |
+
|
49 |
+
def is_relevant_to_constitution(response):
|
50 |
# Keywords to check in the response
|
51 |
relevant_keywords = [
|
52 |
"constitution", "article", "law", "legal", "rights", "act", "judiciary",
|
|
|
65 |
]
|
66 |
|
67 |
# Check if response contains relevant keywords
|
68 |
+
return any(keyword in response.lower() for keyword in relevant_keywords)
|
|
|
|
|
|
|
|
|
69 |
|
70 |
# Create the Gradio chat interface
|
71 |
demo = gr.ChatInterface(
|