import os from groq import Groq import pandas as pd from fpdf import FPDF import streamlit as st # Directly set the Groq API key api_key = "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" # Initialize Groq client client = Groq(api_key=api_key) # Function to generate a study plan def generate_study_plan(subject, days, hours): try: # Call Groq API to generate the study schedule messages = [ {"role": "user", "content": f"Create a {days}-day study plan for {subject} with {hours} hours per day."} ] response = client.chat.completions.create( messages=messages, model="llama3-8b-8192", ) study_plan = response.choices[0].message.content return study_plan except Exception as e: return f"Error generating study plan: {str(e)}" # Export study plan to PDF def export_to_pdf(study_plan, filename="study_plan.pdf"): pdf = FPDF() pdf.add_page() pdf.set_font("Arial", size=12) pdf.multi_cell(0, 10, study_plan) pdf.output(filename) return filename # Export study plan to Excel def export_to_excel(study_plan, filename="study_plan.xlsx"): plan_lines = study_plan.split("\n") df = pd.DataFrame({"Study Plan": plan_lines}) df.to_excel(filename, index=False) return filename # Streamlit UI st.title("Personalized Study Assistant Chatbot") st.write("Generate a tailored study plan with actionable insights and download options.") # Input fields subject = st.text_input("Study Topic or Exam Subject", "IELTS") days = st.number_input("Number of Days for Preparation", min_value=1, value=7) hours = st.number_input("Available Study Hours Per Day", min_value=1, value=3) # Generate study plan button if st.button("Generate Study Plan"): study_plan = generate_study_plan(subject, days, hours) st.subheader("Generated Study Plan") st.text_area("Your Study Plan", study_plan, height=300) # File generation after study plan is created pdf_file = export_to_pdf(study_plan) excel_file = export_to_excel(study_plan) # Create download buttons for both PDF and Excel with open(pdf_file, "rb") as file: st.download_button("Download PDF", file, file_name="study_plan.pdf", key="pdf_download") with open(excel_file, "rb") as file: st.download_button("Download Excel", file, file_name="study_plan.xlsx", key="excel_download")