-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.py
157 lines (133 loc) · 5.45 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
import requests
import openai
import streamlit as st
from io import BytesIO
import base64
from fpdf import FPDF
# Create form for syllabus input
syllabus_input = st.radio("Choose syllabus input method:", ("Text input", "Upload file"))
if syllabus_input == "Text input":
syllabus = st.text_area("Enter your syllabus here:")
elif syllabus_input == "Upload file":
uploaded_file = st.file_uploader("Choose a file")
if uploaded_file is not None:
syllabus = uploaded_file.getvalue().decode("utf-8")
else:
st.write("Please upload a file or enter your syllabus in the text area.")
st.stop()
term_length = st.slider("Select your term length (in weeks)", 1, 20, 10)
# Create form for exam preparation input
exam_syllabus_input = st.radio("Choose exam syllabus input method:", ("Text input", "Upload file"))
if exam_syllabus_input == "Text input":
exam_syllabus = st.text_area("Enter your exam syllabus here:")
elif exam_syllabus_input == "Upload file":
uploaded_file = st.file_uploader("Choose a file")
if uploaded_file is not None:
exam_syllabus = uploaded_file.getvalue().decode("utf-8")
else:
st.write("Please upload a file or enter your exam syllabus in the text area.")
st.stop()
days_left = st.slider("Select the number of days left until your exam", 1, 100, 30)
# Create form for generating study plan
generate_plan = st.button("Generate study plan")
if generate_plan:
if "syllabus" not in locals() or syllabus.strip() == "":
st.write("Please enter your syllabus.")
else:
# Generate study plan
prompt = f"Generate a study plan for a {term_length}-week term based on the following syllabus:\n\n{syllabus}"
response = openai.Completion.create(
engine="davinci",
prompt=prompt,
max_tokens=1024,
n=1,
stop=None,
temperature=0.5,
)
study_plan = response.choices[0].text
# Display study plan to user
st.write("Here's your study plan:")
st.write(study_plan)
# Create form for generating exam preparation plan
generate_exam_plan = st.button("Generate exam preparation plan")
if generate_exam_plan:
if "exam_syllabus" not in locals() or exam_syllabus.strip() == "":
st.write("Please enter your exam syllabus.")
else:
# Generate exam preparation plan
prompt = f"Generate an exam preparation plan based on the following syllabus:\n\n{exam_syllabus}\n\nYou have {days_left} days until your exam."
response = openai.Completion.create(
engine="davinci",
prompt=prompt,
max_tokens=1024,
n=1,
stop=None,
temperature=0.5,
)
exam_plan = response.choices[0].text
# Display exam preparation plan to user
st.write("Here's your exam preparation plan:")
st.write(exam_plan)
# Define the GitHub API endpoint for issues
issues_url = 'https://github.com/gitapi/repos/jistiak/gpt4students/issues'
# Set the headers for the API request, with your personal access token
headers = {
'Authorization': f'Token <your-access-token>',
'Accept': 'application/vnd.github.v3+json'
}
# Define a function to create a new issue on GitHub
def create_github_issue(title, body):
# Define the JSON payload for the API request
payload = {
'title': title,
'body': body
}
# Send the API request to create the new issue
response = requests.post(issues_url, headers=headers, json=payload)
if response.status_code == 201:
print('Feature request posted successfully!')
else:
print('Error:', response.text)
# Call the create_github_issue function with the user's input
create_github_issue('New feature request', 'Please add a feature that allows me to do XYZ')
# create a function to generate resource recommendations
def generate_resources(topic):
prompt = "Find three books, three research papers, and three blog or video links on " + topic
response = openai.Completion.create(
engine="text-davinci-002",
prompt=prompt,
temperature=0.5,
max_tokens=1024,
n = 9,
stop=None,
)
resources = response.choices[0].text.split("\n")
return resources
# create a function to generate a PDF file
def generate_pdf(topic, resources):
pdf = FPDF()
pdf.add_page()
pdf.set_font("Arial", size=16)
pdf.cell(200, 10, txt=f"Recommended Resources for {topic}", ln=1, align="C")
pdf.cell(200, 10, txt=" ", ln=1)
for i, resource in enumerate(resources):
pdf.cell(200, 10, txt=f"{i+1}. {resource}", ln=1, link=resource)
pdf.cell(200, 5, txt=" ", ln=1)
pdf.cell(200, 10, txt=" ", ln=1)
pdf.output("resources.pdf", "F")
with open("resources.pdf", "rb") as pdf_file:
b64 = base64.b64encode(pdf_file.read()).decode()
return b64
# create the Streamlit app interface
st.title("Resource Recommendation Generator")
topic_input = st.text_input("Enter a topic")
if topic_input:
resources = generate_resources(topic_input)
st.markdown("# Recommended Resources")
for i, resource in enumerate(resources):
st.markdown(f"{i+1}. [{resource}]({resource})")
pdf_button = st.download_button(
label="Download PDF",
data=generate_pdf(topic_input, resources),
file_name="resources.pdf"
)