QL2023 commited on
Commit
8b15bbc
·
verified ·
1 Parent(s): 3e905aa

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -80
app.py CHANGED
@@ -6,60 +6,16 @@ OPENAI_API_KEY = os.getenv("OPENAI_API_KEY")
6
 
7
  ############################
8
 
9
- def generate_rule(no_login,low_activity,repeated_course,low_marks,second_lang):
10
- body = " "
11
-
12
- if no_login == "Yes" or low_activity == "Yes":
13
- body += "\n\n - Have you found any <a href = ""https://www.student.unsw.edu.au/moodle/support""> technical difficulties using Moodle?</a>"
14
- body += "\n\n - Did you know there are <a href = ""https://www.student.unsw.edu.au/time-management""> six steps to time management for success</a>?"
15
- if repeated_course == "Yes":
16
- body += "\n\n - Did you know that accessing an <a href=""https://www.student.unsw.edu.au/advising"">academic adviser</a> is free?"
17
- if second_lang == "Yes":
18
- body += "\n\n - Refining your <a href=""https://www.student.unsw.edu.au/english"">communication skills</a> is critical for success. Did you know there are opportunities available?"
19
- body += "\n\n - Students often need to deliver oral presentations in tutorials and seminars. Check out the resources below for helpful tips on presentations and public speaking: <a href=""https://www.student.unsw.edu.au/support-oral-presentations"">Support for Oral Presentations</a>."
20
- if low_marks == "Yes":
21
- body += "\n\n - Did you know that learning all <a href = ""https://www.student.unsw.edu.au/study-hacks"">the hacks you need for success</a> is available?"
22
- body += "\n\n - Do you want to <a href = ""https://www.student.unsw.edu.au/skills"">develop and refine your academic skills</a> more?"
23
- body += "\n\n - Did you know that accessing an <a href=""https://www.student.unsw.edu.au/advising"">academic adviser</a> is free?"
24
- if no_login == "No" and low_activity == "No" and repeated_course == "No" and repeated_course == "No" and low_marks == "No":
25
- body += "\n\n - Did you know that accessing an <a href=""https://www.student.unsw.edu.au/advising"">academic adviser</a> is free?"
26
- body += "\n\n - Have you found any <a href = ""https://www.student.unsw.edu.au/moodle/support""> technical difficulties using Moodle?</a>"
27
-
28
- return body
29
-
30
- def generate_link(no_login,low_activity,repeated_course,low_marks,second_lang):
31
- body = " "
32
-
33
- if no_login == "Yes" or low_activity == "Yes":
34
- body += "\n\n""https://www.student.unsw.edu.au/moodle/support"" "
35
- body += "\n\n""https://www.student.unsw.edu.au/time-management"" "
36
- if repeated_course == "Yes":
37
- body += "\n\n""https://www.student.unsw.edu.au/advising"" "
38
- if second_lang == "Yes":
39
- body += "\n\n""https://www.student.unsw.edu.au/english"" "
40
- body += "\n\n""https://www.student.unsw.edu.au/support-oral-presentations"" "
41
- if low_marks == "Yes":
42
- body += "\n\n""https://www.student.unsw.edu.au/study-hacks"" "
43
- body += "\n\n""https://www.student.unsw.edu.au/skills"" "
44
- body += "\n\n""https://www.student.unsw.edu.au/advising"" "
45
- if no_login == "No" and low_activity == "No" and repeated_course == "No" and repeated_course == "No" and low_marks == "No":
46
- body += "\n\n""https://www.student.unsw.edu.au/advising"" "
47
- body += "\n\n""https://www.student.unsw.edu.au/moodle/support"" "
48
-
49
- return body
50
-
51
- def generate_ai_email(query,persona,temperature,no_login,low_activity,repeated_course,low_marks,second_lang):
52
-
53
- rule_context = generate_link(no_login,low_activity,repeated_course,low_marks,second_lang)
54
-
55
- prompt = f"\"{persona}\". \n\n In your email, provide suggestions and the following hyper links: \n \"{rule_context}\".\n\n Note that each link should appear only once, remove duplicate links. \n\n Also, here's some additional info from lecturer to the student: \"{query}\". Use Australian spelling."
56
 
 
 
