Skip to content

Commit 7c5ed88

Browse files
committed
multi user update
1 parent cada856 commit 7c5ed88

File tree

5 files changed

+24
-19
lines changed

5 files changed

+24
-19
lines changed

Backend/LatestSorter.py

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -56,19 +56,20 @@ def process_files(user:str):
5656
)
5757
print("reseting")
5858
# Function to read and process a file
59-
def process_file(file_name):
59+
def process_file(file_name,user1):
6060

6161

6262

6363
# Read file from S3
64-
65-
response = s3.get_object(Bucket='learnmateai', Key=user+'pyqs_txt/' + file_name)
64+
print(user1)
65+
response = s3.get_object(Bucket='learnmateai', Key=user1+'pyqs_txt/' + file_name)
6666
file_content = response['Body'].read().decode('utf-16-le')
6767

6868
# Split file content into batches (adjust batch size as needed)
6969
batch_size = 30000
7070
batches = [file_content[i:i+batch_size] for i in range(0, len(file_content), batch_size)]
71-
response2 = s3.get_object(Bucket='learnmateai', Key= user+"syllabus_pdf/syllabus.txt")
71+
print(user1+"syllabus_pdf/syllabus.txt")
72+
response2 = s3.get_object(Bucket='learnmateai', Key= user1+"syllabus_pdf/syllabus.txt")
7273
topics = response2['Body'].read().decode('utf-8')
7374
# Process batches
7475
Sorted_PYQ_Mod=[[]for _ in range(5)]
@@ -96,7 +97,7 @@ def process_file(file_name):
9697
#print(text_batches)
9798

9899
bucket_name = 'learnmateai'
99-
folder_name = 'Sorted_PYQS/'
100+
folder_name = user1+'Sorted_PYQS/'
100101

101102

102103
i=0
@@ -117,7 +118,7 @@ def process_file(file_name):
117118
s3.put_object(Bucket=bucket_name, Key=folder_name+"Module"+str(i+1)+".txt", Body=updated_content.encode('utf-8'))
118119

119120
# Print uploaded file information
120-
print(f"File uploaded to '{bucket_name}/{folder_name}'")
121+
print(f"File uploaded to '{user1}{bucket_name}/{folder_name}'")
121122
i=i+1
122123

123124

@@ -142,7 +143,7 @@ def process_file(file_name):
142143
s3.put_object(Bucket=bucket_name, Key=folder_name+"Module"+str(i+1)+".txt", Body=updated_content.encode('utf-8'))
143144

144145
# Print uploaded file information
145-
print(f"File uploaded to '{bucket_name}/{folder_name}'")
146+
print(f"File uploaded to '{user1}{bucket_name}/{folder_name}'")
146147
i=i+1
147148
else:
148149
print("An error occurred:", e)
@@ -151,11 +152,13 @@ def process_file(file_name):
151152

152153

153154
# Get the list of files in the "notes_txt" folder
154-
response = s3.list_objects_v2(Bucket='learnmateai', Prefix='pyqs_txt/')
155+
response = s3.list_objects_v2(Bucket='learnmateai', Prefix=user+'pyqs_txt/')
155156

156157
# Process each file
157158
for file in response['Contents']:
159+
print(file)
158160
file_name = file['Key'].split('/')[-1]
159-
process_file(file_name)
161+
print(file_name)
162+
process_file(file_name,user)
160163

161164
return {"message": "PYQS SORTED"}

Backend/Notes_gen.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,10 @@
1414
openai.api_key = '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'
1515

1616
@app.get("/note_gen")
17-
async def summarize_s3_files():
17+
async def summarize_s3_files(user:str):
18+
user=user+"/"
1819
bucket_name= "learnmateai"
19-
folder_name= "Analysed_Notes"
20+
folder_name= user+"Analysed_Notes"
2021
try:
2122
response = s3.list_objects_v2(Bucket=bucket_name, Prefix=folder_name)
2223
for file in response['Contents']:
@@ -25,7 +26,7 @@ async def summarize_s3_files():
2526
print(file_name)
2627
summary = await summarize_file(bucket_name, file_key,file_name)
2728
print(summary)
28-
save_summary(file_name, summary)
29+
save_summary(file_name, summary,user)
2930
return {'message': 'Created Notes and saved successfully.'}
3031
except Exception as e:
3132
return {'error': str(e)}
@@ -50,10 +51,10 @@ async def summarize_file(bucket_name: str, file_key: str, file_name:str):
5051
except Exception as e:
5152
raise e
5253

53-
def save_summary(file_name: str, summary: str):
54+
def save_summary(file_name: str, summary: str,user):
5455
try:
5556
file_name=file_name.split(".txt")[0]
56-
save_key = f'Notes_Topicwise/{file_name}.txt'
57+
save_key = f'{user}Notes_Topicwise/{file_name}.txt'
5758
s3.put_object(Body=summary, Bucket=s3_bucket_name, Key=save_key)
5859
except Exception as e:
5960
raise e

Backend/Sections_topics_json.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,11 @@ def processor( data):
3030
return summary
3131

3232
@app.get("/card-json")
33-
async def makejson():
33+
async def makejson(user:str):
34+
user=user+"/"
3435
text=""
3536
bucket_name= "learnmateai"
36-
folder_name= "Analysed_Notes"
37+
folder_name= user+"Analysed_Notes"
3738
try:
3839
response = s3.list_objects_v2(Bucket=bucket_name, Prefix=folder_name)
3940
for file in response['Contents']:
@@ -46,7 +47,7 @@ async def makejson():
4647
print(text)
4748

4849
json_text=processor(text)
49-
save_plan(json_text)
50+
save_plan(json_text,user)
5051
# Parse the file content as JSON
5152
json_content = json.loads(json_text)
5253

@@ -58,9 +59,9 @@ async def makejson():
5859

5960

6061

61-
def save_plan( summary: str):
62+
def save_plan( summary: str,user):
6263
try:
63-
save_key = f'Cardjson/cards.txt'
64+
save_key = f'{user}Cardjson/cards.txt'
6465
s3.put_object(Body=summary, Bucket=s3_bucket_name, Key=save_key)
6566
except Exception as e:
6667
raise e
108 Bytes
Binary file not shown.
46 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)