Skip to content

Commit ec11e0c

Browse files
committed
Merge branch 'dev1'
2 parents b9b5455 + 9f45e56 commit ec11e0c

19 files changed

+728
-34
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
venv/
22
Backend/requirements.txt
3-
dat.txt
3+
dat.txt
4+
temp.txt
5+
Backend/test.py
0 Bytes
Binary file not shown.
2.91 KB
Binary file not shown.
-1.06 KB
Binary file not shown.
2.92 KB
Binary file not shown.

Backend/cluster_processor.py

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
import re
2+
3+
def remove_extra_whitespace(input_file, output_file):
4+
with open(input_file, 'r') as file:
5+
content = file.read()
6+
7+
# Remove unwanted characters before numbering
8+
content = re.sub(r'(?<=\n)\s*-+\s*', '', content)
9+
10+
# Remove Roman numbering and add decimal numbering
11+
decimal_number = 1
12+
content = re.sub(r'(?<=\n)([IVXLCDM]+\.)(?=\s)', lambda match: str(decimal_number) + '.', content)
13+
decimal_number += 1
14+
15+
# Remove extra white spaces
16+
content = re.sub(' +', ' ', content)
17+
18+
with open(output_file, 'w') as file:
19+
file.write(content)
20+
21+
22+
def number_questions(input_filename, output_filename):
23+
section_count = 0
24+
question_count = 0
25+
current_section = ""
26+
27+
with open(input_filename, 'r') as input_file:
28+
lines = input_file.readlines()
29+
30+
with open(output_filename, 'w') as output_file:
31+
for line in lines:
32+
# Check if the line starts with "Module X:"
33+
if re.match(r'^Module \d+:', line):
34+
section_count += 1
35+
question_count = 0
36+
current_section = re.findall(r'^Module \d+', line)[0]
37+
output_file.write(line)
38+
# Check if the line starts with "1.", "(a)", or "(i)"
39+
elif re.match(r'^\d+\.|^[(a-z)]\.|^[(i)]\.', line):
40+
question_count += 1
41+
# Modify the line to include the correct question number
42+
modified_line = re.sub(r'^(\d+\.|^[(a-z)]\.|^[(i)]\.)', str(question_count) + '.', line)
43+
# Replace the section number if necessary
44+
modified_line = modified_line.replace(current_section, 'Module ' + str(section_count))
45+
output_file.write(modified_line)
46+
else:
47+
output_file.write(line)
48+
49+
50+
# Usage example
51+
input_file = 'Local_Storage\Generated_Files\cluster_questions.txt' # Replace with your input file path
52+
temp_file = 'temp_output.txt' # Replace with a temporary output file path
53+
output_file = 'final_output.txt' # Replace with your final output file path
54+
55+
# Step 1: Remove extra whitespace
56+
remove_extra_whitespace(input_file, temp_file)
57+
58+
# Step 2: Number the questions
59+
number_questions(temp_file, output_file)
60+
61+
# Step 3: Clean up the temporary file
62+
import os
63+
os.remove(temp_file)

Backend/process_cluster_1.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import re
2+
3+
def remove_extra_whitespace(input_file, output_file):
4+
with open(input_file, 'r') as file:
5+
content = file.read()
6+
7+
# Remove unwanted characters before numbering
8+
content = re.sub(r'(?<=\n)\s*-+\s*', '', content)
9+
10+
# Remove Roman numbering and add decimal numbering
11+
decimal_number = 1
12+
content = re.sub(r'(?<=\n)([IVXLCDM]+\.)(?=\s)', lambda match: str(decimal_number) + '.', content)
13+
decimal_number += 1
14+
15+
# Remove extra white spaces
16+
content = re.sub(' +', ' ', content)
17+
18+
with open(output_file, 'w') as file:
19+
file.write(content)
20+
21+
# Usage example
22+
input_file = 'Local_Storage\Generated_Files\cluster_questions.txt' # Replace with your input file path
23+
output_file = 'output.txt' # Replace with your output file path
24+
remove_extra_whitespace(input_file, output_file)

