Skip to content

Commit

Permalink
Version 1.2 Go-Bot
Browse files Browse the repository at this point in the history
  • Loading branch information
raaasin committed Sep 24, 2023
1 parent 0d574f2 commit 55d8840
Show file tree
Hide file tree
Showing 15 changed files with 106 additions and 155 deletions.
17 changes: 12 additions & 5 deletions app.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from flask import Flask, render_template, request, jsonify
from qna import pipe
from judge import classifier

from models.roberta import pipe
from models.bart import classifier
from models.pGPT import tokenizer,generate_next,to_var,personas,flatten
dialog_hx=[]
app = Flask(__name__)

chat_history = []
Expand All @@ -28,9 +29,15 @@ def ask():
chat_history.append(("Chatbot", answer))
return jsonify({"answer": answer})
else:
answer="I'm sorry I didn't catch that"

user_inp = tokenizer.encode(">> User: "+ question + tokenizer.eos_token)
dialog_hx.append(user_inp)
bot_input_ids = to_var([personas + flatten(dialog_hx)]).long()
msg = generate_next(bot_input_ids)
dialog_hx.append(msg)
answer="{}".format(tokenizer.decode(msg, skip_special_tokens=True))
chat_history.append(("Chatbot", answer))
return jsonify({"answer": answer})

if __name__ == "__main__":
app.run(debug=True)
56 changes: 45 additions & 11 deletions data/data2.txt
Original file line number Diff line number Diff line change
@@ -1,21 +1,55 @@
Once upon a time in the quaint village of Eldertown, nestled deep within a dense forest, there lived a young woman named Elara. She was known far and wide for her captivating green eyes, which seemed to hold secrets of the universe. But it wasn't just her eyes that set her apart; it was her extraordinary ability to manipulate time.
The Article deals with the power of Center & State to make laws relating to mines and minerals in India....
Laws Relating to Mines & Minerals in India

Elara's gift had been passed down through generations of her family. Her ancestors were the Timekeepers, responsible for maintaining the balance of time in the world. Each Timekeeper possessed a unique time-manipulating skill. Elara's power was to glimpse into the past and future.
The essence of federalism lies in the sharing of legal sovereignty by the Union and the federating units. And, in general, the most precise way of demarcating the respective areas of the federation and federating units is to demarcate their respective areas in regard to legislation. There are many reasons for this; but one of the most important, is the demarcation of legislative power which helps in defining boundaries that of the executive power also, as usually the former controls the latter.

One sunny morning, while Elara was strolling through the forest, she stumbled upon an ancient, moss-covered hourglass hidden beneath the roots of a colossal oak tree. As she touched it, a surge of energy coursed through her, and her time-manipulating abilities grew even stronger.
The constitutional provisions in India on the subject of distribution of legislative powers between the Union and the States are spread out over several articles (articles 245-254). However, the most important of those provisions – i.e, the basic one – is that contained in articles 245-246.

With her newfound power, Elara decided to embark on a journey to uncover the secrets of the hourglass and her family's legacy. She knew that her unique gift was linked to this mysterious artifact. Guided by her intuition, she set off with her loyal friend, a mischievous fox named Finn, who had been her companion since childhood.
Article 245 provides, inter alia, that (subject to the provisions of the Constitution).

Their quest took them through treacherous terrains, enchanted forests, and mystical caverns. Along the way, they encountered peculiar creatures and wise sages who shared tales of the hourglass's origin. Legends spoke of a great Timekeeper who had crafted it eons ago, imbuing it with the power to unlock the wisdom of the ages.
# Parliament may make laws for the whole or any part of the territory of India and
# the legislature of a State may make laws for the whole or any part of the State.

As Elara and Finn delved deeper into their adventure, they encountered challenges that tested their friendship and their resolve. They faced riddles from talking owls, crossed bridges guarded by mischievous trolls, and deciphered cryptic maps drawn by ancient spirits. Each trial brought them closer to the hourglass's true purpose.
Thus, article 245 sets out the limits of the legislative powers of the Union and the States from the geographical (or territorial) angle. From the point of view of the subject matter of legislation, it is article 246 which is important. Article 246 reads as under:

One fateful night, under a canopy of shimmering stars, they reached the heart of the forest. There, they found the Timekeeper's sanctuary, a place of ethereal beauty and serenity. At its center stood the hourglass, glowing with an otherworldly light.
1) Notwithstanding anything in clauses (2) and (3), Parliament has exclusive power to make laws with respect to any of the matters enumerated in List 1 of the Seventh Schedule (in this Constitution, referred to as the “Union List”).

