Skip to content

Commit 91ae60c

Browse files
committed
test
1 parent 910e6ba commit 91ae60c

File tree

6 files changed

+49
-19
lines changed

6 files changed

+49
-19
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
venv/
22
Backend/requirements.txt
3-
dat.txt
3+
dat.txt
4+
temp.txt
0 Bytes
Binary file not shown.
-392 Bytes
Binary file not shown.

Backend/test.py

Lines changed: 43 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,56 @@
11
import openai
22
import shutil
33
import os
4+
import chardet
45
from fastapi import FastAPI,UploadFile,File
56
from fastapi import APIRouter
67

7-
def temp_file(file):
8-
try:
9-
with open("dat.txt", "wb") as buffer: # saving file
10-
shutil.copyfileobj(file.file, buffer)
11-
finally:
12-
file.file.close()
138

14-
with open("temp.txt", "r", encoding='utf-8') as file:
15-
text = file.read()
9+
def detect_encoding(data):
10+
result = chardet.detect(data)
11+
encoding = result["encoding"]
12+
return encoding
1613

17-
print("Deleting the saved file.......")
18-
os.remove("temp.txt")
19-
print("deleted....")
20-
return text
14+
router_generate_question = APIRouter()
2115

2216

23-
router_generate_question = APIRouter()
17+
@router_generate_question.post("/gen-questions")
18+
async def gen_questions(sorted_q: UploadFile = File(...),notebook_q: UploadFile = File(...),imp_topics: UploadFile = File(...),ref_paper: UploadFile = File(...)):
19+
#
20+
sorted_questions = await sorted_q.read()
21+
notebook_questions = await notebook_q.read()
22+
important_topics = await imp_topics.read()
23+
reference_paper = await ref_paper.read()
24+
25+
# Decode the file content using the detected encoding
26+
decoded_sorted_questions = sorted_questions.decode(detect_encoding(sorted_questions))
27+
decoded_notebook_questions = notebook_questions.decode(detect_encoding(notebook_questions))
28+
decoded_important_topics = important_topics.decode(detect_encoding(important_topics))
29+
decoded_reference_paper = reference_paper.decode(detect_encoding(reference_paper))
30+
31+
32+
prompt = f"generate 10 questions that are not in reference paper but similar \nSorted Previous Year Questions:\n{decoded_sorted_questions}\n\nNotebook Question List:\n{decoded_notebook_questions}\n\nImportant Topics:\n{decoded_important_topics}\n\nReference Paper:\n{decoded_reference_paper}\n\n"
33+
34+
35+
# Generate questions using OpenAI API
36+
response = openai.Completion.create(
37+
engine="davinci",
38+
prompt=prompt,
39+
max_tokens=1000, # Adjust the max_tokens value as per your requirement
40+
temperature=0.4, # Adjust the temperature value to control the creativity of the generated questions
41+
top_p=1.0,
42+
frequency_penalty=0.0,
43+
presence_penalty=0.0,
44+
n=5 # Adjust the 'n' value to generate more or fewer questions
45+
)
46+
47+
# Extract the generated questions from the API response
48+
generated_questions = [choice['text'].strip() for choice in response.choices]
49+
50+
# Print the generated questions
51+
for i, question in enumerate(generated_questions):
52+
print(f"Question {i+1}: {question}")
2453

2554

2655

27-
def gen_questions(file: UploadFile = File(...)):
28-
text = temp_file(file)
29-
return text
56+
return {"dat1" :decoded_sorted_questions,"dat2" : decoded_notebook_questions,"dat3" : decoded_important_topics,"dat4" : decoded_reference_paper}

__pycache__/main.cpython-310.pyc

80 Bytes
Binary file not shown.

main.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,17 @@
22
from fastapi import FastAPI
33
#from Backend.pyqsorter import router as api1_router
44
from Backend.summariser import router_summariser as summariser
5+
from Backend.test import router_generate_question as generate_question
56
#from Backend.Notes_Analyser import router as api4_router
67
# import other API routers as needed
78

89
app = FastAPI()
910

1011

11-
# Mount the API routerss
12+
# Mount the API routers
1213
#app.include_router(api1_router)
13-
app.include_router(summariser)
14+
#app.include_router(summariser)
15+
app.include_router(generate_question)
1416
#app.include_router(api4_router)
1517

1618
# include other API routers as needed

0 commit comments

Comments
 (0)