Backend/process_cluster_2.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import re
2+
3+
def number_questions(input_filename, output_filename):
4+
section_count = 0
5+
question_count = 0
6+
current_section = ""
7+
8+
with open(input_filename, 'r') as input_file:
9+
lines = input_file.readlines()
10+
11+
with open(output_filename, 'w') as output_file:
12+
for line in lines:
13+
# Check if the line starts with "Module X:"
14+
if re.match(r'^Module \d+:', line):
15+
section_count += 1
16+
question_count = 0
17+
current_section = re.findall(r'^Module \d+', line)[0]
18+
output_file.write(line)
19+
# Check if the line starts with "1.", "(a)", or "(i)"
20+
elif re.match(r'^\d+\.|^[(a-z)]\.|^[(i)]\.', line):
21+
question_count += 1
22+
# Modify the line to include the correct question number
23+
modified_line = re.sub(r'^(\d+\.|^[(a-z)]\.|^[(i)]\.)', str(question_count) + '.', line)
24+
# Replace the section number if necessary
25+
modified_line = modified_line.replace(current_section, 'Module ' + str(section_count))
26+
output_file.write(modified_line)
27+
else:
28+
output_file.write(line)
29+
30+
# Usage
31+
input_filename = "output.txt" # Replace with the actual input filename
32+
output_filename = "numbered_questions.txt" # Replace with the desired output filename
33+
number_questions(input_filename, output_filename)

Backend/test4.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import re
2+
3+
# Read input from text file
4+
with open('question_papers/cluster_questions.txt', 'r') as file:
5+
text = file.read()
6+
7+
# Remove old numbering and add decimal numbering
8+
lines = text.split('\n')
9+
module_questions = {}
10+
current_module = None
11+
question_number = 1
12+
13+
for line in lines:
14+
if line.startswith('Module'):
15+
current_module = re.findall(r'\d+', line)[0]
16+
module_questions[current_module] = []
17+
question_number = 1
18+
elif line.strip().startswith('-'):
19+
question = line.strip()[1:].strip()
20+
if question.startswith('('):
21+
question = question[1:].strip()
22+
question = re.sub(r'^[IVX]+\.?\s*', str(question_number) + '. ', question)
23+
module_questions[current_module].append(question)
24+
question_number += 1
25+
26+
# Save module questions to a file
27+
with open('module_questions.txt', 'w') as file:
28+
for module, questions in module_questions.items():
29+
file.write(f"Module {module}:\n")
30+
for question in questions:
31+
file.write(f"{question}\n")
32+
33+
print("Module questions saved to 'module_questions.txt' file.")

Backend/test5.py

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import torch
2+
from transformers import GPT2LMHeadModel, GPT2Tokenizer
3+
4+
# Load the pre-trained model and tokenizer
5+
model_name = 'gpt2'
6+
model = GPT2LMHeadModel.from_pretrained(model_name)
7+
tokenizer = GPT2Tokenizer.from_pretrained(model_name)
8+
9+
def generate_model_questions(input_questions, num_questions=1):
10+
# Encode input questions
11+
input_ids = tokenizer.encode(input_questions, return_tensors='pt')
12+
13+
# Generate model questions
14+
max_length = 512 # Adjust the maximum length of the generated questions
15+
temperature = 1.0 # Adjust the temperature for controlling randomness
16+
17+
model_questions = []
18+
for _ in range(num_questions):
19+
outputs = model.generate(
20+
input_ids,
21+
max_length=max_length,
22+
num_return_sequences=1,
23+
temperature=temperature,
24+
repetition_penalty=1.0,
25+
pad_token_id=tokenizer.eos_token_id,
26+
early_stopping=True
27+
)
28+
29+
# Decode the generated model question
30+
model_question = tokenizer.decode(outputs[0], skip_special_tokens=True)
31+
model_questions.append(model_question)
32+
33+
return model_questions
34+
35+
# Example usage
36+
input_questions = """1. Explain the design procedure of combinational circuit with an example
37+
2. Implement the following function using a multiplexer
38+
3. Compare TTL and CMOS logic families.
39+
4. Implement the following Boolean function with NAND gates: OR
40+
5. Implement the following function using a multiplexer (Use B as input)"""
41+
model_questions = generate_model_questions(input_questions)
42+
43+
print("Input Question:")
44+
print(input_questions)
45+
print("\nModel Questions:")
46+
for i, question in enumerate(model_questions, 1):
47+
print(f"{i}. {question}")

0 commit comments

Comments
 (0)