Skip to content

Commit 208e103

Browse files
committed
update
1 parent c8a7ff1 commit 208e103

16 files changed

+512
-111
lines changed

Backend/NotesToText.py

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -19,23 +19,8 @@
1919

2020
router = APIRouter()
2121

22-
def download_files_from_s3(bucket_name, prefix, local_directory):
23-
24-
paginator = s3.get_paginator('list_objects_v2')
25-
operation_parameters = {'Bucket': bucket_name, 'Prefix': prefix}
26-
27-
page_iterator = paginator.paginate(**operation_parameters)
28-
29-
for page in page_iterator:
30-
if 'Contents' in page:
31-
for item in page['Contents']:
32-
key = item['Key']
33-
local_file_path = os.path.join(local_directory, os.path.basename(key))
34-
s3.download_file(bucket_name, key, local_file_path)
35-
print(f"Downloaded {key} to {local_file_path}")
3622

3723

38-
3924
def pdf_to_images_from_bytes(pdf_content, output_folder, file_name):
4025
s3_bucket_name = 'learnmateai'
4126

-497 Bytes
Binary file not shown.
645 Bytes
Binary file not shown.
1 Byte
Binary file not shown.
-79 Bytes
Binary file not shown.

Backend/cluster_qns.py

Lines changed: 0 additions & 14 deletions
This file was deleted.

Backend/new_sorter.py

Lines changed: 77 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#pyqsorter , sorts set of pyqs into modules
21
from fastapi import APIRouter
32
import os
43
import re
@@ -7,36 +6,72 @@
76
import tensorflow as tf
87
import tensorflow_hub as hub
98
from sklearnex import patch_sklearn
9+
import boto3
10+
from botocore.exceptions import NoCredentialsError
1011
patch_sklearn()
1112
from sklearn.cluster import KMeans
12-
13-
14-
13+
import tempfile
14+
from io import BytesIO
1515

1616
# Create an instance of APIRouter
1717
test = APIRouter()
1818

19+
# AWS S3 configuration
20+
AWS_ACCESS_KEY_ID = 'AKIAZTHHIOR4CN6UXO6N'
21+
AWS_SECRET_ACCESS_KEY = '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'
22+
AWS_BUCKET_NAME = 'learnmateai'
23+
AWS_BUCKET_FOLDER = 'pyqs_txt'
24+
25+
s3_client = boto3.client(
26+
's3',
27+
aws_access_key_id=AWS_ACCESS_KEY_ID,
28+
aws_secret_access_key=AWS_SECRET_ACCESS_KEY
29+
)
30+
1931
def extract_questions_from_file(filepath):
20-
with open(filepath, 'rb') as f:
21-
result = chardet.detect(f.read())
22-
encoding = result['encoding']
23-
with open(filepath, encoding=encoding) as f:
24-
content = f.read()
25-
pattern = r'((?:[IVX]+|\([a-z]\))\. .*(?:\n\s+\(\w\)\. .*)*)'
26-
matches = re.findall(pattern, content)
27-
questions = [re.sub(r'\n\s+\(\w\)\. ', ' ', match.strip()) for match in matches]
32+
questions = []
33+
with open(filepath, 'rb') as file:
34+
content = file.read()
35+
encoding = chardet.detect(content)['encoding']
36+
decoded_content = content.decode(encoding, errors='ignore')
37+
questions = re.findall(r'\b(?:what|where|why|how|when|which|who|whom|whose)\b.*[?!.]', decoded_content, re.IGNORECASE)
2838
return questions
2939

