Skip to content

Commit b469b6e

Browse files
committed
apis
1 parent 1ec0c77 commit b469b6e

File tree

10 files changed

+57
-11
lines changed

10 files changed

+57
-11
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@ Backend/requirements.txt
33
dat.txt
44
temp.txt
55
Backend/test.py
6-
main.py
6+
main.py
7+
iteration3/

Backend/Final_Processor.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ async def fetch_data(link:str,receiver_email: str ):
2020
response5 = await client.get(f"{link}/question_gen?user={receiver_email}")
2121

2222

23+
2324
payload = {
2425
"receiver_email": receiver_email,
2526
"subject": "LearnMateAI",

Backend/Perfect_video.py

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,19 @@
66
from youtube_transcript_api import YouTubeTranscriptApi
77
from sentence_transformers import SentenceTransformer
88
import torch
9+
import boto3
10+
11+
12+
aws_access_key_id = 'AKIAZTHHIOR4JJ5HLTUB'
13+
aws_secret_access_key = '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'
14+
bucket_name = 'learnmateai'
15+
16+
# Create an S3 client
17+
s3_client = boto3.client("s3",
18+
aws_access_key_id=aws_access_key_id,
19+
aws_secret_access_key=aws_secret_access_key)
20+
21+
922

1023
app = APIRouter()
1124

@@ -38,8 +51,25 @@ def get_video_transcripts(video_ids):
3851
return transcripts
3952

4053
@app.get("/best_video")
41-
def get_best_video(input_text: str):
54+
def get_best_video(email: str,topic: str):
55+
56+
57+
prefix = f"{email}/Notes_Topicwise"
58+
59+
response = s3_client.list_objects_v2(Bucket=bucket_name, Prefix=prefix)
60+
61+
62+
63+
64+
65+
if "Contents" in response:
66+
file_key = prefix + f"/{topic}"
67+
file_obj = s3_client.get_object(Bucket=bucket_name, Key=file_key)
68+
file_content = file_obj["Body"].read().decode("utf-8")
69+
print(file_content)
4270
# Encode the input text
71+
input_text = file_content
72+
4373
input_embedding = model.encode([input_text], convert_to_tensor=True)
4474

4575
# Search for videos and retrieve video transcripts
@@ -59,6 +89,6 @@ def get_best_video(input_text: str):
5989
best_video_id = ranked_videos[0][0]
6090

6191
# Construct the YouTube video URL
62-
best_video_url = f"https://www.youtube.com/watch?v={best_video_id}"
92+
best_video_url = f"https://www.youtube.com/embed/{best_video_id}"
6393

6494
return {"best_video_url": best_video_url}

Backend/Study_planner.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,16 @@ def processor( data,current_data, final_date):
2929
summary = response.choices[0].message.content
3030
return summary
3131

32-
@app.get("/getdata")
33-
async def makeplan(current_date: str,final_date: str):
32+
@app.post("/genStudyPlan")
33+
async def generateStudyPlan(email: str,current_date: str,final_date: str):
3434
text=""
3535
bucket_name= "learnmateai"
36-
folder_name= "Analysed_Notes"
36+
folder_name= f"{email}/Analysed_Notes"
3737
try:
3838
response = s3.list_objects_v2(Bucket=bucket_name, Prefix=folder_name)
3939
for file in response['Contents']:
4040
file_key = file['Key']
41+
print(file_key)
4142
file_name = os.path.basename(file_key)
4243
file_name=file_name.split(".txt")[0]
4344
text=text+"\n"+file_name
@@ -46,7 +47,7 @@ async def makeplan(current_date: str,final_date: str):
4647
print(text)
4748

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

@@ -58,9 +59,9 @@ async def makeplan(current_date: str,final_date: str):
5859

5960

6061

61-
def save_plan( summary: str):
62+
def save_plan(email,summary):
6263
try:
63-
save_key = f'StudyPlan/plan.txt'
64+
save_key = f'{email}/StudyPlan/studyplan.json'
6465
s3.put_object(Body=summary, Bucket=s3_bucket_name, Key=save_key)
6566
except Exception as e:
6667
raise e
557 Bytes
Binary file not shown.
80 Bytes
Binary file not shown.
314 Bytes
Binary file not shown.

Backend/file_sender.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,24 @@ def get_cardData(email: str):
6767

6868
response = s3_client.list_objects_v2(Bucket=bucket_name, Prefix=prefix)
6969

70-
7170
if "Contents" in response:
7271
for obj in response["Contents"]:
7372
file_key = obj["Key"]
7473
file_obj = s3_client.get_object(Bucket=bucket_name, Key=file_key)
7574
file_content = file_obj["Body"].read().decode("utf-8")
7675
json_data = json.loads(file_content)
77-
return json_data
76+
return json_data
77+
78+
@getfiles.post("/studyPlan")
79+
def getStudyPlan(email: str):
80+
prefix = f"{email}/StudyPlan"
81+
82+
response = s3_client.list_objects_v2(Bucket=bucket_name, Prefix=prefix)
83+
84+
if "Contents" in response:
85+
file_key = prefix + "/plan.json"
86+
file_obj = s3_client.get_object(Bucket=bucket_name, Key=file_key)
87+
file_content = file_obj["Body"].read().decode("utf-8")
88+
json_data = json.loads(file_content)
89+
return json_data
90+

__pycache__/main.cpython-310.pyc

134 Bytes
Binary file not shown.

iteration3.txt

2.08 KB
Binary file not shown.

0 commit comments

Comments
 (0)