diff --git a/Alpha/app.py b/Alpha/app.py new file mode 100644 index 0000000..a9c73ff --- /dev/null +++ b/Alpha/app.py @@ -0,0 +1,132 @@ +from flask import Flask, render_template, request, redirect, url_for, session +from educhain import Educhain, LLMConfig +from langchain_google_genai import ChatGoogleGenerativeAI +import requests +import PyPDF2 +from io import BytesIO +from transformers import AutoTokenizer, AutoModelForSeq2SeqLM + +app = Flask(__name__) +app.secret_key = 'supersecretkey' + +tokenizer = AutoTokenizer.from_pretrained("facebook/bart-large-cnn") +model = AutoModelForSeq2SeqLM.from_pretrained("facebook/bart-large-cnn") + +# Initialize Educhain client +gemini = ChatGoogleGenerativeAI( + model="gemini-1.5-pro-002", + api_key="Enter Your API key" + +gemini_config = LLMConfig(custom_model=gemini) +client = Educhain(gemini_config) + +# Function to extract MCQs into lists +def mcqs_to_lists(mcq_list): + question_list = [] + options_list = [] + correct_answers = [] + for i, mcq in enumerate(mcq_list.questions): + question_str = f"{mcq.question}" + options_str = [option for option in mcq.options] # Options without numbers + question_list.append(question_str) + options_list.append(options_str) + correct_answers.append(mcq.answer) + return question_list, options_list, correct_answers + + +@app.route('/', methods=['GET', 'POST']) +def MYS(): + print("MYS function is being called") + print(request.method) + if request.method == 'POST': + print("Form data received") + pdf_url = request.form['pdf_url'] + print("url",pdf_url) + response = requests.get(pdf_url) + if response.status_code == 200: + pdf_file = BytesIO(response.content) + pdf_reader = PyPDF2.PdfReader(pdf_file) + + pdf_text = '' + for page_num in range(len(pdf_reader.pages)): + page = pdf_reader.pages[page_num] + pdf_text += page.extract_text() + + try: + #response = requests.get(pdf_url) + #response.raise_for_status() # Check for HTTP errors + + # Generate MCQs using Educhain client + mcqs_from_url = client.qna_engine.generate_questions_from_data( + source=pdf_text, + source_type="text", + num=5 + ) + + inputs = tokenizer(pdf_text, return_tensors="pt", max_length=1024, truncation=True) + summary_ids = model.generate(inputs["input_ids"], max_length=150, min_length=40, length_penalty=2.0, num_beams=4, early_stopping=True) + summary = tokenizer.decode(summary_ids[0], skip_special_tokens=True) + session['summary'] = summary + print("SUMMARY:") + print(summary[:50]) + + # Extract questions, options, and correct answers + questions, options, correct_answers = mcqs_to_lists(mcqs_from_url) + print(correct_answers) + # Save questions, options, and correct answers to session + session['questions'] = questions + session['options'] = options + session['correct_answers'] = correct_answers + + # Redirect to the quiz page + return redirect(url_for('quiz')) + + except Exception as e: + + return f"OHHH error occurred: {str(e)}" + + return render_template('index.html') + + +@app.route('/quiz', methods=['GET', 'POST']) +def quiz(): + # Retrieve questions and options from session + questions = session.get('questions') + options = session.get('options') + summary = session.get('summary') + print("SUMMARY:",summary[:50]) + if questions and options: + return render_template('quiz.html', questions=questions, options=options,summary=summary) + else: + return "No quiz data found. Please upload a PDF." + + +@app.route('/submit_quiz', methods=['POST']) +def submit_quiz(): + print("YOU ARE IN QUIZ RESULT") + score = 0 + feedback = [] + + # Retrieve correct answers from session + correct_answers = session.get('correct_answers') + questions = session.get('questions') + if not correct_answers or not questions: + return "No quiz data found. Please upload a PDF." + + # Evaluate the user's answers + for idx, correct_answer in enumerate(correct_answers): + user_answer = request.form.get(f'q{idx+1}') # This will now be the option string the user selected + print(f"User answer for Q{idx + 1}: {user_answer}") # Debugging line to check user answers + print(f"Correct answer for Q{idx + 1}: {correct_answer}") + if user_answer and user_answer == correct_answer: + score += 1 + feedback.append(f"Question {idx + 1}: Correct!!! {correct_answer}.") + else: + feedback.append(f"Question {idx + 1}: Incorrect. The correct answer was :{correct_answer}.") + + # Render the results page + return render_template('quiz_result.html', score=score, total=len(questions), feedback=feedback) + + +if __name__ == '__main__': + app.run(debug=True, port=5000) diff --git a/Alpha/requirements.txt b/Alpha/requirements.txt new file mode 100644 index 0000000..c823f24 --- /dev/null +++ b/Alpha/requirements.txt @@ -0,0 +1,245 @@ +aiohappyeyeballs==2.4.0 +aiohttp==3.10.6 +aiosignal==1.3.1 +annotated-types==0.7.0 +anyio==4.4.0 +archspec==0.2.4 +argon2-cffi==23.1.0 +argon2-cffi-bindings==21.2.0 +arrow==1.3.0 +asgiref==3.8.1 +asttokens==2.4.1 +async-lru==2.0.4 +attrs==24.2.0 +babel==2.16.0 +backoff==2.2.1 +bcrypt==4.2.0 +beautifulsoup4==4.12.3 +bleach==6.1.0 +blinker==1.8.2 +boltons==24.0.0 +Brotli==1.1.0 +build==1.2.2 +cachetools==5.5.0 +certifi==2024.8.30 +cffi==1.17.1 +chardet==5.2.0 +charset-normalizer==3.3.2 +chroma-hnswlib==0.7.6 +chromadb==0.5.9 +click==8.1.7 +colorama==0.4.6 +coloredlogs==15.0.1 +comm==0.2.2 +contourpy==1.3.0 +cryptography==43.0.1 +cycler==0.12.1 +dataclasses-json==0.6.7 +debugpy==1.8.5 +decorator==5.1.1 +defusedxml==0.7.1 +Deprecated==1.2.14 +distro==1.9.0 +durationpy==0.7 +educhain==0.3.2 +executing==2.1.0 +fastapi==0.115.0 +fastjsonschema==2.20.0 +filelock==3.13.1 +Flask==3.0.3 +flatbuffers==24.3.25 +fonttools==4.53.1 +fqdn==1.5.1 +frozendict==2.4.4 +frozenlist==1.4.1 +fsspec==2024.2.0 +gitdb==4.0.11 +GitPython==3.1.43 +google-ai-generativelanguage==0.6.6 +google-api-core==2.20.0 +google-api-python-client==2.147.0 +google-auth==2.35.0 +google-auth-httplib2==0.2.0 +google-generativeai==0.7.2 +googleapis-common-protos==1.65.0 +greenlet==3.1.1 +grpcio==1.66.1 +grpcio-status==1.62.3 +gunicorn==23.0.0 +h11==0.14.0 +httpcore==1.0.5 +httplib2==0.22.0 +httptools==0.6.1 +httpx==0.27.2 +huggingface-hub==0.25.1 +humanfriendly==10.0 +idna==3.10 +importlib_metadata==8.4.0 +importlib_resources==6.4.5 +ipykernel==6.29.5 +ipython==8.27.0 +isoduration==20.11.0 +itsdangerous==2.2.0 +jedi==0.19.1 +Jinja2==3.1.4 +jiter==0.5.0 +joblib==1.4.2 +json5==0.9.25 +jsonpatch==1.33 +jsonpointer==3.0.0 +jsonschema==4.23.0 +jsonschema-specifications==2023.12.1 +jupyter-events==0.10.0 +jupyter-lsp==2.2.5 +jupyter-server-mathjax==0.2.6 +jupyter_client==8.6.2 +jupyter_core==5.7.2 +jupyter_server==2.14.2 +jupyter_server_terminals==0.5.3 +jupyterlab==4.2.5 +jupyterlab_git==0.50.1 +jupyterlab_pygments==0.3.0 +jupyterlab_server==2.27.3 +kiwisolver==1.4.7 +kubernetes==31.0.0 +langchain==0.3.1 +langchain-community==0.3.1 +langchain-core==0.3.6 +langchain-google-genai==2.0.0 +langchain-openai==0.2.1 +langchain-text-splitters==0.3.0 +langsmith==0.1.128 +markdown-it-py==3.0.0 +MarkupSafe==2.1.5 +marshmallow==3.22.0 +matplotlib==3.9.2 +matplotlib-inline==0.1.7 +mdurl==0.1.2 +mistune==3.0.2 +mmh3==5.0.1 +monotonic==1.6 +mpmath==1.3.0 +multidict==6.1.0 +mypy-extensions==1.0.0 +nbclient==0.10.0 +nbconvert==7.16.4 +nbdime==4.0.2 +nbformat==5.10.4 +nest-asyncio==1.6.0 +networkx==3.2.1 +notebook_shim==0.2.4 +numpy==1.26.4 +oauthlib==3.2.2 +onnxruntime==1.19.2 +openai==1.48.0 +opentelemetry-api==1.27.0 +opentelemetry-exporter-otlp-proto-common==1.27.0 +opentelemetry-exporter-otlp-proto-grpc==1.27.0 +opentelemetry-instrumentation==0.48b0 +opentelemetry-instrumentation-asgi==0.48b0 +opentelemetry-instrumentation-fastapi==0.48b0 +opentelemetry-proto==1.27.0 +opentelemetry-sdk==1.27.0 +opentelemetry-semantic-conventions==0.48b0 +opentelemetry-util-http==0.48b0 +orjson==3.10.7 +overrides==7.7.0 +packaging==24.1 +pandas==2.2.2 +pandocfilters==1.5.1 +parso==0.8.4 +pexpect==4.9.0 +pillow==10.4.0 +platformdirs==4.3.3 +plotly==5.24.1 +pluggy==1.5.0 +posthog==3.6.6 +prometheus_client==0.20.0 +prompt_toolkit==3.0.47 +proto-plus==1.24.0 +protobuf==4.25.5 +psutil==6.0.0 +ptyprocess==0.7.0 +pure_eval==0.2.3 +pyasn1==0.6.1 +pyasn1_modules==0.4.1 +pycosat==0.6.6 +pycparser==2.22 +pydantic==2.9.2 +pydantic-settings==2.5.2 +pydantic_core==2.23.4 +Pygments==2.18.0 +pyOpenSSL==24.2.1 +pyparsing==3.1.4 +PyPDF2==3.0.1 +PyPika==0.48.9 +pyproject_hooks==1.1.0 +PySocks==1.7.1 +python-dateutil==2.9.0. +python-dotenv==1.0.1 +python-json-logger==2.0.7 +pytz==2024.2 +PyYAML==6.0.2 +pyzmq==26.2.0 +referencing==0.35.1 +regex==2024.9.11 +reportlab==4.2.2 +requests==2.32.3 +requests-oauthlib==2.0.0 +rfc3339-validator==0.1.4 +rfc3986-validator==0.1.1 +rich==13.8.1 +rpds-py==0.20.0 +rsa==4.9 +ruamel.yaml==0.18.6 +ruamel.yaml.clib==0.2.8 +safetensors==0.4.5 +scikit-learn==1.5.2 +scipy==1.14.1 +seaborn==0.13.2 +Send2Trash==1.8.3 +setuptools==75.1.0 +shellingham==1.5.4 +six==1.16.0 +smmap==5.0.1 +sniffio==1.3.1 +soupsieve==2.6 +SQLAlchemy==2.0.35 +stack-data==0.6.3 +starlette==0.38.6 +sympy==1.12 +tenacity==8.5.0 +terminado==0.18.1 +threadpoolctl==3.5.0 +tiktoken==0.7.0 +tinycss2==1.3.0 +tokenizers==0.20.0 +torch==2.4.1 +tornado==6.4.1 +tqdm==4.66.5 +traitlets==5.14.3 +transformers==4.45.1 +truststore==0.9.2 +typer==0.12.5 +types-python-dateutil==2.9.0.20240906 +typing-inspect==0.9.0 +typing_extensions==4.12.2 +tzdata==2024.1 +uri-template==1.3.0 +uritemplate==4.1.1 +urllib3==2.2.3 +uvicorn==0.30.6 +uvloop==0.20.0 +watchfiles==0.24.0 +wcwidth==0.2.13 +webcolors==24.8.0 +webencodings==0.5.1 +websocket-client==1.8.0 +websockets==13.1 +Werkzeug==3.0.4 +wheel==0.43.0 +wrapt==1.16.0 +yarl==1.12.1 +youtube-transcript-api==0.6.2 +zipp==3.20.2 +zstandard==0.23.0 \ No newline at end of file diff --git a/Alpha/static/LOGO.png b/Alpha/static/LOGO.png new file mode 100644 index 0000000..481e519 Binary files /dev/null and b/Alpha/static/LOGO.png differ diff --git a/Alpha/static/Questionmark.jpg b/Alpha/static/Questionmark.jpg new file mode 100644 index 0000000..64799ee Binary files /dev/null and b/Alpha/static/Questionmark.jpg differ diff --git a/Alpha/static/bgm.png b/Alpha/static/bgm.png new file mode 100644 index 0000000..a13f699 Binary files /dev/null and b/Alpha/static/bgm.png differ diff --git a/Alpha/templates/index.html b/Alpha/templates/index.html new file mode 100644 index 0000000..443959e --- /dev/null +++ b/Alpha/templates/index.html @@ -0,0 +1,102 @@ + + +
+ + +
+ MindYourStudy is an innovative application designed to enhance your learning experience. Upload your PDF documents and let our advanced AI summarize and quiz you on the content, making your study sessions more efficient and effective.
+{{ summary }}
+ {% else %} +No summary available.
+ {% endif %} + +Your Score: {{ score }}/{{ total }}
+