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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -8
app.py CHANGED
@@ -39,21 +39,18 @@ def respond(
39
 
40
  response = response.strip()
41
 
42
- # Basic filter to determine relevance
43
- if any(keyword in message.lower() for keyword in ["constitution", "article", "law", "legal", "rights", "act", "judiciary", "legislature", "executive"]):
44
  return response
45
 
46
- # If message does not relate to Constitution or is not a scenario
47
- if "scenario" in message.lower() or "case" in message.lower() or "example" in message.lower():
48
- return response
49
-
50
- return "Sorry, I am a chatbot specializing in questions related to the Constitution of India. Please ask a relevant question."
51
 
52
  # Create the Gradio chat interface
53
  demo = gr.ChatInterface(
54
  respond,
55
  additional_inputs=[
56
- 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 irrelevant, inform the user accordingly.", label="System message", visible=False),
57
  gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
58
  gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
59
  gr.Slider(
 
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(