-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from PrajjwalLyzr/exp/assesment-generator
added assesment generator
- Loading branch information
Showing
8 changed files
with
362 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,161 @@ | ||
# Byte-compiled / optimized / DLL files | ||
__pycache__/ | ||
*.py[cod] | ||
*$py.class | ||
|
||
# C extensions | ||
*.so | ||
|
||
# Distribution / packaging | ||
.Python | ||
build/ | ||
develop-eggs/ | ||
dist/ | ||
downloads/ | ||
eggs/ | ||
.eggs/ | ||
lib/ | ||
lib64/ | ||
parts/ | ||
sdist/ | ||
var/ | ||
wheels/ | ||
share/python-wheels/ | ||
*.egg-info/ | ||
.installed.cfg | ||
*.egg | ||
MANIFEST | ||
|
||
# PyInstaller | ||
# Usually these files are written by a python script from a template | ||
# before PyInstaller builds the exe, so as to inject date/other infos into it. | ||
*.manifest | ||
*.spec | ||
|
||
# Installer logs | ||
pip-log.txt | ||
pip-delete-this-directory.txt | ||
|
||
# Unit test / coverage reports | ||
htmlcov/ | ||
.tox/ | ||
.nox/ | ||
.coverage | ||
.coverage.* | ||
.cache | ||
nosetests.xml | ||
coverage.xml | ||
*.cover | ||
*.py,cover | ||
.hypothesis/ | ||
.pytest_cache/ | ||
cover/ | ||
|
||
# Translations | ||
*.mo | ||
*.pot | ||
|
||
# Django stuff: | ||
*.log | ||
local_settings.py | ||
db.sqlite3 | ||
db.sqlite3-journal | ||
|
||
# Flask stuff: | ||
instance/ | ||
.webassets-cache | ||
|
||
# Scrapy stuff: | ||
.scrapy | ||
|
||
# Sphinx documentation | ||
docs/_build/ | ||
|
||
# PyBuilder | ||
.pybuilder/ | ||
target/ | ||
|
||
# Jupyter Notebook | ||
.ipynb_checkpoints | ||
|
||
# IPython | ||
profile_default/ | ||
ipython_config.py | ||
|
||
# pyenv | ||
# For a library or package, you might want to ignore these files since the code is | ||
# intended to run in multiple environments; otherwise, check them in: | ||
# .python-version | ||
|
||
# pipenv | ||
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. | ||
# However, in case of collaboration, if having platform-specific dependencies or dependencies | ||
# having no cross-platform support, pipenv may install dependencies that don't work, or not | ||
# install all needed dependencies. | ||
#Pipfile.lock | ||
|
||
# poetry | ||
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control. | ||
# This is especially recommended for binary packages to ensure reproducibility, and is more | ||
# commonly ignored for libraries. | ||
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control | ||
#poetry.lock | ||
|
||
# pdm | ||
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control. | ||
#pdm.lock | ||
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it | ||
# in version control. | ||
# https://pdm.fming.dev/#use-with-ide | ||
.pdm.toml | ||
|
||
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm | ||
__pypackages__/ | ||
|
||
# Celery stuff | ||
celerybeat-schedule | ||
celerybeat.pid | ||
|
||
# SageMath parsed files | ||
*.sage.py | ||
|
||
# Environments | ||
.env | ||
.venv | ||
env/ | ||
venv/ | ||
ENV/ | ||
env.bak/ | ||
venv.bak/ | ||
litellm_uuid.txt | ||
|
||
# Spyder project settings | ||
.spyderproject | ||
.spyproject | ||
|
||
# Rope project settings | ||
.ropeproject | ||
|
||
# mkdocs documentation | ||
/site | ||
|
||
# mypy | ||
.mypy_cache/ | ||
.dmypy.json | ||
dmypy.json | ||
|
||
# Pyre type checker | ||
.pyre/ | ||
|
||
# pytype static type analyzer | ||
.pytype/ | ||
|
||
# Cython debug symbols | ||
cython_debug/ | ||
|
||
# PyCharm | ||
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can | ||
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore | ||
# and can be added to the global gitignore or merged into this file. For a more nuclear | ||
# option (not recommended) you can uncomment the following to ignore the entire idea folder. | ||
#.idea/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# Welcome to the Assessment Generator by Lyzr! | ||
|
||
![Lyzr Logo](./logo/lyzr-logo.png) | ||
|
||
In this Assessment Generator you can upload any textbook PDF, specify the subject and major topics, and instantly generate 10 insightful questions per topic using an AI-powered QA bot Agent from Lyzr SDK. | ||
|
||
|
||
*Note: For this application to function properly in your local system, ensure that the required dependencies are installed and configured correctly, and make sure that you have your OpenAI API Key.* | ||
|
||
### Create Virtual Environment | ||
- `python3 -m venv venv` - Ubuntu/MacOs | ||
- `python -m venv venv` - Windows | ||
|
||
### Activate the environment | ||
- `source venv/bin/activate` - Ubuntu/MaOS | ||
- `venv/Script/acitvate` - Windows | ||
|
||
### Installing Dependencies | ||
- `pip3 install -r requirements.txt`- Ubuntu/MacOs | ||
- `pip install -r requirements.txt` - Windows | ||
|
||
|
||
### Run the application on local server | ||
`streamlit run app.py` | ||
|
||
# About Lyzr | ||
Lyzr is a low-code agent framework that follows an **‘agentic’** way to build LLM apps, contrary to Langchain’s ‘functions and chains’ way and DSPy’s ‘programmatic’ way of building LLM apps. | ||
|
||
- [Lyzr](https://www.lyzr.ai/) | ||
- [Book a Demo](https://www.lyzr.ai/book-demo/) | ||
- [Discord](https://discord.gg/nm7zSyEFA2) | ||
- [Slack](https://join.slack.com/t/genaiforenterprise/shared_invite/zt-2a7fr38f7-_QDOY1W1WSlSiYNAEncLGw) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
import os | ||
from PIL import Image | ||
from utils import utils | ||
import streamlit as st | ||
from dotenv import load_dotenv; load_dotenv() | ||
from lyzr import QABot | ||
|
||
# Setup your config | ||
st.set_page_config( | ||
page_title="Assesement Generator", | ||
layout="centered", # or "wide" | ||
initial_sidebar_state="auto", | ||
page_icon="./logo/lyzr-logo-cut.png" | ||
) | ||
|
||
# Load and display the logo | ||
image = Image.open("./logo/lyzr-logo.png") | ||
st.image(image, width=150) | ||
|
||
# App title and introduction | ||
st.title("Assesement Generator by Lyzr") | ||
st.markdown("### Welcome to the Assesement Generator!") | ||
st.markdown("Assesement Generator by Lyzr will provide you 10 insightful questions on the textbook pdf you have uploaded") | ||
|
||
# Custom function to style the app | ||
def style_app(): | ||
# You can put your CSS styles here | ||
st.markdown(""" | ||
<style> | ||
.app-header { visibility: hidden; } | ||
.css-18e3th9 { padding-top: 0; padding-bottom: 0; } | ||
.css-1d391kg { padding-top: 1rem; padding-right: 1rem; padding-bottom: 1rem; padding-left: 1rem; } | ||
</style> | ||
""", unsafe_allow_html=True) | ||
|
||
# Assesement Generator Application | ||
|
||
# replace this with your openai api key or create an environment variable for storing the key. | ||
os.environ["OPENAI_API_KEY"] = os.getenv('OPENAI_API_KEY') | ||
|
||
|
||
# create directory if it doesn't exist | ||
data = "data" | ||
os.makedirs(data, exist_ok=True) | ||
|
||
|
||
|
||
def vector_store_configuration(bookname): | ||
vector_store_params = { | ||
"vector_store_type": "WeaviateVectorStore", | ||
"url": os.getenv('VECTOR_STORE_URL'), # replce the url with your weaviate cluster url | ||
"api_key": os.getenv('VECTOR_STORE_API'), # replace the api with your weaviate cluster api | ||
"index_name": f"Book{bookname}IndexName" | ||
} | ||
|
||
return vector_store_params | ||
|
||
|
||
def smartstudy_bot(filepath, vector_params): | ||
"This function will implement the Lyzr's QA agent to summarize the Youtube Video" | ||
smartstudy = QABot.pdf_qa( | ||
input_files=[str(filepath)], | ||
vector_store_params=vector_params | ||
) | ||
|
||
return smartstudy | ||
|
||
if __name__ == "__main__": | ||
style_app() | ||
uploaded_file = st.file_uploader("Choose PDF file", type=["pdf"]) | ||
if uploaded_file is not None: | ||
filename = utils.save_uploaded_file(uploaded_file) | ||
subject_name = st.text_input("Write the subject of your Book") | ||
topics = st.text_input("Enter topics (by comma seperated)") | ||
topics_list = [topic.strip() for topic in topics.split(",") if topic.strip()] | ||
|
||
if topics_list is not None: | ||
if st.button("Generate"): | ||
path = utils.get_files_in_directory(data) | ||
filepath = path[0] | ||
vector_params = vector_store_configuration(filename) | ||
study_agent = smartstudy_bot(filepath=filepath, vector_params=vector_params) | ||
if study_agent is not None: | ||
topic_response = utils.user_subject_topics(agent=study_agent, subject=subject_name, topics_lst=topics_list) | ||
utils.flashcard_viewer(response=topic_response) | ||
else: | ||
utils.remove_existing_files(data) | ||
st.warning('Please Upload pdf file') | ||
|
||
with st.expander("ℹ️ - About this App"): | ||
st.markdown(""" | ||
This app uses Lyzr QABot agent to 10 qustions from TextBook pdf. The QABot agent is built on the powerful Retrieval-Augmented Generation (RAG) model, enhancing your ability to extract valuable insights. For any inquiries or issues, please contact Lyzr. | ||
""") | ||
st.link_button("Lyzr", url='https://www.lyzr.ai/', use_container_width = True) | ||
st.link_button("Book a Demo", url='https://www.lyzr.ai/book-demo/', use_container_width = True) | ||
st.link_button("Discord", url='https://discord.gg/nm7zSyEFA2', use_container_width = True) | ||
st.link_button("Slack", url='https://join.slack.com/t/genaiforenterprise/shared_invite/zt-2a7fr38f7-_QDOY1W1WSlSiYNAEncLGw', use_container_width = True) |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import os | ||
import shutil | ||
import streamlit as st | ||
from pathlib import Path | ||
import pandas as pd | ||
|
||
def remove_existing_files(directory): | ||
for filename in os.listdir(directory): | ||
file_path = os.path.join(directory, filename) | ||
try: | ||
if os.path.isfile(file_path) or os.path.islink(file_path): | ||
os.unlink(file_path) | ||
elif os.path.isdir(file_path): | ||
shutil.rmtree(file_path) | ||
except Exception as e: | ||
st.error(f"Error while removing existing files: {e}") | ||
|
||
|
||
def get_files_in_directory(directory): | ||
# This function help us to get the file path along with filename. | ||
files_list = [] | ||
|
||
if os.path.exists(directory) and os.path.isdir(directory): | ||
for filename in os.listdir(directory): | ||
file_path = os.path.join(directory, filename) | ||
|
||
if os.path.isfile(file_path): | ||
files_list.append(file_path) | ||
|
||
return files_list | ||
|
||
def save_uploaded_file(uploaded_file): | ||
# Function to save uploaded file | ||
remove_existing_files('data') | ||
|
||
file_path = os.path.join('data', uploaded_file.name) | ||
with open(file_path, "wb") as file: | ||
file.write(uploaded_file.read()) | ||
st.success("File uploaded successfully") | ||
|
||
rev = uploaded_file.name[::-1] | ||
rev = rev[4:] | ||
filename = rev[::-1] | ||
|
||
return filename[:3] | ||
|
||
|
||
def user_subject_topics(agent, subject, topics_lst): | ||
resposne_flash = {} | ||
for topic in topics_lst: | ||
prompt = f"""You are an expert of this {subject}, Can you write down 3-5 important questions on this {subject} and its topics: {topic} """ | ||
response = agent.query(prompt) | ||
if response is not None: | ||
if response.response == 'Empty Response': | ||
st.warning('Please provide valid pdf') | ||
|
||
elif response.response != 'Empty Response': | ||
# st.subheader("These are the Important Questions, you should prepare") | ||
# st.write(response.response) | ||
resposne_flash[topic] = response.response.split('?') | ||
|
||
return resposne_flash | ||
|
||
|
||
def flashcard_viewer(response:dict): | ||
for topic, questions in response.items(): | ||
st.subheader(topic) | ||
for question in questions: | ||
st.write(question) | ||
st.markdown("---") | ||
|