Skip to content

Byte404 #28

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 344 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
344 commits
Select commit Hold shift + click to select a range
a285218
Update Notes_Analyser.py
ANGELOANTU7 May 23, 2023
510e986
Update Notes_Analyser.py
ANGELOANTU7 May 23, 2023
b85236b
edit Notes ana..
ANGELOANTU7 May 23, 2023
a12ec38
Update Notes_Analyser.py
ANGELOANTU7 May 23, 2023
c8c7a67
Update Notes_Analyser.cpython-310.pyc
ANGELOANTU7 May 23, 2023
db5aa19
changing output directory of analyser
ANGELOANTU7 May 23, 2023
e27d236
Update Notes_Analyser.py
ANGELOANTU7 May 23, 2023
928d4e7
deleting curr files in generated files
ANGELOANTU7 May 23, 2023
1afaaf0
Update Notes_Analyser.cpython-310.pyc
ANGELOANTU7 May 23, 2023
bbaeaed
Update README.md
ANGELOANTU7 May 23, 2023
501f785
Update README.md
ANGELOANTU7 May 23, 2023
6579bc9
Update README.md
ANGELOANTU7 May 23, 2023
1908c30
Update README.md
ANGELOANTU7 May 23, 2023
a59259d
Update README.md
ANGELOANTU7 May 23, 2023
506bba6
Update README.md
ANGELOANTU7 May 23, 2023
ffa95e8
Update README.md
ANGELOANTU7 May 23, 2023
f8de4d0
hero 3
harshedabdulla May 23, 2023
2906395
Merge branch 'main' of https://github.com/ANGELOANTU7/intel-hack into…
harshedabdulla May 23, 2023
7696d60
Update README.md
ANGELOANTU7 May 23, 2023
c8f3720
Merge branch 'main' of https://github.com/ANGELOANTU7/intel-hack
ANGELOANTU7 May 23, 2023
dd918df
Update README.md
ANGELOANTU7 May 23, 2023
8125ff5
Create summarizer_requirememts.txt
heyronjmilton May 23, 2023
c7675cc
Update README.md
ANGELOANTU7 May 23, 2023
406e963
Merge branch 'main' of https://github.com/ANGELOANTU7/intel-hack
ANGELOANTU7 May 23, 2023
8ff01db
Update README.md
ANGELOANTU7 May 23, 2023
bc3392b
Update README.md
ANGELOANTU7 May 23, 2023
e4da1e0
Update README.md
ANGELOANTU7 May 23, 2023
e32d3aa
testing
heyronjmilton May 23, 2023
b0b8a0d
Merge branch 'main' of https://github.com/ANGELOANTU7/intel-hack
heyronjmilton May 23, 2023
98da8f9
assigning task
ANGELOANTU7 May 23, 2023
a489b37
Update README.md
ANGELOANTU7 May 23, 2023
77b9764
Update README.md
ANGELOANTU7 May 23, 2023
3f38fc9
Update README.md
ANGELOANTU7 May 23, 2023
06b308b
Update README.md
ANGELOANTU7 May 23, 2023
c54357b
Update README.md
ANGELOANTU7 May 23, 2023
4b80133
Update README.md
ANGELOANTU7 May 23, 2023
9c41e58
Update README.md
ANGELOANTU7 May 23, 2023
8036984
Update README.md
ANGELOANTU7 May 23, 2023
212aafd
Update README.md
ANGELOANTU7 May 23, 2023
f7d4d83
Create Narrator.py
ANGELOANTU7 May 23, 2023
c459b50
narrator start
ANGELOANTU7 May 23, 2023
bca39de
50% narrator
ANGELOANTU7 May 23, 2023
f8aec18
test
heyronjmilton May 23, 2023
aa0e584
test
heyronjmilton May 23, 2023
b3b8eda
test
heyronjmilton May 23, 2023
2bcf7cc
minor
heyronjmilton May 23, 2023
7f6d930
summariser update
heyronjmilton May 23, 2023
5162312
Update summariser.py
heyronjmilton May 23, 2023
85ac6bf
Update summariser.py
heyronjmilton May 23, 2023
fcce207
Update main.py
heyronjmilton May 23, 2023
bf59316
summariser env update
heyronjmilton May 23, 2023
fbcc863
Update .gitignore
heyronjmilton May 23, 2023
f510f3d
Update test_sum.py
heyronjmilton May 23, 2023
fa88b49
Update main.py
heyronjmilton May 23, 2023
928010d
Update test_sum.py
heyronjmilton May 23, 2023
1bbc490
testing
heyronjmilton May 23, 2023
7e7a10e
test
heyronjmilton May 23, 2023
1194690
req
Sameer-Abdulla May 23, 2023
48972c3
Update test_sum.cpython-310.pyc
heyronjmilton May 23, 2023
0d218c0
Update summariser.py
heyronjmilton May 23, 2023
b03a4fc
Update main.py
heyronjmilton May 23, 2023
250856e
test
heyronjmilton May 23, 2023
0bf623a
path change
Sameer-Abdulla May 23, 2023
a35951d
vision api added
Sameer-Abdulla May 23, 2023
a46e32f
file added
Sameer-Abdulla May 23, 2023
86c7588
fast api
Sameer-Abdulla May 23, 2023
efb5f68
fns added
Sameer-Abdulla May 23, 2023
8c4601a
added main
Sameer-Abdulla May 23, 2023
7b2c70d
updated summariser
heyronjmilton May 23, 2023
97e9e60
env update
heyronjmilton May 23, 2023
ffa0305
fast api added
Sameer-Abdulla May 23, 2023
9ee9f9a
updated narrator
ANGELOANTU7 May 23, 2023
552635a
Merge branch 'dev1'
ANGELOANTU7 May 23, 2023
be3fb71
Update README.md
ANGELOANTU7 May 23, 2023
45ac654
Update README.md
ANGELOANTU7 May 23, 2023
0cd85bd
Travis Cl
ANGELOANTU7 May 23, 2023
274488e
Update .travis.yml
ANGELOANTU7 May 23, 2023
bb4111c
Update .travis.yml
ANGELOANTU7 May 23, 2023
d95a8e6
almost done
Sameer-Abdulla May 23, 2023
f3f84cc
commit counter
ANGELOANTU7 May 23, 2023
0dbe320
updated key
ANGELOANTU7 May 23, 2023
6144375
Update .travis.yml
ANGELOANTU7 May 23, 2023
51a45c3
Update .travis.yml
ANGELOANTU7 May 23, 2023
d5d341f
Update .travis.yml
ANGELOANTU7 May 23, 2023
79b4098
Update .travis.yml
ANGELOANTU7 May 23, 2023
da5fb96
Update README.md
ANGELOANTU7 May 23, 2023
ebd4f3a
image added
Sameer-Abdulla May 23, 2023
98e7e40
deleted
ANGELOANTU7 May 23, 2023
3934063
note summariser over
ANGELOANTU7 May 23, 2023
d6e49e6
requirement updates
heyronjmilton May 23, 2023
30a9d93
Create Speech_to_text.py
ANGELOANTU7 May 24, 2023
736aca4
Update Speech_to_text.py
ANGELOANTU7 May 24, 2023
c4e93d1
api key
ANGELOANTU7 May 24, 2023
434e6d6
service region
ANGELOANTU7 May 24, 2023
f6578f2
update
ANGELOANTU7 May 24, 2023
0e632d8
edit
ANGELOANTU7 May 24, 2023
419421b
Update speech_text.py
ANGELOANTU7 May 24, 2023
0adbaf4
delete
ANGELOANTU7 May 24, 2023
dffb02b
Update main.py
ANGELOANTU7 May 24, 2023
20995d4
change in main
ANGELOANTU7 May 24, 2023
04ac749
Create test.mpeg
ANGELOANTU7 May 24, 2023
48bb876
Update speech_text.py
ANGELOANTU7 May 24, 2023
6138cf7
key
ANGELOANTU7 May 24, 2023
6460d48
Update speech_text.py
ANGELOANTU7 May 24, 2023
b332b34
debugging speech2txt
ANGELOANTU7 May 24, 2023
71335eb
Update speech_text.py
ANGELOANTU7 May 24, 2023
139e3c8
Update speech_text.cpython-310.pyc
ANGELOANTU7 May 24, 2023
992e039
done
ANGELOANTU7 May 24, 2023
89d0e25
Testing
ANGELOANTU7 May 24, 2023
f8014ae
Create speech2text_requirements.txt
ANGELOANTU7 May 24, 2023
372d9e8
Update speech_text.py
ANGELOANTU7 May 24, 2023
b9d39b1
Update speech_text.py
ANGELOANTU7 May 24, 2023
2089c38
Update speech_text.py
ANGELOANTU7 May 24, 2023
0a80855
Update speech_text.py
ANGELOANTU7 May 24, 2023
2efb0b1
Update speech_text.py
ANGELOANTU7 May 24, 2023
48f9edf
Update speech_text.py
ANGELOANTU7 May 24, 2023
237df05
Update speech_text.py
ANGELOANTU7 May 24, 2023
145b802
navbar
harshedabdulla May 25, 2023
92134df
2
harshedabdulla May 25, 2023
9154d4f
upload prt
harshedabdulla May 25, 2023
b4e7615
enable CORS
ANGELOANTU7 May 25, 2023
8bd9f29
edit
ANGELOANTU7 May 25, 2023
3d4b14f
edit 2
ANGELOANTU7 May 25, 2023
bc03682
edit 3
ANGELOANTU7 May 25, 2023
59c33ad
upload page
harshedabdulla May 25, 2023
cd8317b
3
ANGELOANTU7 May 25, 2023
02b70b4
edit
ANGELOANTU7 May 25, 2023
09de5ee
Update texttoAIvideo.py
ANGELOANTU7 May 25, 2023
055c6aa
update
ANGELOANTU7 May 25, 2023
c948ef0
update
ANGELOANTU7 May 25, 2023
3cf80c9
debugging
ANGELOANTU7 May 25, 2023
0d4e252
done
ANGELOANTU7 May 25, 2023
5789088
full working ai avatar
ANGELOANTU7 May 25, 2023
857989d
upload page 2
harshedabdulla May 25, 2023
3b3c1dc
upload notes complete
harshedabdulla May 25, 2023
b667116
venv changed
Sameer-Abdulla May 25, 2023
707acbf
final
Sameer-Abdulla May 25, 2023
225b98c
Merge pull request #3 from ANGELOANTU7/harshed
ANGELOANTU7 May 26, 2023
d89dc58
Merge branch 'sameer'
ANGELOANTU7 May 26, 2023
20a4099
upload notes+pyq+summary
harshedabdulla May 26, 2023
bee6fac
Merge branch 'dev1'
ANGELOANTU7 May 26, 2023
1f852c3
reqrmt done
Sameer-Abdulla May 26, 2023
2adfb23
Merge pull request #5 from ANGELOANTU7/sameer
ANGELOANTU7 May 26, 2023
bbe3e64
anythingmore component
harshedabdulla May 26, 2023
4267ab0
Merge pull request #6 from ANGELOANTU7/harshed
ANGELOANTU7 May 26, 2023
b4e8f4f
notes2txt
ANGELOANTU7 May 26, 2023
a2dca84
Update module_1.txt
ANGELOANTU7 May 26, 2023
f529d41
test
heyronjmilton May 26, 2023
da593a5
test
heyronjmilton May 26, 2023
a84662e
Update Generate_qns.py
heyronjmilton May 26, 2023
910e6ba
Update test.py
heyronjmilton May 26, 2023
91ae60c
test
heyronjmilton May 26, 2023
82372de
Update test.cpython-310.pyc
heyronjmilton May 26, 2023
2a8ef13
Update .gitignore
heyronjmilton May 26, 2023
83a2df5
UI
ANGELOANTU7 May 26, 2023
d9020f8
cluster_qns api done
Sameer-Abdulla May 26, 2023
4bb0f12
Merge branch 'sameer'
ANGELOANTU7 May 26, 2023
c959a7c
tutor 1
harshedabdulla Jun 1, 2023
1845696
test
heyronjmilton Jun 3, 2023
ff43b09
Create test2.py
heyronjmilton Jun 3, 2023
5f49917
test
heyronjmilton Jun 4, 2023
7084af0
test
heyronjmilton Jun 4, 2023
65d0fd6
g
ANGELOANTU7 Jun 4, 2023
9f45e56
test
heyronjmilton Jun 4, 2023
4dce696
cloud
ANGELOANTU7 Jun 6, 2023
b0bfb00
dashboard
harshedabdulla Jun 6, 2023
8ff07e9
Merge branch 'main' of https://github.com/ANGELOANTU7/intel-hack into…
harshedabdulla Jun 6, 2023
5d70213
update
ANGELOANTU7 Jun 6, 2023
b9b5455
Merge branch 'main' of https://github.com/ANGELOANTU7/intel-hack
ANGELOANTU7 Jun 6, 2023
ec11e0c
Merge branch 'dev1'
heyronjmilton Jun 6, 2023
c43aa40
cloud
ANGELOANTU7 Jun 6, 2023
d9053f9
Update NotesToText.py
ANGELOANTU7 Jun 6, 2023
56d884f
Update NotesToText.py
ANGELOANTU7 Jun 6, 2023
c11c5f3
test
heyronjmilton Jun 6, 2023
1e2a0fe
api call
harshedabdulla Jun 6, 2023
ee20138
Update NotesToText.py
ANGELOANTU7 Jun 6, 2023
1f0d23c
Update NotesToText.py
ANGELOANTU7 Jun 6, 2023
fbff951
Merge branch 'main' of https://github.com/ANGELOANTU7/intel-hack into…
harshedabdulla Jun 6, 2023
7e3086a
Update package.json
ANGELOANTU7 Jun 6, 2023
6ff9ecb
Merge branch 'main' of https://github.com/ANGELOANTU7/intel-hack
ANGELOANTU7 Jun 6, 2023
5b0255a
Update package.json
ANGELOANTU7 Jun 6, 2023
2eedcf5
Update package.json
ANGELOANTU7 Jun 6, 2023
4950b02
main_summ
heyronjmilton Jun 6, 2023
b88ed12
Update package.json
ANGELOANTU7 Jun 6, 2023
2c0ab9f
Update package.json
ANGELOANTU7 Jun 6, 2023
7929f6a
upload final
harshedabdulla Jun 7, 2023
a9229ea
notestotext
ANGELOANTU7 Jun 7, 2023
7aa3125
Merge branch 'main' of https://github.com/ANGELOANTU7/intel-hack
ANGELOANTU7 Jun 7, 2023
37befa7
Dashboard cluster questions[final]
harshedabdulla Jun 7, 2023
4ff60f5
Merge pull request #11 from ANGELOANTU7/dev2
heyronjmilton Jun 7, 2023
71d3d05
Create note_highlighter_test.py
heyronjmilton Jun 7, 2023
14dcb2c
Merge pull request #12 from ANGELOANTU7/dev2
heyronjmilton Jun 7, 2023
bffb434
studyplanner
harshedabdulla Jun 7, 2023
0728586
6
ANGELOANTU7 Jun 7, 2023
c8a7ff1
sorter
ANGELOANTU7 Jun 7, 2023
2a0f602
study planner
harshedabdulla Jun 9, 2023
a7280a2
dashboard
harshedabdulla Jun 24, 2023
208e103
update
ANGELOANTU7 Jun 24, 2023
06e186e
Merge branch 'main' of https://github.com/ANGELOANTU7/intel-hack
ANGELOANTU7 Jun 24, 2023
0f34ce6
adding into app
ANGELOANTU7 Jun 24, 2023
2a450ed
notes to text 98% done
ANGELOANTU7 Jun 24, 2023
b8a4435
Create NotesChunker.py
ANGELOANTU7 Jun 24, 2023
33b7343
EDIT
ANGELOANTU7 Jun 24, 2023
2e3dc06
chunker
ANGELOANTU7 Jun 24, 2023
a9a0492
chunker over
ANGELOANTU7 Jun 24, 2023
bec1e9d
latestpyqsorter done
ANGELOANTU7 Jun 24, 2023
79ed5a2
sorter sender
ANGELOANTU7 Jun 25, 2023
27ddddf
SORTER FIXED
ANGELOANTU7 Jun 25, 2023
abf5a4d
dashboard complete
harshedabdulla Jun 25, 2023
88202ff
signup ui+ login ui+ page telling to wait for emai
harshedabdulla Jun 25, 2023
7f95b49
test
heyronjmilton Jun 28, 2023
0f4c9f3
Merge pull request #13 from ANGELOANTU7/dev_3
heyronjmilton Jun 28, 2023
af11c4d
test
heyronjmilton Jun 28, 2023
316b669
Merge pull request #14 from ANGELOANTU7/dev_3
heyronjmilton Jun 28, 2023
b26870c
email
Sameer-Abdulla Jun 28, 2023
9396b0b
some change
Sameer-Abdulla Jun 28, 2023
6dc8c62
email and documentai
Sameer-Abdulla Jun 28, 2023
e0cf6f0
test
heyronjmilton Jun 28, 2023
2f4247b
2 modules
ANGELOANTU7 Jun 28, 2023
d4e6807
Merge branch 'main' of https://github.com/ANGELOANTU7/intel-hack
ANGELOANTU7 Jun 28, 2023
adeffbc
test
heyronjmilton Jun 28, 2023
f7c3feb
test
heyronjmilton Jun 28, 2023
9175216
study planner
ANGELOANTU7 Jun 28, 2023
9bf0999
Merge branch 'main' of https://github.com/ANGELOANTU7/intel-hack
ANGELOANTU7 Jun 28, 2023
2194a7e
link
ANGELOANTU7 Jun 29, 2023
cada856
link
ANGELOANTU7 Jun 29, 2023
7c5ed88
multi user update
ANGELOANTU7 Jun 29, 2023
8d9d0ed
final
ANGELOANTU7 Jun 30, 2023
e8eab4f
back
ANGELOANTU7 Jul 1, 2023
ec8d0e8
Create file_sender.py
heyronjmilton Jul 1, 2023
1cb7d65
intel
ANGELOANTU7 Jul 1, 2023
07624a2
Merge branch 'main' of https://github.com/ANGELOANTU7/intel-hack
heyronjmilton Jul 1, 2023
1ec0c77
file_sender
heyronjmilton Jul 1, 2023
4b7b35f
ocr done
Sameer-Abdulla Jul 1, 2023
07c5f7c
sum
ANGELOANTU7 Jul 1, 2023
f1d0960
Merge branch 'main' of https://github.com/ANGELOANTU7/intel-hack
ANGELOANTU7 Jul 1, 2023
b469b6e
apis
heyronjmilton Jul 1, 2023
fff572c
Merge branch 'main' of https://github.com/ANGELOANTU7/intel-hack
heyronjmilton Jul 1, 2023
d245916
sum
ANGELOANTU7 Jul 1, 2023
7299196
test
heyronjmilton Jul 1, 2023
89d5b78
Create iteration3_requirements.txt
heyronjmilton Jul 1, 2023
ed1b905
Merge branch 'main' of https://github.com/ANGELOANTU7/intel-hack
heyronjmilton Jul 1, 2023
a00a604
clean up
heyronjmilton Jul 1, 2023
1955dc2
clean up
heyronjmilton Jul 1, 2023
d4b2650
Update README.md
ANGELOANTU7 Jul 2, 2023
b044e2b
Update README.md
heyronjmilton Jul 2, 2023
3f2107e
frontend final
harshedabdulla Jul 2, 2023
9f9763b
Update README.md
harshedabdulla Jul 2, 2023
273de50
Update README.md
harshedabdulla Jul 2, 2023
cf46a79
added screenshot of intel benchmark as request by judges
ANGELOANTU7 Jul 2, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .DS_Store
Binary file not shown.
9 changes: 9 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
venv/
Backend/requirements.txt
dat.txt
temp.txt
Backend/test.py
main.py
iteration3/
test_files/
Backend/test/
13 changes: 13 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
language: python
python:
- "3.8"

