File size: 6,919 Bytes
32f0adf
 
3d42484
 
 
 
 
32f0adf
3d42484
 
32f0adf
 
 
 
 
3d42484
 
194079c
46804eb
7a4cfb1
 
3d42484
7a4cfb1
 
 
32f0adf
66453e8
862d7ee
 
3d42484
 
 
32f0adf
194079c
 
 
 
32f0adf
 
 
 
 
 
 
 
 
 
7a4cfb1
 
32f0adf
 
 
 
 
fd55bda
 
 
 
32f0adf
fd55bda
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
32f0adf
 
 
 
 
 
 
 
 
 
 
 
 
 
7a4cfb1
 
 
32f0adf
 
 
 
 
 
 
 
 
 
 
 
7a4cfb1
32f0adf
fd55bda
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
32f0adf
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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
import spaces
import gradio as gr
import torch
from transformers import AutoTokenizer, AutoModelForCausalLM

MODEL_NAME = "Fralet/DDeduPModelv7"

print("Loading tokenizer...")
tokenizer = AutoTokenizer.from_pretrained(MODEL_NAME)

print("Loading model...")
model = AutoModelForCausalLM.from_pretrained(MODEL_NAME, device_map="auto")


prompts = """You are a Design Developer of Educational Programs (DDeduP). Below is an instruction that describes a task.

### Instruction:
{}

### Input:
{}

### Response:
{}"""

def generate(instruction, program, number):
    prompt = prompts.format(instruction, program, "")

    inputs = tokenizer(prompt, return_tensors="pt")
    with torch.no_grad():
        outputs = model.generate(
            **inputs,
            max_new_tokens=number
        )

    text = tokenizer.decode(outputs[0], skip_special_tokens=True)

    if "### Response:" in text:
        text = text.split("### Response:")[1].strip()

    return text


@spaces.GPU
def generate_goal(program):
    instruction="Write an educational program goal for this educational program in English. The goal should be as concise and specific as possible within the context of the professional field."
    return generate(instruction, program, 500)


@spaces.GPU
def generate_learning_outcomes(program):
    instruction="Write 10-12 learning outcomes for this educational program in English in JSON. The learning outcomes should follow Bloom's taxonomy (knowledge, comprehension, application, analysis, synthesis, evaluation)."
    return generate(instruction, program, 4000)

@spaces.GPU
def generate_course_description(program):
    instruction="Provide a concise and informative description of the course in English, highlighting its key objectives, topics covered, and intended outcomes."
    return generate(instruction, program, 1000)

@spaces.GPU
def generate_recommendation(program):
    instruction="Recommend appropriate courses that align with the educational program. Provide course titles in English, enclosed in brackets and separated by semicolons."
    return generate(instruction, program, 4000)

@spaces.GPU
def generate_course_lo_mapping(program):
    instruction = (
        "Match each course with all relevant learning outcome codes from the educational program. "
        "Format the output as a JSON object, ensuring accurate alignment between course content "
        "and program-level learning outcomes."
    )
    return generate(instruction, program, 8000)
    
@spaces.GPU
def generate_professional_standards(program):
    instruction = (
        "Extract all professional standards relevant to this educational program "
        "and present them in JSON format in the English language."
    )
    return generate(instruction, program, 500)
    
@spaces.GPU
def generate_emerging_professions(program):
    instruction = (
        "Extract relevant emerging professions from the Atlas of New Professions "
        "based on the educational program and its stated goal. "
        "Present the results in JSON format, with all content written in Russian."
    )
    return generate(instruction, program, 500)

@spaces.GPU
def generate_graduate_professions(program):
    instruction = (
        "List potential professions that graduates of the educational program "
        "may pursue upon completion in English. "
        "Present the output as a JSON array."
    )
    return generate(instruction, program, 500)
    
with gr.Blocks(title="DDeduP API") as demo:

    gr.Markdown("# DDeduP API")

    with gr.Tab("Generate Goal"):
        goal_input = gr.Textbox(lines=5, label="Educational Program")
        goal_output = gr.Textbox(lines=8, label="Goal")
        goal_btn = gr.Button("Generate Goal")

        goal_btn.click(
            fn=generate_goal,
            inputs=goal_input,
            outputs=goal_output,
            api_name="generate_goals"
        )


    with gr.Tab("Generate Learning Outcomes"):
        lo_input = gr.Textbox(lines=5, label="Educational Program")
        lo_output = gr.Textbox(lines=15, label="Learning Outcomes JSON")
        lo_btn = gr.Button("Generate Learning Outcomes")

        lo_btn.click(
            fn=generate_learning_outcomes,
            inputs=lo_input,
            outputs=lo_output,
            api_name="generate_learning_outcomes"


        )

    with gr.Tab("Generate Course Descriptions"):
        lo_input = gr.Textbox(lines=5, label="Educational Program")
        lo_output = gr.Textbox(lines=15, label="Course Descriptions")
        lo_btn = gr.Button("Generate Course Descriptions")

        lo_btn.click(
            fn=generate_course_description,
            inputs=lo_input,
            outputs=lo_output,
            api_name="generate_course_descriptions"


        )
    with gr.Tab("Generate Recommendations"):
        lo_input = gr.Textbox(lines=5, label="Educational Program")
        lo_output = gr.Textbox(lines=15, label="Recommendations")
        lo_btn = gr.Button("Generate Recommendations")

        lo_btn.click(
            fn=generate_recommendation,
            inputs=lo_input,
            outputs=lo_output,
            api_name="generate_recommendation"


        )
    with gr.Tab("Course ↔ Learning Outcomes"):
        input_box = gr.Textbox(lines=5, label="Educational Program")
        output_box = gr.Textbox(lines=20, label="Course Mapping JSON")
        btn = gr.Button("Generate Mapping")
    
        btn.click(
            fn=generate_course_lo_mapping,
            inputs=input_box,
            outputs=output_box,
            api_name="generate_course_lo_mapping"
        )

    with gr.Tab("Professional Standards"):
        input_box = gr.Textbox(lines=5, label="Educational Program")
        output_box = gr.Textbox(lines=20, label="Professional Standards JSON")
        btn = gr.Button("Generate Standards")
    
        btn.click(
            fn=generate_professional_standards,
            inputs=input_box,
            outputs=output_box,
            api_name="generate_professional_standards"
        )

    with gr.Tab("Emerging Professions"):
        input_box = gr.Textbox(lines=5, label="Educational Program")
        output_box = gr.Textbox(lines=20, label="Emerging Professions JSON")
        btn = gr.Button("Generate Emerging Professions")
    
        btn.click(
            fn=generate_emerging_professions,
            inputs=input_box,
            outputs=output_box,
            api_name="generate_emerging_professions"
        )

    with gr.Tab("Graduate Professions"):
        input_box = gr.Textbox(lines=5, label="Educational Program")
        output_box = gr.Textbox(lines=20, label="Professions JSON")
        btn = gr.Button("Generate Professions")
    
        btn.click(
            fn=generate_graduate_professions,
            inputs=input_box,
            outputs=output_box,
            api_name="generate_graduate_professions"
        )
demo.launch()