Spaces:
Runtime error
Runtime error
use Series interfaces
Browse files
app.py
CHANGED
|
@@ -17,18 +17,13 @@ df = pd.read_csv('data/MYP_Key_Related_Concepts.tsv', sep='\t')
|
|
| 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
|
| 23 |
row = df.loc[df['Subject'] == subject].squeeze()
|
| 24 |
key_concepts = row.filter(regex='Key.*').dropna().tolist()
|
| 25 |
related_concepts = row.filter(regex='Related.*').dropna().tolist()
|
| 26 |
key_concept = random.choice(key_concepts)
|
| 27 |
related_concept = random.choice(related_concepts)
|
| 28 |
-
|
| 29 |
-
# Select a random global context
|
| 30 |
global_context = random.choice(global_contexts)
|
| 31 |
-
|
| 32 |
return key_concept, related_concept, global_context
|
| 33 |
|
| 34 |
def botResponse(user_input, messages):
|
|
@@ -48,19 +43,23 @@ def get_llm_response_and_generate_unit(subject, year, key_concept, related_conce
|
|
| 48 |
llm_response = botResponse(user_input, messages)
|
| 49 |
return llm_response
|
| 50 |
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
gr.
|
| 63 |
-
|
| 64 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 65 |
|
| 66 |
iface.launch()
|
|
|
|
| 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 |
def generate_unit(subject, year):
|
|
|
|
| 21 |
row = df.loc[df['Subject'] == subject].squeeze()
|
| 22 |
key_concepts = row.filter(regex='Key.*').dropna().tolist()
|
| 23 |
related_concepts = row.filter(regex='Related.*').dropna().tolist()
|
| 24 |
key_concept = random.choice(key_concepts)
|
| 25 |
related_concept = random.choice(related_concepts)
|
|
|
|
|
|
|
| 26 |
global_context = random.choice(global_contexts)
|
|
|
|
| 27 |
return key_concept, related_concept, global_context
|
| 28 |
|
| 29 |
def botResponse(user_input, messages):
|
|
|
|
| 43 |
llm_response = botResponse(user_input, messages)
|
| 44 |
return llm_response
|
| 45 |
|
| 46 |
+
iface1 = gr.Interface(fn=generate_unit,
|
| 47 |
+
inputs=[gr.components.inputs.Dropdown(choices=subjects, label="Subject", default=subjects[0]),
|
| 48 |
+
gr.components.inputs.Dropdown(choices=myp_years, label="MYP Year", default=myp_years[0])],
|
| 49 |
+
outputs=[gr.components.outputs.Textbox(label="Key Concept"),
|
| 50 |
+
gr.components.outputs.Textbox(label="Related Concept"),
|
| 51 |
+
gr.components.outputs.Textbox(label="Global Context")])
|
| 52 |
+
|
| 53 |
+
iface2 = gr.Interface(fn=get_llm_response_and_generate_unit,
|
| 54 |
+
inputs=[gr.components.inputs.Dropdown(choices=subjects, label="Subject", default=subjects[0]),
|
| 55 |
+
gr.components.inputs.Dropdown(choices=myp_years, label="MYP Year", default=myp_years[0]),
|
| 56 |
+
gr.components.inputs.Textbox(label="Key Concept"),
|
| 57 |
+
gr.components.inputs.Textbox(label="Related Concept"),
|
| 58 |
+
gr.components.inputs.Textbox(label="Global Context")],
|
| 59 |
+
outputs=gr.components.outputs.Textbox(label="LLM Response"))
|
| 60 |
+
|
| 61 |
+
iface = gr.Series(interfaces=[iface1, iface2],
|
| 62 |
+
title="Unit Idea Generator (MYP Version)",
|
| 63 |
+
description="Step 1: Select a subject and MYP year to generate a unit idea. Step 2: Once you're satisfied with the generated unit idea, use it to generate a response from the language model.")
|
| 64 |
|
| 65 |
iface.launch()
|