# Customize this script to match your requirements
script:
- echo "Running tests..."
- pip install -r angelo_requirements.txt

# This section is important for badge generation
before_deploy:
- git fetch --unshallow

164 changes: 164 additions & 0 deletions Backend/Final_LatestSorter.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
from fastapi import APIRouter
import boto3
import openai
import time
from botocore.exceptions import ClientError

number=4
s3_access_key = ""
s3_secret_access_key = ""
s3_bucket_name = "learnmateai"

s3 = boto3.client("s3", aws_access_key_id=s3_access_key, aws_secret_access_key=s3_secret_access_key)

# Set up OpenAI API credentials
openai.api_key = ''

def batch_text(input_text, delimiter="Module"):
batches = input_text.split(delimiter)
cleaned_batches = [batch.strip() for batch in batches if batch.strip()]
if(len(cleaned_batches)<3):
batches = input_text.split("MODULE")
cleaned_batches = [batch.strip() for batch in batches if batch.strip()]
return cleaned_batches

def upload_to_s3(bucket_name, folder_name, file_name, content):
s3 = boto3.client('s3')
key = folder_name + '/' + file_name
s3.put_object(Body=content, Bucket=bucket_name, Key=key)

def get_text_from_s3(bucket_name, file_name, encoding='utf-8'):
response = s3.get_object(Bucket=bucket_name, Key=file_name)
content = response['Body'].read()

