Sarathrsk03 commited on
Commit
7728950
·
verified ·
1 Parent(s): 070416c

Upload 5 files

Browse files
Files changed (5) hide show
  1. app.py +104 -0
  2. dataset.csv +15 -0
  3. llmConnect.py +55 -0
  4. requirements.txt +75 -0
  5. systemInstruction.txt +12 -0
app.py ADDED
@@ -0,0 +1,104 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import llmConnect
3
+ import csv
4
+ from dotenv import load_dotenv
5
+ import os
6
+
7
+ load_dotenv()
8
+
9
+ def authenticate(user,password):
10
+ if user == os.getenv("username") and password == os.getenv("password"):
11
+ return True
12
+ return False
13
+
14
+ def generate_questions(topic):
15
+ llmConnect.addToDataset(topic)
16
+
17
+ def readDataset():
18
+ with open('dataset.csv', 'r') as file:
19
+ data = list(csv.reader(file))
20
+ return data
21
+
22
+ def getFirstQuestion(topic):
23
+ generate_questions(topic)
24
+ data = readDataset()
25
+ question = data[0][1]
26
+ answers = data[0][2:6]
27
+ return question, gr.update("answer",choices=answers)
28
+
29
+ def nextQuestion(question_no):
30
+ data = readDataset()
31
+ if question_no < len(data):
32
+ question = data[question_no][1]
33
+ answers = data[question_no][2:6]
34
+ return question, gr.update("answer",choices=answers)
35
+ return "Quiz completed!", gr.update("answer",choices=["Quiz completed"])
36
+
37
+ with gr.Blocks() as demo:
38
+ # Initialize states
39
+ user_answers = gr.State([])
40
+ question_no = gr.State(0)
41
+
42
+ with gr.Row():
43
+ with gr.Column():
44
+ topic = gr.Textbox(
45
+ label="Topic",
46
+ placeholder="Enter the topic you want to generate questions for"
47
+ )
48
+ submit = gr.Button(value="Generate Questions")
49
+
50
+ with gr.Column():
51
+ question = gr.Textbox(label="Question", elem_id="question")
52
+ answer = gr.Dropdown(
53
+ label="Answer",
54
+ interactive=True,
55
+ elem_id="answer",
56
+ multiselect=False,
57
+ allow_custom_value=False,
58
+ filterable=False
59
+ )
60
+
61
+ def handle_next(ans, answers, q_no):
62
+ # Store the answer
63
+ answers.append(ans)
64
+ # Increment question number
65
+ next_q_no = q_no + 1
66
+ # Get next question
67
+ question, new_answers = nextQuestion(next_q_no)
68
+ return question, new_answers, answers, next_q_no
69
+
70
+ next = gr.Button(value="Next Question")
71
+ next.click(
72
+ handle_next,
73
+ inputs=[answer, user_answers, question_no],
74
+ outputs=[question, answer, user_answers, question_no]
75
+ )
76
+
77
+ submit.click(
78
+ getFirstQuestion,
79
+ inputs=[topic],
80
+ outputs=[question, answer]
81
+ )
82
+
83
+ with gr.Column():
84
+ score = gr.Textbox(
85
+ label="Score",
86
+ placeholder="Your score will be displayed here"
87
+ )
88
+
89
+ def calculate_score(answers):
90
+ data = readDataset()
91
+ correct_answers = []
92
+ for i in range(len(data)):
93
+ correct_answers.append(data[i][1+int(data[i][6])])
94
+ score = sum(1 for a, c in zip(answers, correct_answers) if a == c)
95
+ return f"Your score: {score}/{len(answers)}"
96
+
97
+ submit_score = gr.Button(value="Submit")
98
+ submit_score.click(
99
+ calculate_score,
100
+ inputs=[user_answers],
101
+ outputs=[score]
102
+ )
103
+
104
+ demo.launch(auth=authenticate)
dataset.csv ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ 1,What does the term 'Corporate Veil' refer to in the context of corporate law?,The legal separation between a company and its shareholders,The physical security measures for corporate buildings,The privacy policies of a company,The confidentiality agreements between a company and its employees,1
2
+ 2,"Which legislation primarily governs the formation, operation, and management of companies in India?","The Indian Contract Act, 1872","The Companies Act, 2013","The Securities and Exchange Board of India Act, 1992","The Indian Partnership Act, 1932",2
3
+ 3,What is the main difference between a public company and a private company?,"Public companies have limited liability, while private companies have unlimited liability","Public companies can invite the public to subscribe to their shares, whereas private companies cannot","Public companies are required to hold an Annual General Meeting, private companies are not",Public companies are larger in size compared to private companies,2
4
+ 4,What is the role of the 'Board of Directors' in a company?,To manage the day-to-day operations of the company,To represent the employees of the company,To provide legal advice to the company,To oversee the overall strategy and governance of the company,4
5
+ 5,What does 'Memorandum of Association' (MoA) of a company define?,The internal rules and regulations of the company,The procedures for calling board meetings,The relationship between the company and its shareholders,The company's objectives and scope of operations,4
6
+ 6,What is 'Corporate Social Responsibility' (CSR) as per Indian law?,An optional activity of a company to engage in philanthropic work,A mandatory activity for certain companies to contribute to society,A tax deduction for companies engaging in environmental protection,A marketing strategy for companies to enhance their image,2
7
+ 7,What are 'Independent Directors' on a company's board?,Directors who are appointed by the government,Directors who have no financial or personal relationship with the company,Directors who are appointed by the shareholders,Directors who manage the day-to-day operations of the company,2
8
+ 8,What is the significance of 'Annual General Meeting' (AGM) of a company?,A meeting to discuss the company's daily operations,A meeting to select new directors,A mandatory meeting of shareholders to discuss the company's performance and future plans,A meeting to only declare the annual profits,3
9
+ 9,What does 'Insider Trading' refer to in the context of corporate law?,Buying or selling company shares based on non-public information,Trading shares using a brokerage account,Engaging in trade with foreign countries,Disclosing company secrets to the media,1
10
+ 10,What is 'Limited Liability' in the context of a company?,The liability of a company is limited to its employees,The liability of the shareholders is limited to the amount they have invested in the company,The liability of a company is limited to its assets,The liability of directors is limited to their salary,2
11
+ 11,What is the purpose of 'Articles of Association' (AoA) of a company?,To define the relationship between a company and the public,To define the objectives of the company,To define the internal rules and regulations for the management of a company,To define the registered office address of a company,3
12
+ 12,What are the consequences of a company failing to comply with the provisions of the Companies Act?,It may be awarded with a tax exemption,"It may be subject to penalties, fines, or even imprisonment of its directors",It will be given a notice period of 1 year to make changes,It may be considered a success,2
13
+ 13,What is the concept of 'Winding Up' or 'Liquidation' of a company?,The process of starting a new business venture,The process of transferring control of the company to new owners,The process of dissolving the company and distributing its assets among creditors and shareholders,The process of rebranding the company,3
14
+ 14,Which body regulates the capital markets in India and oversees the issue of shares and securities?,Reserve Bank of India (RBI),Securities and Exchange Board of India (SEBI),Ministry of Corporate Affairs (MCA),National Stock Exchange (NSE),2
15
+ 15,What does the term 'Registered Office' of a company signify?,The office where the company's directors meet,The company's official correspondence address,The location of the company's factory or manufacturing unit,The location where the shareholders of the company reside,2
llmConnect.py ADDED
@@ -0,0 +1,55 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from google import genai
2
+ from google.genai import types
3
+ from dotenv import load_dotenv
4
+ import os
5
+ import json
6
+ load_dotenv()
7
+ import csv
8
+
9
+
10
+ try:
11
+ client = genai.Client(api_key=os.getenv('geminiAPI'))
12
+ except Exception as e:
13
+ print("Error: ", e)
14
+
15
+
16
+ def readSystemInstructions():
17
+ try:
18
+ with open('systemInstruction.txt', 'r') as file:
19
+ data = file.read()
20
+ return data
21
+ except Exception as e:
22
+ print("Error: ", e)
23
+ return None
24
+
25
+
26
+ def generateSyntheticData(topic:str):
27
+ response = client.models.generate_content(
28
+ model="gemini-2.0-flash-exp",
29
+ contents= topic ,
30
+ config = types.GenerateContentConfig(
31
+ response_mime_type="application/json",
32
+ system_instruction= readSystemInstructions()
33
+ )
34
+ )
35
+
36
+ return json.loads(response.text)
37
+
38
+
39
+
40
+
41
+
42
+ def addToDataset(topic:str):
43
+ data = generateSyntheticData(topic)
44
+ with open('dataset.csv', 'w') as file:
45
+ writer = csv.writer(file)
46
+ for i in data:
47
+ for question_number, question_details in i.items():
48
+ writer.writerow([question_number,question_details['question'],question_details['options'][0],question_details['options'][1],question_details['options'][2],question_details['options'][3],question_details['correct_choice']])
49
+ print("Added to dataset")
50
+
51
+
52
+ if __name__ == "__main__":
53
+ addToDataset(topic="Python Programming")
54
+
55
+
requirements.txt ADDED
@@ -0,0 +1,75 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ aiofiles==23.2.1
2
+ altair==5.5.0
3
+ annotated-types==0.7.0
4
+ anyio==4.8.0
5
+ attrs==25.1.0
6
+ blinker==1.9.0
7
+ cachetools==5.5.1
8
+ certifi==2025.1.31
9
+ charset-normalizer==3.4.1
10
+ click==8.1.8
11
+ fastapi==0.115.8
12
+ ffmpy==0.5.0
13
+ filelock==3.17.0
14
+ fsspec==2024.12.0
15
+ gitdb==4.0.12
16
+ GitPython==3.1.44
17
+ google-auth==2.38.0
18
+ google-genai==0.8.0
19
+ gradio==5.14.0
20
+ gradio_client==1.7.0
21
+ h11==0.14.0
22
+ httpcore==1.0.7
23
+ httpx==0.28.1
24
+ huggingface-hub==0.28.1
25
+ idna==3.10
26
+ Jinja2==3.1.5
27
+ jsonschema==4.23.0
28
+ jsonschema-specifications==2024.10.1
29
+ markdown-it-py==3.0.0
30
+ MarkupSafe==2.1.5
31
+ mdurl==0.1.2
32
+ narwhals==1.24.1
33
+ numpy==2.2.2
34
+ orjson==3.10.15
35
+ packaging==24.2
36
+ pandas==2.2.3
37
+ pillow==11.1.0
38
+ protobuf==5.29.3
39
+ pyarrow==19.0.0
40
+ pyasn1==0.6.1
41
+ pyasn1_modules==0.4.1
42
+ pydantic==2.10.6
43
+ pydantic_core==2.27.2
44
+ pydeck==0.9.1
45
+ pydub==0.25.1
46
+ Pygments==2.19.1
47
+ python-dateutil==2.9.0.post0
48
+ python-dotenv==1.0.1
49
+ python-multipart==0.0.20
50
+ pytz==2025.1
51
+ PyYAML==6.0.2
52
+ referencing==0.36.2
53
+ requests==2.32.3
54
+ rich==13.9.4
55
+ rpds-py==0.22.3
56
+ rsa==4.9
57
+ ruff==0.9.4
58
+ safehttpx==0.1.6
59
+ semantic-version==2.10.0
60
+ shellingham==1.5.4
61
+ six==1.17.0
62
+ smmap==5.0.2
63
+ sniffio==1.3.1
64
+ starlette==0.45.3
65
+ tenacity==9.0.0
66
+ toml==0.10.2
67
+ tomlkit==0.13.2
68
+ tornado==6.4.2
69
+ tqdm==4.67.1
70
+ typer==0.15.1
71
+ typing_extensions==4.12.2
72
+ tzdata==2025.1
73
+ urllib3==2.3.0
74
+ uvicorn==0.34.0
75
+ websockets==14.2
systemInstruction.txt ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ Your job is to generate 15 questions on the given topic
2
+ Difficulty level: Medium
3
+
4
+ Generate the question and 4 options
5
+ Also return the choice no which is the correct option
6
+
7
+ Return type: JSON
8
+ key : question number
9
+ value : all other data
10
+
11
+ Example:
12
+ [{'1': {'question': 'Which article of the Indian Constitution deals with the establishment of the Supreme Court?', 'options': ['Article 120', 'Article 124', 'Article 130', 'Article 136'], 'correct_choice': '2'}}, {'2': {'question': 'What is the term of office for a judge of the High Court in India?', 'options': ['5 years', '6 years', 'Until the age of 62', 'Until the age of 65'], 'correct_choice': '3'}}, {'3': {'question': 'Which of the following is NOT a type of jurisdiction exercised by the Supreme Court of India?', 'options': ['Original Jurisdiction', 'Appellate Jurisdiction', 'Advisory Jurisdiction', 'Administrative Jurisdiction'], 'correct_choice': '4'}}, {'4': {'question': "The concept of 'Public Interest Litigation' (PIL) originated in which country?", 'options': ['United Kingdom', 'United States', 'India', 'Australia'], 'correct_choice': '2'}}, {'5': {'question': 'Under which schedule of the Indian Constitution are the provisions related to the administration and control of Scheduled Areas and Scheduled Tribes laid down?', 'options': ['Fifth Schedule', 'Sixth Schedule', 'Seventh Schedule', 'Eighth Schedule'], 'correct_choice': '1'}}, {'6': {'question': "Which constitutional amendment introduced the concept of 'Lok Adalats'?", 'options': ['42nd Amendment', '44th Amendment', '73rd Amendment', 'None of the above'], 'correct_choice': '4'}}, {'7': {'question': 'Who has the power to transfer a judge from one High Court to another in India?', 'options': ['President of India', 'Chief Justice of India', 'Parliament', 'Law Minister'], 'correct_choice': '1'}}, {'8': {'question': 'Which is the highest law officer of the Government of India?', 'options': ['Attorney General of India', 'Solicitor General of India', 'Chief Justice of India', 'Law Minister'], 'correct_choice': '1'}}, {'9': {'question': 'The power of Judicial Review in India is derived from which of the following?', 'options': ['Constitution of India', 'Parliamentary Statute', 'Presidential Ordinance', 'Supreme Court Judgement'], 'correct_choice': '1'}}, {'10': {'question': "What is the meaning of 'Habeas Corpus'?", 'options': ['To have the body', 'To give a command', 'To be informed', 'To certify'], 'correct_choice': '1'}}, {'11': {'question': 'Which part of the Indian Constitution deals with the Union Judiciary?', 'options': ['Part IV', 'Part V', 'Part VI', 'Part VII'], 'correct_choice': '2'}}, {'12': {'question': 'The National Legal Services Authority (NALSA) was constituted under which Act?', 'options': ['The Legal Practitioners Act, 1879', 'The Code of Civil Procedure, 1908', 'The Legal Services Authorities Act, 1987', 'The Constitution of India'], 'correct_choice': '3'}}, {'13': {'question': 'Which of the following is NOT a writ jurisdiction of the High Courts in India?', 'options': ['Habeas Corpus', 'Mandamus', 'Certiorari', 'Interlocutory'], 'correct_choice': '4'}}, {'14': {'question': 'How many High Courts are there in India?', 'options': ['20', '25', '30', '35'], 'correct_choice': '2'}}, {'15': {'question': 'Who is the appointing authority of the District Judges in India?', 'options': ['President of India', 'Governor of the State', 'Chief Justice of India', 'Chief Justice of the High Court'], 'correct_choice': '2'}}]