diff --git a/CEREBRO by the Code Hackers/booksumarise.py b/CEREBRO by the Code Hackers/booksumarise.py new file mode 100644 index 0000000..09523d0 --- /dev/null +++ b/CEREBRO by the Code Hackers/booksumarise.py @@ -0,0 +1,283 @@ +import streamlit as st +import requests +import random +from PIL import Image +from io import BytesIO +import plotly.graph_objects as go +import datetime + +GOOGLE_BOOKS_API_URL = "https://www.googleapis.com/books/v1/volumes" + +# Set page configuration +st.set_page_config(layout="wide") +st.title('📚 CEREBRO - Your Ultimate Learning Companion') + +# Cool CSS for visuals and animations +st.markdown( + """ + + """, unsafe_allow_html=True +) + +# Sidebar with mood selection and book progress +st.sidebar.header("📊 Personalized Experience") +mood = st.sidebar.selectbox("How are you feeling today?", + ["Happy", "Curious", "Focused", "Mysterious", "Energetic", "Creative"]) + +st.sidebar.subheader("📖 Reading Challenge") +books_to_read = st.sidebar.number_input("Set your learning goal (books per month):", min_value=1, max_value=50, value=5) +progress = st.sidebar.slider("Update your progress:", 0, books_to_read, 0) +progress_percentage = (progress / books_to_read) * 100 + +# Circular progress bar +fig = go.Figure(go.Indicator( + mode="gauge+number", + value=progress, + title={'text': "Reading Progress", 'font': {'color': "white"}}, + gauge={'axis': {'range': [0, books_to_read], 'tickwidth': 2, 'tickcolor': "white"}, + 'bar': {'color': "#ff6f61"}, + 'bgcolor': "black", + 'borderwidth': 2, + 'bordercolor': "white", + 'steps': [{'range': [0, books_to_read], 'color': "#1f77b4"}]}, + domain={'x': [0, 1], 'y': [0, 1]} +)) +st.sidebar.plotly_chart(fig, use_container_width=True) + +# Book Finder Section +col1, col2 = st.columns([2, 1]) +with col1: + st.subheader("🔍 Book Finder") + input_text = st.text_input("Search for a book or subject:") + + + def fetch_book_data(query): + response = requests.get(GOOGLE_BOOKS_API_URL, params={'q': query}) + if response.status_code == 200: + data = response.json() + return data['items'] if 'items' in data else None + return None + + + def extract_book_info(book): + info = book['volumeInfo'] + return { + 'title': info.get('title', 'No title available'), + 'authors': ', '.join(info.get('authors', ['Unknown author'])), + 'description': info.get('description', 'No summary available'), + 'publishedDate': info.get('publishedDate', 'Unknown publication date'), + 'categories': ', '.join(info.get('categories', ['Unknown category'])), + 'pageCount': info.get('pageCount', 'Unknown'), + 'averageRating': info.get('averageRating', 'Not rated'), + 'imageLinks': info.get('imageLinks', {}).get('thumbnail', None), + 'infoLink': info.get('infoLink', '#') + } + + + if input_text: + books = fetch_book_data(input_text) + if books: + book = extract_book_info(books[0]) + + # Display book information + st.subheader(book['title']) + st.write(f"**By:** {book['authors']}") + + if book['imageLinks']: + try: + response = requests.get(book['imageLinks']) + if response.status_code == 200: + img = Image.open(BytesIO(response.content)) + st.image(img, width=200) + except Exception as e: + st.write(f"Image error: {e}") + st.write(f"**Published:** {book['publishedDate']}") + st.write(f"**Categories:** {book['categories']}") + st.write(f"**Pages:** {book['pageCount']}") + st.write(f"**Rating:** {book['averageRating']}/5") + + with st.expander("📖 Book Summary"): + st.write(book['description']) + + st.markdown(f"[More Info]({book['infoLink']})") + +# Mood-based book recommendations +with col2: + st.subheader(f"📚 Books for Your {mood} Mood") + + + def recommend_books_by_mood(mood): + mood_genres = { + "Happy": ["Comedy", "Self-help", "Inspirational"], + "Curious": ["Non-fiction", "Science", "History"], + "Focused": ["Business", "Technology", "Productivity"], + "Mysterious": ["Mystery", "Crime", "Suspense"], + "Energetic": ["Adventure", "Thriller", "Science Fiction"], + "Creative": ["Art", "Design", "Creativity"] + } + genre = random.choice(mood_genres[mood]) + response = requests.get(GOOGLE_BOOKS_API_URL, params={'q': f'subject:{genre}', 'maxResults': 5}) + if response.status_code == 200: + data = response.json() + return [extract_book_info(book) for book in data.get('items', [])] + return None + + + mood_books = recommend_books_by_mood(mood) + if mood_books: + for book in mood_books[:3]: + st.markdown(f""" +
+