try:
text_content = content.decode(encoding)
except UnicodeDecodeError:
# Handle decoding error gracefully
text_content = content.decode('latin-1') # Try an alternative encoding

return text_content

app = APIRouter()

@app.get("/sorter")
def process_files(user:str):
user=user+"/"
# Make an API request with a reset message
response = openai.ChatCompletion.create(
model="gpt-3.5-turbo",
messages=[
{
"role": "user",
"content": "forget everything told before by me"
}
]
)
print("reseting")
# Function to read and process a file
def process_file(file_name,user1):



# Read file from S3
print(user1)
response = s3.get_object(Bucket='learnmateai', Key=user1+'pyqs_txt/' + file_name)
file_content = response['Body'].read().decode('utf-8')

# Split file content into batches (adjust batch size as needed)
batch_size = 30000
batches = [file_content[i:i+batch_size] for i in range(0, len(file_content), batch_size)]
print(user1+"syllabus_txt/syllabus.txt")
response2 = s3.get_object(Bucket='learnmateai', Key= user1+"syllabus_pdf/syllabus.txt")
topics = response2['Body'].read().decode('utf-8')
# Process batches
Sorted_PYQ_Mod=[[]for _ in range(5)]
for batch in batches:
# Send batch to OpenAI API
print(batch)