30-
3140
def extract_questions_from_directory(directory):
41+
paginator = s3_client.get_paginator('list_objects_v2')
42+
operation_parameters = {'Bucket': AWS_BUCKET_NAME, 'Prefix': directory}
43+
44+
page_iterator = paginator.paginate(**operation_parameters)
45+
46+
try:
47+
if not os.path.exists("temp1/pyqs_txt"):
48+
os.makedirs("temp1/pyqs_txt") # Create directory if it doesn't exist
49+
for page in page_iterator:
50+
if 'Contents' in page:
51+
for item in page['Contents']:
52+
key = item['Key']
53+
local_file_path = os.path.join("temp1/pyqs_txt", os.path.basename(key)) # Use basename of key as local file name
54+
try:
55+
s3_client.download_file(AWS_BUCKET_NAME, key, local_file_path)
56+
print(f"Downloaded {key} to {local_file_path}")
57+
except Exception as e:
58+
print(f"Failed to download {key}: {str(e)}")
59+
except Exception as e:
60+
print(f"An error occurred during pagination: {str(e)}")
61+
return []
62+
3263
questions = []
33-
for filename in os.listdir(directory):
34-
filepath = os.path.join(directory, filename)
64+
for filename in os.listdir("temp1/pyqs_txt"):
65+
filepath = os.path.join("temp1/pyqs_txt", filename)
3566
if os.path.isfile(filepath):
3667
questions += extract_questions_from_file(filepath)
68+
3769
return questions
3870

39-
def cluster_questions_1(questions, num_clusters):
71+
def cluster_questions(questions, num_clusters):
72+
if len(questions) == 0:
73+
return None, []
74+
4075
module_url = "https://tfhub.dev/google/universal-sentence-encoder-large/5"
4176

4277
embed = hub.load(module_url)
@@ -53,17 +88,17 @@ def cluster_questions_1(questions, num_clusters):
5388

5489
return y_kmeans, repeated_indices
5590

56-
5791
@test.get("/api1")
5892
def api1_handler():
59-
questions = extract_questions_from_directory('Local_Storage/pyqs_text')
93+
questions = extract_questions_from_directory(AWS_BUCKET_FOLDER)
6094
num_clusters = 4
61-
62-
labels, repeated_indices = cluster_questions_1(questions, num_clusters)
95+
96+
labels, repeated_indices = cluster_questions(questions, num_clusters)
6397

6498
print("Clustering questions")
6599
for i in range(num_clusters):
66-
cluster_questions = np.array(questions)[np.where(labels == i)[0]]
100+
cluster_indices = np.where(labels == i)[0]
101+
cluster_questions = np.array(questions)[cluster_indices]
67102
print(f"Module {i+1}:")
68103
for question in cluster_questions:
69104
print(f" - {question}")
@@ -74,21 +109,33 @@ def api1_handler():
74109
for index in repeated_indices:
75110
print(f" - {questions[index]}")
76111

77-
with open('Local_Storage/Generated_Files/cluster_questions.txt', 'w') as f:
112+
try:
113+
# Write cluster questions to S3
114+
cluster_questions_content = ""
78115
for i in range(num_clusters):
79-
cluster_questions = np.array(questions)[np.where(labels == i)[0]]
80-
f.write(f"Module {i+1}:\n")
116+
cluster_indices = np.where(labels == i)[0]
117+
cluster_questions = np.array(questions)[cluster_indices]
118+
cluster_questions_content += f"Module {i+1}:\n"
81119
for question in cluster_questions:
82-
f.write(f" - {question}\n")
83-
f.write("\n")
120+
cluster_questions_content += f" - {question}\n"
121+
cluster_questions_content += "\n"
84122

85-
# Write repeated questions to file
123+
# Write repeated questions to S3
86124
if repeated_indices:
87-
f.write("Repeated Questions:\n")
125+
cluster_questions_content += "Repeated Questions:\n"
88126
for index in repeated_indices:
89-
f.write(f" - {questions[index]}\n")
127+
cluster_questions_content += f" - {questions[index]}\n"
128+
129+
s3_client.put_object(
130+
Body=cluster_questions_content.encode(),
131+
Bucket=AWS_BUCKET_NAME,
132+
Key='Generated_Files/cluster_questions.txt'
133+
)
134+
135+
return {"message": "Previous Year question papers sorted into modules"}
136+
except NoCredentialsError:
137+
return {"message": "Failed to write to S3. Credentials not available."}
90138

91-
return {"message": "Previous Year question papers sorted to modules"}
92139

93140
@test.post("/api1")
94141
def api1_post_handler():

Backend/pyqsorter.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from sklearnex import patch_sklearn
1010
patch_sklearn()
1111
from sklearn.cluster import KMeans
12-
from pathlib import path
12+
from pathlib import Path
1313

1414

1515

