Spaces:
Sleeping
Sleeping
| import openai | |
| import random | |
| import gradio as gr | |
| import os | |
| openai.api_key = os.environ["OpenAPI_Key"] | |
| manual = r"""Vul beide velden in door titel en course tree te kopiëren vanuit de Factsheet in MES Editor, en druk op Submit.""" | |
| # Define the system message | |
| SystemPrompt_10 = r"""You're a factsheets creator: creating factsheets for our e-learning modules that comply precisely with the requirements. The user will send as input: | |
| 1. Title of e-learning | |
| 2. Course structure | |
| You will convert this info into a factsheet, with the following components: | |
| -Description: | |
| [Catchy text with a short explanation what the module is about(75 - 100 words, a few sentences), in Dutch.Use language like: 'In deze module bespreken we ...'.] | |
| -Competencies: | |
| f.Competences: Select the competences, related to this course from the list below and should not exceed 3: | |
| 1.Vakinhoudelijk / Klinisch handelen | |
| 2. Communicatie | |
| 3. Samenwerking | |
| 4. Organisatie | |
| 5. Maatschappelijk handelen | |
| 6. Kennis en wetenschap | |
| 7. Professionaliteit | |
| Please add the respective percentage for each competence. Use % that are only multiples of 10, e.g. 10%, 20% and so on, and not 15%, 25% and so on. Naturally, the sum of all should be 100%. | |
| Just give your best estimate. | |
| - Target group(s) | |
| [pick one from: Onderwijsassistent / Persoonlijk Begeleider MZ / Gespecialiseerd pedagogisch medewerker. If none of those qualify, make up your own.]""" | |
| UserPrompt_10 = r"""""" | |
| AssistantPrompt_10 = r"""""" | |
| UserPrompt_11 = r"""""" | |
| AssistantPrompt_11 = r"""""" | |
| # Function to make API call | |
| def api_call(messages, temperature=0.5, model="gpt-4"): | |
| return openai.ChatCompletion.create( | |
| messages=messages, | |
| temperature=temperature, | |
| model=model | |
| ).choices[0].message.content | |
| # Function to be called by Gradio interface | |
| def process_inputs(Name, Tree): | |
| # Check if either field is empty | |
| if not Name: | |
| return manual | |
| if not Tree: | |
| return manual | |
| else: | |
| # Step 1: User input and first API call | |
| stepOne = [ | |
| {"role": "system", "content": SystemPrompt_10}, | |
| {"role": "user", "content": f"Title of e-learning: {Name}\n\nCourse structure:\n{Tree}"} | |
| ] | |
| Script_1 = api_call(stepOne, 0.7) | |
| return Script_1 | |
| # Create the Gradio interface | |
| iface = gr.Interface( | |
| fn=process_inputs, | |
| inputs=[ | |
| gr.Textbox(lines=2, label='Name of e-learning'), | |
| gr.Textbox(lines=2, label='Course Structure') | |
| ], | |
| outputs=gr.Textbox(label="Suggested Factsheet info (double-check & revise)", show_copy_button=True) | |
| ) | |
| iface.launch(share=True) | |
| iface.launch() |