{book['title']}

+

by {book['authors']}

+ Book cover +

{book['description'][:100]}...

+ More Info +
+
+ """, unsafe_allow_html=True) + else: + st.write("No recommendations found. Try another mood!") +# Adaptive quiz related to the book search +st.subheader("🧠 Book-Related Quiz") + +if input_text and books: + # Generate questions from book metadata + book_question = { + "question": f"Who is the author of '{book['title']}'?", + "options": [book['authors'], "Unknown", "J.K. Rowling", "George Orwell"], + "answer": book['authors'] + } + + publication_question = { + "question": f"When was '{book['title']}' published?", + "options": [book['publishedDate'], "2020", "2010", "Unknown"], + "answer": book['publishedDate'] + } + + # Select a random question to display + quiz_question = random.choice([book_question, publication_question]) + st.write(f"**{quiz_question['question']}**") + selected_option = st.radio("Choose your answer:", quiz_question['options']) + + if st.button("Submit Book Quiz Answer"): + if selected_option == quiz_question['answer']: + st.success("Correct! 🎉") + else: + st.error(f"Wrong! The correct answer is {quiz_question['answer']}.") + +# Study planner with tasks +st.subheader("🗂️ Study Planner") +if 'tasks' not in st.session_state: + st.session_state['tasks'] = [] + +task = st.text_input("Add a new task to your to-do list:") +if st.button("Add Task"): + st.session_state['tasks'].append(task) + st.write(f"Added task: {task}") + +if st.session_state['tasks']: + st.subheader("Your Tasks") + for i, task in enumerate(st.session_state['tasks']): + st.write(f"{i + 1}. {task}") + if st.button(f"Remove Task {i + 1}", key=f"remove_task_{i}"): + st.session_state['tasks'].pop(i) + +# AI-powered study time suggestions +st.subheader("📅 AI-Powered Study Time Suggestions") + + +def suggest_study_time(): + current_hour = datetime.datetime.now().hour + return "Morning" if current_hour >= 18 else "Afternoon" + + +suggested_time = suggest_study_time() +st.write( + f"Based on your current schedule, it's best to study in the **{suggested_time}** tomorrow for maximum productivity!") diff --git a/README.md b/README.md index ea47f84..a0bee55 100644 --- a/README.md +++ b/README.md @@ -1 +1,9 @@ -# hackathon-projects \ No newline at end of file +CEREBRO - Your Ultimate Learning Companion + +📚 Welcome to CEREBRO, an innovative application designed to enhance your learning experience! Whether you're preparing for exams or simply looking to expand your knowledge, CEREBRO offers a suite of interactive features to help you achieve your learning goals. Features : Book Search & Information: Discover books and access essential details such as summaries, authors, and publication dates. Mood-Based Recommendations: Get personalized book suggestions based on your current mood! Reading Challenge Tracker: Set reading goals and track your progress with an interactive gauge. Adaptive Quizzes: Test your knowledge with fun quizzes that adapt to your learning needs. Study Planner: Organize your tasks and manage your study schedule effortlessly. Visual Notes: Take notes in a markdown-friendly interface and save them as PDFs for later reference. + +Technologies Used Frontend: Streamlit, HTML, CSS Backend: Python APIs: Google Books API for book data Visualization: Plotly for charts and graphs and various AI integrations. + +Usage Once you have the application running, you can: + +Search for books by entering a title or subject. Track your reading progress through the reading challenge feature. Take adaptive quizzes and manage your study tasks with ease. Create visual notes and you can gather information in it.