Elara touched the hourglass, and her vision began to blur. She saw glimpses of her ancestors, her family's history intertwined with the very fabric of time itself. She understood that her gift was not just a power to wield but a responsibility to uphold.
2) Notwithstanding anything in clause (3), Parliament, and subject to clause (1), the Legislature of any State also, shall have power to make laws with respect to any of the matters enumerated in List III in the Seventh Schedule (in this Constitution, referred to as the “Concurrent List”).

With the hourglass's wisdom, Elara learned how to use her powers to bring harmony and healing to the world. She could mend the wounds of the past and guide the future towards peace and prosperity. She became a true Timekeeper, fulfilling her family's legacy.
3) Subject to clauses (1) and (2), the Legislature of any State has exclusive power to make laws for such State or any part thereof with respect to any of the matters enumerated in List II in the Seventh Schedule (in this Constitution, referred to as the “State List”)

As the years passed, Elara and Finn continued their adventures, using their newfound knowledge to make the world a better place. They protected the forest, helped those in need, and shared the wisdom of the hourglass with all who sought it.
4) Parliament has power to make laws with respect to any matter for any part of the territory of India not included in a State, notwithstanding that such matter is a matter enumerated in the State List”.

And so, the story of Elara, the Timekeeper, and her faithful friend Finn, was passed down through generations as a tale of hope, friendship, and the enduring power of time itself.
The co-existence of Central and State laws in a particular area can give rise to litigation. Such problems arise, either because the Union or a State may illegally encroach upon the province of the other (parallel) legislature, or they may arise because (though there is no encroachment, as such, on each other’s sphere), the two laws clash with each other.

The two situations are, strictly speaking, different from each other; and they must be judged by two different tests. Where the subject-matter of the legislation in question falls within either the Union List or the State list only, then the question is to be decided with reference to legislative competence. One of the two laws must necessarily be void, because (leaving aside matters in the Concurrent List), the Indian Constitution confers exclusive jurisdiction upon Parliament for matters in the Union List and upon a State Legislature for matters in the State List. The correct doctrine applicable in such cases is that of ultra vires. Since one of the two laws must be void, the question of inconsistency between the two has no relevance. Only one law will survive; and the other law will not survive, because ex hypothesi, it has no life.
In contrast, where the legislation passed by the Union and the State is on a subject matter included in the Concurrent List, then the matter cannot be determined by applying the test of ultra vires because the hypothesis is, that both the laws are (apart from repugnancy), constitutionally valid. In such a case, the test to be adopted will be that of repugnancy, under article 254(2), of the Constitution.

It follows, that it is only where the legislation is on a matter in the Concurrent List, that it would be relevant to apply the test of repugnancy. Notwithstanding the contrary view expressed in some quarters, this appears to be the correct position. Such a view was expressed by Dr. D. Basu in his Commentary on the Constitution of India (1950) 1st edition, page 564, and it is this view, that seems to have been upheld (impliedly) by the Supreme Court in the under - mentioned decisions: -

1. Deep Chand v. State of U.P., AIR 1959 SC 648; (1959) Suppl. 2 SCR 8.
2. Premnath v. State of J & K, AIR 1959 SC 749 (1959) Suppl 2 SCR 270.
3. Ukha v. State of Maharashtra, AIR 1963 SC 1531, paragraph 20.
4. Bar Council, U.P. v. State of U.P., AIR 1973 SC 231, 238; (1973) 1 SCC 261.
5. Barani v. Henry, AIR 1983 SC 150, paragraph 15.
6. Hoechst Pharmaceuticals v. State of Bihar, AIR 1983 SC 1020, paragraphs 68, 69 and 76 (Full decisoon of the position).
7. Pochanna Lingappa v. State of Maharashtra, AIR 1985 SC 389, paragraph 26; (1985) 1 SCC 425.
8. Vijay Kumar Sharma v. State of Karnataka, AIR 1990 SC 2072 [For decisions in section 107, Government of India Act, 1935 see Lakhi Narayan Das v. Province of Bihar, AIR 1950 FC 59.]

Four salient features mark the scheme of distribution of legislative powers under the Indian Constitution.
1) There is a three-fold distribution of legislative power-represented by three lists – Union, State and Concurrent.

2) The supremacy of federal laws is maintained in two situations (which are the principal situations of practical importance):

a. in determining the extent of legislative power of the federation and the units, (if a doubt arises as to the list in which a particular subject of legislation falls, the non obstante clause in article 246 achieves federal supremacy);

b. in determining the question whether a federal law will prevail or a State law will prevail; (if both have an impact on a particular human activity, and are in conflict with each other, then the federal law prevails).