response = openai.ChatCompletion.create(
model="gpt-3.5-turbo",
messages=[
{
"role": "user",
"content": f"I will feed you a question paper as text,sort the question in the text below based on this syllabus having {number} modules :{topics} (it should look exactly like MODULE:questions ) all questions should cluster under its module , the output should exactly have the {number} number of ""MODULE"" written under each the questions come ,it should have all MODULE even if any is empty, never give question seperately with there modules tag, i need questions to be grouped under module always,Any output you give should only be from the txt given below you should not create any new question :\n\n{batch}\n\n"
}
]
)

important_topics = response.choices[0].message.content
#print(important_topics)
#return important_topics
# Add a delay of 20 seconds to handle rate limit


text_batches = batch_text(important_topics)
#print(text_batches)

bucket_name = 'learnmateai'
folder_name = user1+'Sorted_PYQS/'


i=0
try:

for batch in enumerate(text_batches):
print(batch)

result=' '.join(str(element) for element in batch)
new_content = result
response = s3.get_object(Bucket=bucket_name, Key=folder_name+"Module"+str(i+1)+".txt")
current_content = response['Body'].read().decode('utf-8')


updated_content = current_content + new_content

# Upload the updated content to S3
s3.put_object(Bucket=bucket_name, Key=folder_name+"Module"+str(i+1)+".txt", Body=updated_content.encode('utf-8'))

