MohammadYaseen commited on
Commit
0377ea6
·
verified ·
1 Parent(s): ef9a4e0

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +74 -0
app.py ADDED
@@ -0,0 +1,74 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ from groq import Groq
3
+ import pandas as pd
4
+ from fpdf import FPDF
5
+ import streamlit as st
6
+
7
+ # Directly set the Groq API key
8
+ api_key = "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"
9
+
10
+ # Initialize Groq client
11
+ client = Groq(api_key=api_key)
12
+
13
+ # Function to generate a study plan
14
+ def generate_study_plan(subject, days, hours):
15
+ try:
16
+ # Call Groq API to generate the study schedule
17
+ messages = [
18
+ {"role": "user",
19
+ "content": f"Create a {days}-day study plan for {subject} with {hours} hours per day."}
20
+ ]
21
+ response = client.chat.completions.create(
22
+ messages=messages,
23
+ model="llama3-8b-8192",
24
+ )
25
+ study_plan = response.choices[0].message.content
26
+ return study_plan
27
+ except Exception as e:
28
+ return f"Error generating study plan: {str(e)}"
29
+
30
+ # Export study plan to PDF
31
+ def export_to_pdf(study_plan, filename="study_plan.pdf"):
32
+ pdf = FPDF()
33
+ pdf.add_page()
34
+ pdf.set_font("Arial", size=12)
35
+ pdf.multi_cell(0, 10, study_plan)
36
+ pdf.output(filename)
37
+ return filename
38
+
39
+ # Export study plan to Excel
40
+ def export_to_excel(study_plan, filename="study_plan.xlsx"):
41
+ plan_lines = study_plan.split("\n")
42
+ df = pd.DataFrame({"Study Plan": plan_lines})
43
+ df.to_excel(filename, index=False)
44
+ return filename
45
+
46
+ # Streamlit UI
47
+ st.title("Personalized Study Assistant Chatbot")
48
+ st.write("Generate a tailored study plan with actionable insights and export options.")
49
+
50
+ # Input fields
51
+ subject = st.text_input("Study Topic or Exam Subject", "IELTS")
52
+ days = st.number_input("Number of Days for Preparation", min_value=1, value=7)
53
+ hours = st.number_input("Available Study Hours Per Day", min_value=1, value=3)
54
+
55
+ # Generate study plan button
56
+ if st.button("Generate Study Plan"):
57
+ study_plan = generate_study_plan(subject, days, hours)
58
+ st.subheader("Generated Study Plan")
59
+ st.text_area("Your Study Plan", study_plan, height=300)
60
+
61
+ # Export options
62
+ col1, col2 = st.columns(2)
63
+ with col1:
64
+ if st.button("Export to PDF"):
65
+ pdf_file = export_to_pdf(study_plan)
66
+ st.success(f"Study plan exported as {pdf_file}")
67
+ with open(pdf_file, "rb") as file:
68
+ st.download_button("Download PDF", file, file_name="study_plan.pdf")
69
+ with col2:
70
+ if st.button("Export to Excel"):
71
+ excel_file = export_to_excel(study_plan)
72
+ st.success(f"Study plan exported as {excel_file}")
73
+ with open(excel_file, "rb") as file:
74
+ st.download_button("Download Excel", file, file_name="study_plan.xlsx")