57
  response = openai.ChatCompletion.create(
58
  model="gpt-4",
59
  messages=[
60
  {
61
  "role": "system",
62
- "content": prompt
63
  },
64
  {
65
  "role": "user",
@@ -76,21 +32,15 @@ def generate_ai_email(query,persona,temperature,no_login,low_activity,repeated_c
76
  text = response["choices"][0]["message"]["content"]
77
  return text
78
 
79
- def generate_rule_email(no_login,low_activity,repeated_course,low_marks,second_lang):
80
- body = "Hello\n\n I hope this email finds you well. I wanted to check in and see how you're doing with your current coursework and if you have any questions or concerns. Please don't hesitate to reach out if you need any assistance or guidance.\n Suggestions:\n"
81
-
82
- body += generate_rule(no_login,low_activity,repeated_course,low_marks,second_lang)
83
-
84
- return body
85
 
86
  ############################
87
 
88
- title = "Email Generator v0.2"
89
 
90
  with gr.Blocks(title=title) as demo:
91
  gr.Markdown("""
92
- # Email Generator v0.2
93
- Generate message. Select the conditions for a dummy student. Put your additional note in the left input window and select a tone.
94
  """)
95
  with gr.Tab("Email Content"):
96
  with gr.Row():
@@ -115,9 +65,9 @@ with gr.Blocks(title=title) as demo:
115
  value="No",
116
  type="value"
117
  )
118
- second_lang = gr.Radio(["Yes", "No"],
119
- label="English as a second language",
120
- value="No",
121
  type="value"
122
  )
123
  with gr.Row():
@@ -127,35 +77,30 @@ with gr.Blocks(title=title) as demo:
127
  step = 0.1
128
  )
129
  with gr.Column():
130
- email_input1 = gr.Textbox(label="Additional info",
131
- info="Additional info to be included on top of standard rules, message for student, etc. Select from an example below or start typing",
132
- lines=5,
133
- value=" ",
134
- )
135
- gr.Examples(["I understand you applied for special consideration","I've never seen you in class","I heard you lost your pet"], inputs=[email_input1])
136
- email_input2 = gr.Textbox(label="Persona",
137
- info="Temporary input window for persona",
138
  lines=5,
139
  value=" ",
140
  )
141
- gr.Examples(["You are a friendly professor who is trying to give the student a reminder.","You are an angry professor who is trying to give the student a warning."], inputs=[email_input2])
142
  with gr.Column():
143
- email_rule = gr.Textbox(
144
- label="Rule-based Email",
145
- info="Email generated based on rules without knowledge of additional info",
146
  lines=15,
147
- value="Please scroll if message is long")
148
- email_rule_button = gr.Button("Generate Rule-based Email")
149
  with gr.Column():
150
- email_ai = gr.Textbox(
151
- label="AI-generated Email",
152
- info="Combination of rules and additional info you typed",
153
  lines=15,
154
  value="Depending on message content, please wait up to 30s, please scroll if message is long",
155
  )
156
- email_ai_button = gr.Button("Generate AI Email")
157
 
158
- email_ai_button.click(generate_ai_email, inputs=[email_input1,email_input2,temperature,no_login,low_activity,repeated_course,low_marks,second_lang], outputs=[email_ai], api_name="gen")
159
- email_rule_button.click(generate_rule_email, inputs=[no_login,low_activity,repeated_course,low_marks,second_lang], outputs=[email_rule])
 
160
 
161
  demo.launch()
 
6
 
7
  ############################
8
 
9
+ def generate_ai_text(prompt,temperature):
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
10
 
11
+ query = prompt
12
+
13
  response = openai.ChatCompletion.create(
14
  model="gpt-4",
15
  messages=[
16
  {
17
  "role": "system",
18
+ "content": query
19
  },
20
  {
21
  "role": "user",
 
32
  text = response["choices"][0]["message"]["content"]
33
  return text
34
 
 
 
 
 
 
 
35
 
36
  ############################
37
 
38
+ title = "Explainer v0.1"
39
 
40
  with gr.Blocks(title=title) as demo:
41
  gr.Markdown("""
42
+ # Explainer v0.1
43
+ Generate explanation. Select the conditions for a dummy student. Put your prompt in the text input window.
44
  """)
45
  with gr.Tab("Email Content"):
46
  with gr.Row():
 
65
  value="No",
66
  type="value"
67
  )
68
+ WAM = gr.Radio(["Low","Medium", "High"],
69
+ label="WAM",
70
+ value="Low",
71
  type="value"
72
  )
73
  with gr.Row():
 
77
  step = 0.1
78
  )
79
  with gr.Column():
80
+ ini_prompt = gr.Textbox(label="initial prompt",
81
+ info="Initial prompt",
 
 
 
 
 
 
82
  lines=5,
83
  value=" ",
84
  )
85
+ gr.Examples(["A prediction model was developed to determine whether a student will pass or fail a course. Given these data points, please analyze and explain the potential reasons for the student's success or failure."], inputs=[ini_prompt])
86
  with gr.Column():
87
+ revised_prompt = gr.Textbox(
88
+ label="Revised Prompt",
89
+ info="Revised Prompt",
90
  lines=15,
91
+ value=" ")
92
+ prompt_button = gr.Button("Generate Revised Prompt")
93
  with gr.Column():
94
+ genai_text = gr.Textbox(
95
+ label="AI-generated Text",
96
+ info="AI-generated Text",
97
  lines=15,
98
  value="Depending on message content, please wait up to 30s, please scroll if message is long",
99
  )
100
+ text_ai_button = gr.Button("Generate Text")
101
 
102
+ prompt_button.click(generate_prompt, inputs=[no_login,low_activity,repeated_course,low_marks,WAM], outputs=[revised_prompt])
103
+ text_ai_button.click(generate_ai_text, inputs=[revised_prompt,temperature], outputs=[genai_text], api_name="gen")
104
+
105
 
106
  demo.launch()