-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
74 lines (66 loc) · 2.56 KB
/
main.py
File metadata and controls
74 lines (66 loc) · 2.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
from groq import Groq
import streamlit as st
import os
import PyPDF2
from dotenv import load_dotenv
# Loading environment variables
load_dotenv()
client=Groq(
api_key=os.getenv('GROQ_API_KEY')
)
# Function to summarize text and generate quiz questions
def summarize_text(prompt):
try:
response = client.chat.completions.create(
model='openai/gpt-oss-20b',
messages=[
{
"role": "system",
"content": (
"You are an expert educational assistant. "
"Your tasks are:\n"
"1. Summarize the provided notes in a clear and concise way.\n"
"2. Use easy-to-understand language suitable for students.\n"
"3. Present the summary in bullet points with logical flow.\n"
"4. Highlight key terms, formulas, or definitions clearly.\n"
"5. At the end, generate 3-5 multiple choice questions (MCQs) "
"for revision. Each MCQ should:\n"
" - Have one correct answer and 3 distractors.\n"
" - Be directly based on the summary.\n"
" - Provide the correct answer after the options."
)
},
{
"role": "user",
"content": f"Here are the notes to process:\n\n{prompt}"
}
],
temperature=0.7
)
return response.choices[0].message.content
except Exception as e:
return f"Cant Summarize at the Moment"
# Streamlit UI
st.set_page_config(page_title='Notes Summarizer and Quizer', page_icon=':books:',layout='wide')
st.title('Notes Summarizer and Quizer :books:')
st.write('---')
st.sidebar.header('Upload your notes 📝')
st.sidebar.write('---')
uploaded_file=st.sidebar.file_uploader('Upload a PDF file containing your notes ⬇️', type=['pdf'])
# Process the uploaded file
if uploaded_file is not None:
with st.spinner('Processing your notes...'):
pdf_reader = PyPDF2.PdfReader(uploaded_file)
text = ""
for page in pdf_reader.pages:
text += page.extract_text() + "\n"
summary = summarize_text(text)
st.subheader('Summary and Quiz')
st.markdown(summary)
# Download button
st.download_button(
label='Download Summary and Quiz',
data=summary,
file_name='summary_and_quiz.txt',
mime='application/plain'
)