yashMahajan commited on
Commit
d638867
·
verified ·
1 Parent(s): f13cda4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -5
app.py CHANGED
@@ -39,18 +39,35 @@ def respond(
39
 
40
  response = response.strip()
41
 
42
- # Check relevance with leniency
43
- if "constitution" in message.lower() or "law" in message.lower() or "rights" in message.lower():
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
44
  return response
45
 
46
- # Provide response even for less relevant questions
47
- return response or "Sorry, I can only answer questions related to the Constitution of India. Please ask a relevant question."
48
 
49
  # Create the Gradio chat interface
50
  demo = gr.ChatInterface(
51
  respond,
52
  additional_inputs=[
53
- gr.Textbox(value="You are a knowledgeable assistant specializing in the Constitution of India. Answer only questions related to the Constitution. If the question is less relevant but potentially related, still provide an answer.", label="System message", visible=False),
54
  gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
55
  gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
56
  gr.Slider(
 
39
 
40
  response = response.strip()
41
 
42
+ # Keywords to check in the response
43
+ relevant_keywords = [
44
+ "constitution", "article", "law", "legal", "rights", "act", "judiciary",
45
+ "legislature", "executive", "fundamental", "amendment", "provision",
46
+ "policy", "directive", "supreme court", "high court", "legislation",
47
+ "government", "election", "parliament", "state", "central", "reform",
48
+ "citizen", "equality", "democracy", "directive principles", "fundamental duties",
49
+ "preamble", "enforcement", "federalism", "separation of powers", "justice",
50
+ "republic", "state legislature", "union territory", "bill", "ordinance",
51
+ "convention", "charter", "treaty", "declaration", "proclamation", "amendments",
52
+ "compensation", "grievance", "judicial review", "secularism", "socialism",
53
+ "pluralism", "sovereignty", "autonomy", "independence", "integrity", "caste",
54
+ "reservation", "minorities", "discrimination", "fundamental rights",
55
+ "emergency", "state emergency", "national emergency", "local bodies",
56
+ "tribunal", "ombudsman", "civil rights", "criminal justice", "human rights"
57
+ ]
58
+
59
+ # Check if response contains any relevant keywords
60
+ if any(keyword in response.lower() for keyword in relevant_keywords):
61
  return response
62
 
63
+ # If response does not contain relevant keywords
64
+ return "Sorry, I am a chatbot specializing in questions related to the Constitution of India. Please ask a relevant question."
65
 
66
  # Create the Gradio chat interface
67
  demo = gr.ChatInterface(
68
  respond,
69
  additional_inputs=[
70
+ gr.Textbox(value="You are a knowledgeable assistant specializing in the Constitution of India. Answer only questions related to the Constitution. If the answer does not contain relevant constitutional keywords, inform the user accordingly.", label="System message", visible=False),
71
  gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
72
  gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
73
  gr.Slider(