# Print uploaded file information
print(f"File uploaded to '{user1}{bucket_name}/{folder_name}'")
i=i+1



time.sleep(20)

except ClientError as e:

if e.response['Error']['Code'] == 'NoSuchKey':
print("File not found in S3 bucket.")

for batch in enumerate(text_batches):
print(batch)

result=' '.join(str(element) for element in batch)
new_content = result

#print(result)
updated_content =new_content

# Upload the updated content to S3
s3.put_object(Bucket=bucket_name, Key=folder_name+"Module"+str(i+1)+".txt", Body=updated_content.encode('utf-8'))

# Print uploaded file information
print(f"File uploaded to '{user1}{bucket_name}/{folder_name}'")
i=i+1
else:
print("An error occurred:", e)




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

# Process each file
for file in response['Contents']:
print(file)
file_name = file['Key'].split('/')[-1]
print(file_name)
process_file(file_name,user)

return {"message": "PYQS SORTED"}
84 changes: 84 additions & 0 deletions Backend/Final_NotesChunker.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
from fastapi import APIRouter
import boto3
import openai
import time

s3_access_key = ""
s3_secret_access_key = ""
s3_bucket_name = "learnmateai"

s3 = boto3.client("s3", aws_access_key_id=s3_access_key, aws_secret_access_key=s3_secret_access_key)