Lines changed: 6 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,14 @@
11
Module 1:
2-
- II. Simplify the following Boolean function into (1) sum-of-products form
3-
- V. Implement the following function using a multiplexer
4-
- II. Simplify the following function using Quine McCluskey method.
5-
- IV. Simplify the following Boolean function into (i) sum-of-products form and
6-
- V. Implement the following Boolean function with NAND gates: OR
7-
- VI. Implement the following function using a multiplexer (Use B as input).
8-
- I. (a) (
9-
- III. (a) Simplify the followng Boolean functions using K-map (5)
10-
- I. (a) Perform the following:
11-
- III. Simplify the following Boolean function using the tabulation method.
12-
- VIII. Differentiate PLA and PAL. Draw the PLA for functions: (10)
13-
- III. (a) Simplify the following Boolean function into (6)
14-
- IV. (a) Implement the following four Boolean expressions with three half adders: (6)
15-
- VIII. (a) Design a PLA circuit to implement the functions (6)
2+
- VII. (a) Explain the internal organization of a memory chip which has 16 words
3+
- VIII. (a)
164

175
Module 2:
18-
- III. Prove the theorems of Boolean algebra by using postulates.
19-
- I. (a) Perform the following number conversions:
20-
- IV. Derive the expressions for a 4-bit magnitude comparator and implement it
21-
- V. (a) Design a decimal adder using 4-bit binary parallel adders.
22-
- IV. (a) Explain the working of a 4-bit BCD adder with block diagram (7)
23-
- V. (a) Explain the working of a 4-bit magnitude comparator. (5)
24-
- II. (a) What is a gray code? What are the advantages of gray code? Find the gray (3)
25-
- V. (a) Explain the working of Decimal adder with block diagram and explain the (5)
26-
- X. (5)
27-
- I. (a) Given the two binary numbers X = 1010100 and Y = 1000011, perform the
28-
- V. (a) What is Carry Propagation delay? Design a 4- bit binary parallel adder (6)
6+
- I. (a) With necessary diagrams, explain the mechanism of address ffanslation
297

308
Module 3:
31-
- I. (a) Convert (63.25) 10 to Hexa decimal and octal.
32-
- VII. Design and explain a 4 bit asynchronous up-down binary counter.
33-
- VIII. Write short notes on (1) Fan in and Fan out (ii) Propogation delay
34-
- VI. Design a 4-bit Johnson counter. How does it differ from a ring counter?
35-
- VII. Design a 4-bit binary ripple counter using JK flip flops.
36-
- VIII. Design a RAM consisting of four words of four bits each. Also show the
37-
- I. (a) Convert (AB2)16 to octal.
38-
- VII. Design a 4 bit binary ripple counter using JK flip flops. OR
39-
- II. (a) Using 10's complement, subtract 3250-72532. (2)
40-
- VII. Design a counter that has repeated sequence of six states 0,1,2,4,5,6 using JK OR (10)
41-
- VII. (a) Design a 2 bit synchronous up counter using .1K flipflops. (5)
42-
- VI. (a) Design a synchronous counter using .T flip-flops which counts the (6)
43-
- VII. (a) Draw the logic diagram of a four-bit binary ripple counter. Show that a (6)
9+
- II. (a) With a neat diagram,,t explain the functional units of a computer.
10+
- V. (a) Explain the purpose of carry save addition of summands in
4411

4512
Module 4:
46-
- IV. Explain the design procedure of combinational circuit with an example
47-
- IX. Compare TTL and CMOS logic families.
48-
- VIII. Explain the operation of 2 input CMOS NOR gate and CMOS inverter in
49-
- IX. Explain with circuit diagram a typical 2 input TTL NAND gate.
50-
- VI. (a) Explain the working of SR latch with NAND gate with the help of logic diagram (6)
51-
- VIII. (a) Design a combinational circuit using a ROM.The circuit accepts three bit (6)
52-
- IX. Explain the working of RTL and DTL circuit. Explain how fan-out of DTL gate (10)
53-
- VI. (a) Explain the working of SR latch using NOR gate with the help of logic (6)
54-
- IX. (a) Draw and explain the working of Basic RTL NOR gate. (5)
55-
- IX. (a) Draw circuit of an TTL NAND gate and explain the operation. (7)
13+
- I. (a) Explain the single bus structure with a neat diagrarn.
5614

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+

0 commit comments

Comments
 (0)