Spaces:
Sleeping
Sleeping
| import streamlit as st | |
| import os | |
| from groq import Groq | |
| # Set up page configuration | |
| st.set_page_config(page_title="EduNexus", page_icon=":book:", layout="wide") | |
| # Set the Groq API key | |
| os.environ["GROQ_API_KEY"] = "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" # Replace with your actual API key | |
| # Initialize Groq client | |
| client = Groq(api_key=os.environ.get("GROQ_API_KEY")) | |
| # Define the LLaMA model to be used | |
| MODEL_NAME = "llama3-8b-8192" | |
| # Function to call Groq API | |
| def call_groq_api(prompt): | |
| try: | |
| chat_completion = client.chat.completions.create( | |
| messages=[{"role": "user", "content": prompt}], | |
| model=MODEL_NAME | |
| ) | |
| return chat_completion.choices[0].message.content | |
| except Exception as e: | |
| return f"Error: {str(e)}" | |
| # Define functions for each tool with few-shot examples | |
| def personalized_learning_assistant(topic): | |
| prompt = f""" | |
| Provide a personalized learning plan for the topic: {topic}. | |
| Example 1: For 'Machine Learning': 'Create a plan with courses on supervised learning, unsupervised learning, and neural networks. Include practical exercises and projects.' | |
| Example 2: For 'Data Science': 'Suggest a plan with a focus on data analysis, visualization, and statistical modeling. Recommend tools like Python, R, and SQL.' | |
| Example 3: For 'Web Development': 'Outline a plan that covers front-end and back-end development, including HTML, CSS, JavaScript, and server-side technologies.' | |
| Example 4: For '{topic}':""" | |
| return call_groq_api(prompt) | |
| def ai_coding_mentor(code_snippet): | |
| prompt = f""" | |
| Review this AI code snippet and provide suggestions or improvements: | |
| {code_snippet} | |
| Example 1: 'In the provided code, consider using a different activation function to improve performance.' | |
| Example 2: 'The code can be optimized by reducing redundant calculations and enhancing readability.' | |
| Example 3: 'Add comments to explain complex sections of the code for better understanding.' | |
| Example 4: 'For the provided snippet, suggest improvements or fixes:''' | |
| return call_groq_api(prompt) | |
| def smart_document_summarizer(document_text): | |
| prompt = f""" | |
| Summarize the following document: | |
| {document_text} | |
| Example 1: 'The document discusses the impact of climate change on global agriculture, emphasizing the need for sustainable practices.' | |
| Example 2: 'It provides an overview of recent advancements in AI technology and its applications in various fields.' | |
| Example 3: 'The text outlines the historical development of renewable energy sources and their future potential.' | |
| Example 4: 'Summarize this document:''' | |
| return call_groq_api(prompt) | |
| def interactive_study_planner(exam_schedule): | |
| prompt = f""" | |
| Create an interactive study plan based on this exam schedule: | |
| {exam_schedule} | |
| Example 1: 'For an exam schedule with subjects A, B, and C, create a plan that allocates study time for each subject and includes breaks.' | |
| Example 2: 'Plan should include daily study goals and revision sessions leading up to the exams.' | |
| Example 3: 'Suggest a study plan that balances subject preparation with relaxation to avoid burnout.' | |
| Example 4: 'Based on the provided schedule, create a study plan:''' | |
| return call_groq_api(prompt) | |
| def real_time_qa_support(question): | |
| prompt = f""" | |
| Provide an answer to the following academic question: | |
| {question} | |
| Example 1: 'Question: What is the capital of France? Answer: Paris.' | |
| Example 2: 'Question: Explain the theory of relativity. Answer: The theory of relativity, developed by Albert Einstein, includes two theories: special relativity and general relativity, explaining the relationship between space, time, and gravity.' | |
| Example 3: 'Question: What is the process of photosynthesis? Answer: Photosynthesis is the process by which green plants use sunlight to synthesize foods with the help of chlorophyll, water, and carbon dioxide.' | |
| Example 4: 'Answer this question:''' | |
| return call_groq_api(prompt) | |
| def mental_health_check_in(feelings): | |
| prompt = f""" | |
| Provide some advice based on these feelings: | |
| {feelings} | |
| Example 1: 'Feeling stressed? Try practicing mindfulness and deep breathing exercises to calm your mind.' | |
| Example 2: 'If you're feeling anxious, consider talking to a trusted friend or counselor for support.' | |
| Example 3: 'Feeling overwhelmed? Break your tasks into smaller steps and focus on completing them one at a time.' | |
| Example 4: 'Based on these feelings, provide advice:''' | |
| return call_groq_api(prompt) | |
| # Initialize session state if not already set | |
| if 'responses' not in st.session_state: | |
| st.session_state['responses'] = { | |
| "personalized_learning_assistant": "", | |
| "ai_coding_mentor": "", | |
| "smart_document_summarizer": "", | |
| "interactive_study_planner": "", | |
| "real_time_qa_support": "", | |
| "mental_health_check_in": "" | |
| } | |
| # Function to clear session state values | |
| def clear_session_state(): | |
| for key in st.session_state.keys(): | |
| if key.startswith('responses'): | |
| st.session_state[key] = "" | |
| if key in ['personalized_learning_assistant', 'ai_coding_mentor', 'smart_document_summarizer', 'interactive_study_planner', 'real_time_qa_support', 'mental_health_check_in']: | |
| st.session_state[key] = "" | |
| # Add custom styling using Streamlit | |
| st.markdown(""" | |
| <style> | |
| body { | |
| background-color: #000000; /* Royal Black */ | |
| color: #ffffff; /* White */ | |
| } | |
| .custom-class { | |
| background-color: #000000; /* Royal Black */ | |
| color: #ffffff; /* White */ | |
| } | |
| .stButton { | |
| background-color: #ffffff; /* White */ | |
| color: #000000; /* Royal Black */ | |
| border-radius: 12px; | |
| padding: 12px 24px; | |
| font-size: 16px; | |
| box-shadow: 0 6px 12px rgba(0, 0, 0, 0.4); | |
| transition: background-color 0.3s, box-shadow 0.3s; | |
| } | |
| .stButton:hover { | |
| background-color: #d3d3d3; /* Light Gray */ | |
| box-shadow: 0 8px 16px rgba(0, 0, 0, 0.5); | |
| } | |
| .stTextInput, .stTextArea { | |
| border: 1px solid #ffffff; /* White */ | |
| border-radius: 12px; | |
| background-color: #ffffff; /* White */ | |
| color: #000000; /* Royal Black */ | |
| } | |
| .stTextInput::placeholder, .stTextArea::placeholder { | |
| color: #000000; /* Royal Black */ | |
| font-weight: bold; | |
| } | |
| .stMarkdown, .stTextInput, .stTextArea { | |
| border-radius: 12px; | |
| } | |
| .stSidebar { | |
| background-color: #000000; /* Royal Black */ | |
| color: #ffffff; /* White */ | |
| } | |
| .stSidebar .stMarkdown { | |
| color: #ffffff; /* White */ | |
| } | |
| .footer { | |
| background-color: #000000; /* Royal Black */ | |
| padding: 15px; | |
| text-align: center; | |
| color: #ffffff; /* White */ | |
| border-top: 1px solid #ffffff; /* White */ | |
| position: fixed; | |
| bottom: 0; | |
| width: 100%; | |
| } | |
| .footer a { | |
| color: #ffffff; /* White */ | |
| margin: 0 15px; | |
| text-decoration: none; | |
| font-size: 18px; | |
| } | |
| .footer a:hover { | |
| color: #d3d3d3; /* Light Gray */ | |
| } | |
| .footer i { | |
| font-size: 22px; | |
| } | |
| .custom-placeholder { | |
| color: #000000; /* Royal Black */ | |
| font-weight: bold; | |
| } | |
| </style> | |
| """, unsafe_allow_html=True) | |
| # Display main title | |
| st.title("EduNexus") | |
| # Sidebar with tasks | |
| st.sidebar.title("Tasks") | |
| tasks = [ | |
| "π Personalized Learning Assistant", | |
| "π€ AI Coding Mentor", | |
| "π Smart Document Summarizer", | |
| "π Interactive Study Planner", | |
| "β Real-Time Q&A Support", | |
| "π¬ Mental Health Check-In" | |
| ] | |
| selected_task = st.sidebar.radio("Select a task", tasks) | |
| # Main content area based on selected task | |
| st.header(f"Selected Task: {selected_task}") | |
| if selected_task == "π Personalized Learning Assistant": | |
| topic = st.text_input("Enter the topic for the learning plan:") | |
| if st.button("Generate Learning Plan"): | |
| st.session_state['responses']["personalized_learning_assistant"] = personalized_learning_assistant(topic) | |
| st.write(st.session_state['responses']["personalized_learning_assistant"]) | |
| elif selected_task == "π€ AI Coding Mentor": | |
| code_snippet = st.text_area("Paste your AI code snippet here:") | |
| if st.button("Review Code"): | |
| st.session_state['responses']["ai_coding_mentor"] = ai_coding_mentor(code_snippet) | |
| st.write(st.session_state['responses']["ai_coding_mentor"]) | |
| elif selected_task == "π Smart Document Summarizer": | |
| document_text = st.text_area("Paste your document text here:") | |
| if st.button("Summarize Document"): | |
| st.session_state['responses']["smart_document_summarizer"] = smart_document_summarizer(document_text) | |
| st.write(st.session_state['responses']["smart_document_summarizer"]) | |
| elif selected_task == "π Interactive Study Planner": | |
| exam_schedule = st.text_area("Enter your exam schedule here:") | |
| if st.button("Create Study Plan"): | |
| st.session_state['responses']["interactive_study_planner"] = interactive_study_planner(exam_schedule) | |
| st.write(st.session_state['responses']["interactive_study_planner"]) | |
| elif selected_task == "β Real-Time Q&A Support": | |
| question = st.text_input("Enter your academic question here:") | |
| if st.button("Get Answer"): | |
| st.session_state['responses']["real_time_qa_support"] = real_time_qa_support(question) | |
| st.write(st.session_state['responses']["real_time_qa_support"]) | |
| elif selected_task == "π¬ Mental Health Check-In": | |
| feelings = st.text_input("How are you feeling today?") | |
| if st.button("Get Advice"): | |
| st.session_state['responses']["mental_health_check_in"] = mental_health_check_in(feelings) | |
| st.write(st.session_state['responses']["mental_health_check_in"]) | |
| # Add a footer with contact information | |
| st.markdown(""" | |
| <div class="footer"> | |
| <a href="mailto:[email protected]"><i class="fa fa-envelope"></i> Contact</a> | |
| <a href="https://www.edunexus.com"><i class="fa fa-globe"></i> Website</a> | |
| <a href="https://www.linkedin.com/company/edunexus"><i class="fa fa-linkedin"></i> LinkedIn</a> | |
| <a href="https://twitter.com/edunexus"><i class="fa fa-twitter"></i> Twitter</a> | |
| </div> | |
| """, unsafe_allow_html=True) | |