Skip to content

Commit 27ddddf

Browse files
committed
SORTER FIXED
1 parent 79ed5a2 commit 27ddddf

File tree

6 files changed

+26
-12
lines changed

6 files changed

+26
-12
lines changed

Backend/LatestSorter.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,23 @@ def get_text_from_s3(bucket_name, file_name, encoding='utf-8'):
4343

4444
@app.get("/sorter")
4545
def process_files():
46+
47+
# Make an API request with a reset message
48+
response = openai.ChatCompletion.create(
49+
model="gpt-3.5-turbo",
50+
messages=[
51+
{
52+
"role": "user",
53+
"content": "forget everything told before by me"
54+
}
55+
]
56+
)
57+
print("reseting")
4658
# Function to read and process a file
4759
def process_file(file_name):
60+
61+
62+
4863
# Read file from S3
4964

5065
response = s3.get_object(Bucket='learnmateai', Key='pyqs_txt/' + file_name)
@@ -59,14 +74,14 @@ def process_file(file_name):
5974
Sorted_PYQ_Mod=[[]for _ in range(5)]
6075
for batch in batches:
6176
# Send batch to OpenAI API
62-
77+
print(batch)
6378

6479
response = openai.ChatCompletion.create(
6580
model="gpt-3.5-turbo",
6681
messages=[
6782
{
6883
"role": "user",
69-
"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 with there modules i need it as grouped under module always :\n\n{batch}\n\n"
84+
"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 with there modules i need it as grouped under module always,questions should only be from the txt given below you should not create any new question :\n\n{batch}\n\n"
7085
}
7186
]
7287
)

Backend/SortedPQYsender.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import os
55
import requests
66
from fastapi.responses import FileResponse
7+
from fastapi.responses import Response
78

89
app = APIRouter()
910

@@ -87,11 +88,11 @@ def generate_pdf():
8788

8889
response.raise_for_status()
8990

90-
# Save PDF response to a temporary file
91-
temp_pdf_path = "temp_pdf/temp_pdf.pdf" # Replace with the desired path to save the temporary PDF file
92-
with open(temp_pdf_path, "wb") as temp_pdf_file:
93-
for chunk in response.iter_content(chunk_size=8192):
94-
temp_pdf_file.write(chunk)
91+
# Set the content type and headers for the PDF response
92+
headers = {
93+
'Content-Type': 'application/pdf',
94+
'Content-Disposition': 'attachment; filename=combined_pdf.pdf'
95+
}
9596

96-
# Return the temporary PDF file
97-
return FileResponse(temp_pdf_path, filename='combined_pdf.pdf', media_type='application/pdf')
97+
# Return the PDF response
98+
return Response(content=response.content, headers=headers)
237 Bytes
Binary file not shown.
-89 Bytes
Binary file not shown.

Dockerfile

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,13 @@ RUN yum install -y poppler-utils
1010
COPY Backend ./Backend
1111
COPY client ./client
1212
COPY Files ./Files
13-
COPY images ./images
14-
COPY images ./temp_pdf
1513
COPY Local_Storage ./Local_Storage
1614

1715
COPY requirements.txt .
1816
RUN pip3 install -r requirements.txt --target "${LAMBDA_TASK_ROOT}"
1917

2018
RUN chmod a+rwx Local_Storage
21-
RUN chmod a+rwx images
19+
2220

2321

2422

requirements.txt

1.77 KB
Binary file not shown.

0 commit comments

Comments
 (0)