# Set up OpenAI API credentials
openai.api_key = ''

def batch_text(input_text, delimiter="TOPIC:"):
batches = input_text.split(delimiter)
cleaned_batches = [batch.strip() for batch in batches if batch.strip()]
return cleaned_batches

def upload_to_s3(bucket_name, folder_name, file_name, content):
s3 = boto3.client('s3')
key = folder_name + '/' + file_name
s3.put_object(Body=content, Bucket=bucket_name, Key=key)

app = APIRouter()

@app.get("/process_files")
def process_files(user: str):
user=user+"/"
# Function to read and process a file
def process_file(file_name):
# Read file from S3
response = s3.get_object(Bucket='learnmateai', Key=user+'notes_txt/' + file_name)
file_content = response['Body'].read().decode('utf-8')

# Split file content into batches (adjust batch size as needed)
batch_size = 3000
batches = [file_content[i:i+batch_size] for i in range(0, len(file_content), batch_size)]

# Process batches
for batch in batches:
# Send batch to OpenAI API


response = openai.ChatCompletion.create(
model="gpt-3.5-turbo",
messages=[
{
"role": "user",
"content": f"divide the text topic wise (it should look like TOPIC:notes) notes should very breif and be created in a way so that you will be able to recreate the full txt :\n\n{batch}\n\n"
}
]
)

important_topics = response.choices[0].message.content
#print(important_topics)
#return important_topics
# Add a delay of 20 seconds to handle rate limit
time.sleep(20)

text_batches = batch_text(important_topics)

bucket_name = 'learnmateai'
file=file_name.split(".")[0]
folder_name = f'{user}Analysed_Notes/{file}'

for i, batch in enumerate(text_batches):
lines = batch.split('\n')
file_name1 = lines[0].strip().replace(" ", "_") + '.txt'
content = '\n'.join(lines[1:]).strip()
upload_to_s3(bucket_name, folder_name, file_name1, content)

# Print uploaded file information
print(f"File '{file_name1}' uploaded to '{bucket_name}/{folder_name}'")

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

# Process each file
for file in response['Contents']:
file_name = file['Key'].split('/')[-1]
process_file(file_name)

return {"message": "NOTES"}
Loading