Spaces:
Runtime error
Runtime error
File size: 4,647 Bytes
4770b19 8b15bbc 4770b19 8b15bbc 4770b19 682d5d5 4770b19 8b15bbc 4770b19 ed7db54 4770b19 e277616 ed7db54 48b930a e277616 4770b19 8b15bbc 4770b19 ea6e1d6 8b15bbc 4770b19 d31048a 4770b19 ed7db54 f23f972 4770b19 8b15bbc 4770b19 9d6dce4 4770b19 78d0ddd 16905b4 78d0ddd 4770b19 8b15bbc f23f972 4770b19 ed7db54 4770b19 8b15bbc f23f972 8b15bbc 302b13c 78d0ddd 8b15bbc 4770b19 8b15bbc f23f972 4770b19 8b15bbc 4770b19 ed7db54 8b15bbc 4770b19 | 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 | import os
import openai
import gradio as gr
OPENAI_API_KEY = os.getenv("OPENAI_API_KEY")
############################
def generate_ai_text(prompt,temperature):
query = prompt
response = openai.ChatCompletion.create(
model="gpt-4o",
messages=[
{
"role": "system",
"content": query
},
{
"role": "user",
"content": " "
},
],
temperature=temperature,
max_tokens=3000,
top_p=1,
frequency_penalty=0,
presence_penalty=0
)
text = response["choices"][0]["message"]["content"]
return text
def generate_prompt(risk_category,ini_prompt,no_login,low_activity,repeated_course,low_marks,WAM,forum_count,pre_fail,this_fail):
body = ini_prompt
data = f"The student is predicted to be '{risk_category}'\n Here are the indicators for the student:\n No Moodle Login: {no_login}\n Low Moodle Activity: {low_activity}\n Student is repeating this course: {repeated_course}\n Student has low marks: {low_marks}\n Student's WAM across all courses: {WAM}\n Student's forum activity: {forum_count}\n Count of student's previous fail of all courses: {pre_fail}\n Count of student's previous fail of this courses: {this_fail}\n "
text = body + "\n\n" + data
return text
############################
title = "Explainer v0.1"
with gr.Blocks(title=title) as demo:
gr.Markdown("""
# Explainer v0.2
Generate explanation. Select the conditions for a dummy student. Put your prompt in the text input window.
""")
with gr.Tab("Features"):
with gr.Row():
with gr.Column():
risk_category = gr.Radio(["May need urgent support", "May fall behind","On track"],
label="Prediction Status",
value="May need urgent support",
type="value"
)
no_login = gr.Radio(["Yes", "No"],
label="No Moodle login in last 7 days",
value="Yes",
type="value"
)
low_activity = gr.Radio(["Yes", "No"],
label="Low Moodle activity",
value="Yes",
type="value"
)
repeated_course = gr.Radio(["Yes", "No"],
label="Repeated Course",
value="No",
type="value"
)
low_marks = gr.Radio(["Yes", "No"],
label="Low marks",
value="No",
type="value"
)
WAM = gr.Radio(["Low","Medium", "High"],
label="WAM",
value="Low",
type="value"
)
forum_count = gr.Radio(["Low","Medium", "High"],
label="Moodle Forum Action",
value="Low",
type="value"
)
with gr.Row():
pre_fail = gr.Slider(0, 10, value=0, step=1, label="Previous Fail (All Course)", info="Choose between 0 and 10")
with gr.Row():
this_fail = gr.Slider(0, 10, value=0, step=1, label="Previous Fail (This Course)", info="Choose between 0 and 10")
with gr.Column():
ini_prompt = gr.Textbox(label="initial prompt",
info="Initial prompt",
lines=15,
value=" ",
)
gr.Examples(["A machine learning prediction model was developed to predict student's academic performance for a course. A list of data points will be given later, please analyze and explain the potential reasons for the student's success or failure. Be concise, reply under 200 words."], inputs=[ini_prompt])
with gr.Column():
revised_prompt = gr.Textbox(
label="Revised Prompt",
info="Revised Prompt",
lines=25,
value=" ")
with gr.Row():
temperature = gr.Slider(0, 2, value=0.5, step=0.1, label="LLM temperature", info="Choose between 0 and 2")
prompt_button = gr.Button("Generate Revised Prompt")
with gr.Column():
genai_text = gr.Textbox(
label="AI-generated Text",
info="AI-generated Text",
lines=30,
value="Depending on message content, please wait up to 30s, please scroll if message is long",
)
text_ai_button = gr.Button("Generate Text")
prompt_button.click(generate_prompt, inputs=[risk_category,ini_prompt,no_login,low_activity,repeated_course,low_marks,WAM,forum_count,pre_fail,this_fail], outputs=[revised_prompt])
text_ai_button.click(generate_ai_text, inputs=[revised_prompt,temperature], outputs=[genai_text], api_name="gen")
demo.launch() |