commonman commited on
Commit
b20bc5a
·
1 Parent(s): fba560a

separate random generation and LLM submission

Browse files
Files changed (1) hide show
  1. app.py +14 -16
app.py CHANGED
@@ -15,7 +15,8 @@ df = pd.read_csv('data/MYP_Key_Related_Concepts.tsv', sep='\t')
15
 
16
  # Get subjects and MYP years
17
  subjects = df['Subject'].tolist()
18
- myp_years = [str(i) for i in range(1, 6)]
 
19
 
20
  def generate_unit(subject, year):
21
  # Select a random key and related concept based on the subject
@@ -31,8 +32,6 @@ def generate_unit(subject, year):
31
  return key_concept, related_concept, global_context
32
 
33
  def botResponse(user_input, messages):
34
- # adds the user input to the ongoing chat log
35
- # and submits the log to OpenAI
36
  messages.append({"role": "user", "content": user_input})
37
  response = openai.ChatCompletion.create(
38
  model="gpt-3.5-turbo-0613",
@@ -40,22 +39,21 @@ def botResponse(user_input, messages):
40
  )
41
  return response.choices[0].message['content']
42
 
43
- def get_llm_response_and_generate_unit(subject, year):
44
- key_concept, related_concept, global_context = generate_unit(subject, year)
45
  user_input = f"We are studying the subject '{subject}' with a focus on the key concept '{key_concept}', the related concept '{related_concept}', and under the global context of '{global_context}'."
46
  messages = [
47
  {"role": "system", "content": "You are a helpful assistant."},
48
  {"role": "user", "content": user_input}
49
  ]
50
  llm_response = botResponse(user_input, messages)
51
- return key_concept, related_concept, global_context, llm_response
52
-
53
- iface = gr.Interface(fn=get_llm_response_and_generate_unit,
54
- inputs=[gr.inputs.Dropdown(subjects, label="Subject"),
55
- gr.inputs.Dropdown(myp_years, label="MYP Year")],
56
- outputs=[gr.outputs.Textbox(label="Key Concept"),
57
- gr.outputs.Textbox(label="Related Concept"),
58
- gr.outputs.Textbox(label="Global Context"),
59
- gr.outputs.Textbox(label="LLM Response")])
60
-
61
- iface.launch()
 
15
 
16
  # Get subjects and MYP years
17
  subjects = df['Subject'].tolist()
18
+ myp_years = ["MYP 1 / Grade 6", "MYP 2 / Grade 7", "MYP 3 / Grade 8", "MYP 4 / Grade 9", "MYP 5 / Grade 10"]
19
+
20
 
21
  def generate_unit(subject, year):
22
  # Select a random key and related concept based on the subject
 
32
  return key_concept, related_concept, global_context
33
 
34
  def botResponse(user_input, messages):
 
 
35
  messages.append({"role": "user", "content": user_input})
36
  response = openai.ChatCompletion.create(
37
  model="gpt-3.5-turbo-0613",
 
39
  )
40
  return response.choices[0].message['content']
41
 
42
+ def get_llm_response_and_generate_unit(subject, year, key_concept, related_concept, global_context):
 
43
  user_input = f"We are studying the subject '{subject}' with a focus on the key concept '{key_concept}', the related concept '{related_concept}', and under the global context of '{global_context}'."
44
  messages = [
45
  {"role": "system", "content": "You are a helpful assistant."},
46
  {"role": "user", "content": user_input}
47
  ]
48
  llm_response = botResponse(user_input, messages)
49
+ return llm_response
50
+
51
+ iface = gr.Interface(fn=[generate_unit, get_llm_response_and_generate_unit],
52
+ inputs=[[gr.inputs.Dropdown(subjects, label="Subject"), default=subjects[0],
53
+ gr.inputs.Dropdown(myp_years, label="MYP Year"), default=myp_years[0]],
54
+ [gr.inputs.Dropdown(subjects, label="Subject"), default=subjects[0],
55
+ gr.inputs.Dropdown(myp_years, label="MYP Year"), default=myp_years[0],
56
+ gr.inputs.Textbox(label="Key Concept"),
57
+ gr.inputs.Textbox(label="Related Concept"),
58
+ gr.inputs.Textbox(label="Global Context")]],
59
+ outputs