3) If a particular topic does not find an express mention in the three legislative lists, then the power to legislate thereon (i.e., the residuary law-making power) is vested in the federation.

4) In certain situations (even apart from emergencies), the federation may come to be vested with legislative power, even on state subjects.

[Mr. Justice, E. S. Venkataramiah and P. M. Bakshi, Indian Federalism (1992), pages 72-73, para 7.1].
In the federal structure of India, the State Governments are the owner of minerals located within the boundaries of the State concerned. Although mineral wealth vests with the State Govt., yet the subject of regulation of Mines and Minerals development is covered under 7th schedule of constitution of India. Rule making powers in respect of minor minerals have been delegated to the States under section 15 of this Act.

In accordance with article 297 of the Constitution, the Central Government is the owner of the minerals underlying the ocean within the territorial waters or the Exclusive Economic Zone of India. In this connection, entry at serial No. 23 of List II (State list) to the Constitution provides that ‘Regulation of mines and mineral development subject to the provisions of List I with respect to regulation and development under the control of the Union’, are within the purview of States while entry at serial No. 54 of List I states that ‘Regulation of mines and mineral development to the extent to which such regulation and development under the control of the Union is declared by Parliament by law to be expedient in the public interest’ shall be within the purview of the Central Government. In pursuance to entry at serial No. 54 of List I, Parliament has passed legislation titled ‘The Mines & Minerals (Development and Regulation) Act, 1957’ as Central Act (No. 67 of 1957)
Binary file not shown.
66 changes: 0 additions & 66 deletions jupyter/.ipynb_checkpoints/model-checkpoint.ipynb

This file was deleted.

6 changes: 0 additions & 6 deletions jupyter/model-checkpoint.ipynb

This file was deleted.

66 changes: 0 additions & 66 deletions jupyter/model.ipynb

This file was deleted.

Binary file added models/__pycache__/bart.cpython-310.pyc
Binary file not shown.
Binary file added models/__pycache__/pGPT.cpython-310.pyc
Binary file not shown.
Binary file added models/__pycache__/roberta.cpython-310.pyc
Binary file not shown.
File renamed without changes.
41 changes: 41 additions & 0 deletions models/pGPT.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
from transformers import GPT2Tokenizer, GPT2LMHeadModel
import torch
tokenizer = GPT2Tokenizer.from_pretrained("af1tang/personaGPT")
model = GPT2LMHeadModel.from_pretrained("af1tang/personaGPT")
if torch.cuda.is_available():
model = model.cuda()
## utility functions ##
flatten = lambda l: [item for sublist in l for item in sublist]

def to_data(x):
if torch.cuda.is_available():
x = x.cpu()
return x.data.numpy()

def to_var(x):
if not torch.is_tensor(x):
x = torch.Tensor(x)
if torch.cuda.is_available():
x = x.cuda()
return x

def display_dialog_history(dialog_hx):
for j, line in enumerate(dialog_hx):
msg = tokenizer.decode(line)
if j %2 == 0:
print(">> User: "+ msg)
else:
print("Bot: "+msg)
print()

def generate_next(bot_input_ids, do_sample=True, top_k=10, top_p=.92,
max_length=1000, pad_token=tokenizer.eos_token_id):
full_msg = model.generate(bot_input_ids, do_sample=True,
top_k=top_k, top_p=top_p,
max_length=max_length, pad_token_id=tokenizer.eos_token_id)
msg = to_data(full_msg.detach()[0])[bot_input_ids.shape[-1]:]
return msg
# get personality facts for conversation
personas=['I am military veteran<|endoftext|>', 'I like to promote about joining the Indian navy <|endoftext|>', 'I am a good person who helps everyone<|endoftext|>']
personas = tokenizer.encode(''.join(['<|p2|>'] + personas + ['<|sep|>'] + ['<|start|>']))
# converse for 8 turns
File renamed without changes.
5 changes: 5 additions & 0 deletions models/test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from transformers import GPT2Tokenizer, GPT2LMHeadModel
tokenizer = GPT2Tokenizer.from_pretrained("af1tang/personaGPT")
model = GPT2LMHeadModel.from_pretrained("af1tang/personaGPT")
personas=['I am military veteran<|endoftext|>', 'I like to promote about joining the Indian navy <|endoftext|>', 'I am a good person who helps everyone<|endoftext|>']
personas = tokenizer.encode(''.join(['<|p2|>'] + personas + ['<|sep|>'] + ['<|start|>']))
1 change: 0 additions & 1 deletion output.py

This file was deleted.

3 changes: 3 additions & 0 deletions req.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
flask
transformers
torch
haystack

0 comments on commit 55d8840

Please sign in to comment.