| |
| |
|
|
| |
| from sentence_transformers import SentenceTransformer |
| from transformers import pipeline |
| import faiss |
| import numpy as np |
| import gradio as gr |
|
|
| |
| legal_texts = [ |
| |
| "Is dowry illegal in India? -> Yes, under the Dowry Prohibition Act, 1961, giving, taking, or demanding dowry is illegal and punishable by up to 3 years of imprisonment and fines.", |
| "What are a woman's rights after marriage? -> A woman has rights to residence, maintenance, dignity, and protection against domestic violence under Indian law.", |
|
|
| |
| "How can a woman file for divorce? -> A woman can file for divorce on grounds such as cruelty, adultery, desertion, conversion, mental disorder, and mutual consent under the Hindu Marriage Act, 1955.", |
| "Can a divorced woman claim maintenance? -> Yes, under Section 125 of the Criminal Procedure Code (CrPC), a divorced woman can claim maintenance if she cannot maintain herself.", |
|
|
| |
| "What protections does a woman have under the Domestic Violence Act? -> The Protection of Women from Domestic Violence Act, 2005 grants women the right to protection orders, residence, monetary relief, and child custody.", |
| "What is domestic violence under Indian law? -> Domestic violence includes physical, emotional, sexual, verbal, and economic abuse against a woman within the family.", |
|
|
| |
| "What rights do women have at the workplace? -> Under the POSH Act, 2013, women have the right to a safe working environment and can file complaints about sexual harassment at the workplace.", |
| "How can a woman report sexual harassment at work? -> She can file a complaint with the Internal Complaints Committee (ICC) established under the POSH Act, 2013.", |
|
|
| |
| "Can daughters inherit ancestral property? -> Yes, under the Hindu Succession (Amendment) Act, 2005, daughters have equal rights to ancestral property as sons.", |
| "What happens to a woman's property after marriage? -> A woman's property remains solely hers after marriage unless she chooses to transfer or gift it voluntarily.", |
|
|
| |
| "What are a woman's rights during pregnancy at work? -> Under the Maternity Benefit Act, 1961, a woman is entitled to 26 weeks of paid maternity leave for the first two children.", |
| "Is it legal to fire a woman during maternity leave? -> No, dismissing a woman during maternity leave is illegal under the Maternity Benefit Act.", |
|
|
| |
| "How can a woman file an FIR for harassment? -> A woman can directly approach a police station to file an FIR. As per Supreme Court guidelines, no woman can be denied lodging an FIR.", |
| "Can a woman file an online police complaint? -> Yes, many Indian states offer online FIR and grievance redressal portals where women can file complaints remotely.", |
|
|
| |
| "What are the laws against sexual assault in India? -> Sections 354, 354A, 354B, 354C, and 354D of IPC deal with outraging a woman's modesty, harassment, stalking, and voyeurism.", |
| "Is marital rape recognized in Indian law? -> As of now, marital rape is not fully criminalized under Indian law except under certain circumstances like child marriage or separation cases.", |
| |
| |
| "Is child marriage illegal in India? -> Yes, under the Prohibition of Child Marriage Act, 2006, marriage below 18 years (for girls) and 21 years (for boys) is illegal and punishable.", |
|
|
| |
| "What protections exist against human trafficking? -> The Immoral Traffic (Prevention) Act, 1956 criminalizes trafficking of women and girls for prostitution.", |
| "Can women working as domestic helpers claim protection? -> Yes, domestic workers are entitled to protection under labor laws and state-level welfare boards.", |
|
|
| |
| "What are a woman's rights against cyberbullying? -> A woman facing online abuse, threats, or revenge porn can report under the Information Technology Act, 2000 and IPC Section 66A, 67, 67A.", |
| "How can a woman report cybercrime? -> She can file a complaint at the nearest Cyber Crime Cell or use the online portal: cybercrime.gov.in.", |
|
|
| |
| "Are women entitled to joint property after marriage? -> In case of divorce, women can claim maintenance and residential rights but automatic rights over husband's property depend on various factors.", |
| "Do women have banking rights without husband/family permission? -> Yes, adult women have the full legal right to operate independent bank accounts and investments.", |
|
|
| |
| "What are a widow's rights to husband's property? -> A widow has a rightful share in her deceased husband's property under the Hindu Succession Act, 1956.", |
|
|
| |
| "What are a woman's rights regarding child custody after divorce? -> Custody decisions are based on the child's welfare. Generally, mothers are granted custody for minor children unless proven unfit.", |
|
|
| |
| "What legal protections exist against acid attacks? -> Acid attacks are punishable under IPC Sections 326A and 326B with imprisonment up to 10 years or life, along with fines.", |
| "Can acid attack victims get compensation? -> Yes, acid attack victims are entitled to free medical treatment and compensation under Supreme Court rulings and state schemes.", |
|
|
| |
| "Can a woman legally terminate a pregnancy? -> Under the Medical Termination of Pregnancy (MTP) Act, 1971, a woman can legally terminate a pregnancy up to 24 weeks under certain conditions.", |
|
|
| |
| "Do women have the right to equal pay? -> Yes, under the Equal Remuneration Act, 1976, women must be paid equally to men for the same work.", |
| "Can a woman demand workplace creche facilities? -> Under the Maternity Benefit (Amendment) Act, 2017, organizations with more than 50 employees must provide creche facilities." |
| ] |
|
|
|
|
| |
| model = SentenceTransformer('all-MiniLM-L6-v2') |
| embeddings = model.encode(legal_texts) |
|
|
| |
| dimension = embeddings.shape[1] |
| index = faiss.IndexFlatL2(dimension) |
| index.add(np.array(embeddings)) |
|
|
| |
| generator = pipeline('text-generation', model='tiiuae/falcon-7b-instruct', max_new_tokens=100) |
|
|
| |
| def empowerbot_answer(user_query): |
| |
| query_embedding = model.encode([user_query]) |
| |
| |
| D, I = index.search(np.array(query_embedding), k=1) |
| matched_text = legal_texts[I[0][0]] |
| |
| |
| prompt = f"You are an expert legal assistant for women. Based on the following law: {matched_text} \n\nAnswer the user's question: {user_query}" |
| |
| |
| output = generator(prompt)[0]['generated_text'] |
| |
| return output |
|
|
| |
| def feedback_loop(user_query, correct_answer): |
| |
| with open('feedback_data.txt', 'a') as f: |
| f.write(f"Query: {user_query}\nCorrect Answer: {correct_answer}\n\n") |
| |
| print("Feedback received, thank you for helping improve EmpowerBot!") |
|
|
| |
| def chatbot_interface(user_input): |
| answer = empowerbot_answer(user_input) |
| return answer |
|
|
| |
| def rate_answer(user_input, correct_answer): |
| feedback_loop(user_input, correct_answer) |
| return "Thank you for your feedback!" |
|
|
| |
| iface = gr.Interface(fn=chatbot_interface, |
| inputs=gr.Textbox(label="Ask your question about women's legal rights"), |
| outputs=gr.Textbox(label="EmpowerBot's Answer"), |
| title="EmpowerBot - Women's Legal Assistant", |
| description="Ask EmpowerBot about women's rights and get reliable legal information.") |
|
|
| feedback_iface = gr.Interface(fn=rate_answer, |
| inputs=[gr.Textbox(label="Your Query"), gr.Textbox(label="Correct Answer")], |
| outputs="text", |
| title="Provide Feedback", |
| description="Help improve EmpowerBot by providing feedback on answers.") |
|
|
| |
| iface.launch() |
| |