Spaces:
Sleeping
Sleeping
import gradio as gr | |
import requests | |
API_KEY = "Prep@123" | |
LCG_SERVICE_URL = "http://bore.testsprep.online:8082/v1/theory_lcg" | |
weights_mapping = { | |
'beginner': { | |
'easy': 0.6, | |
'medium': 0.2, | |
'hard': 0.2 | |
}, | |
'intermediate': { | |
'easy': 0.2, | |
'medium': 0.6, | |
'hard': 0.2 | |
}, | |
'advanced': { | |
'easy': 0.2, | |
'medium': 0.2, | |
'hard': 0.6 | |
} | |
} | |
template_los = """0. Identify the challenges in Matching sentence endings: More endings than questions, Some endings may be grammatically correct but not connected to the main ideas in the text, Information for possible endings is placed randomly in the passage | |
1. Understand and apply the steps for answering Matching sentence endings questions effectively: Read and underline keywords in incomplete sentences and endings, Scan using keywords in incomplete sentences to locate the information area, and Match incomplete sentences with endings and compare to the information area""" | |
def get_response_message(config): | |
headers = { | |
'accept': 'application/json', | |
'Authorization': f'Bearer {API_KEY}', | |
'Content-Type': 'application/json' | |
} | |
data = { | |
"model": "lcg_sft", | |
"input_data": { | |
"user_level": config["user_level"], | |
"num_questions": config["num_questions"], | |
"question_type": config["question_type"], | |
"language": config["language"], | |
"explanation_language": config["explanation_language"], | |
"context": config["context"], | |
"learning_outcomes": [lo.strip() for lo in config['learning_outcomes'].split('\n')], | |
"mode": config["mode"], | |
"weights": { | |
"easy": 0, | |
"hard": 0, | |
"medium": 0 | |
} | |
}, | |
"do_sample": True, | |
"temperature": 0.7, | |
"top_p": 0.9, | |
"n": 1, | |
"max_tokens": 4096, | |
"stop": "string", | |
"stream": False | |
} | |
response = requests.post(LCG_SERVICE_URL, headers=headers, json=data) | |
return response.json()["data"] | |
def generate_questions(user_level, num_questions, question_type, language, explanation_language, context, learning_outcomes, mode): | |
config = { | |
"user_level": user_level, | |
"num_questions": int(num_questions), | |
"question_type": question_type, | |
"language": language, | |
"explanation_language": explanation_language, | |
"context": context, | |
"learning_outcomes": learning_outcomes, | |
"mode": mode | |
} | |
return get_response_message(config) | |
iface = gr.Interface( | |
fn=generate_questions, | |
inputs=[ | |
gr.Dropdown(["beginner", "intermediate", "advanced"], label="User Level"), | |
gr.Number(value=5, label="Number of Questions"), | |
gr.Dropdown(["Short answer", "Single choice", "Multiple choice"], label="Question Type"), | |
gr.Dropdown(["English", "Vietnamese"], label="Language"), | |
gr.Dropdown(["English", "Vietnamese"], label="Explanation Language"), | |
gr.Textbox(lines=5, placeholder="Enter context here...", label="Context"), | |
gr.Textbox(lines=5, default=template_los, label="Learning Outcomes"), | |
gr.Dropdown(["Reviewing", "Practicing"], label="Mode") | |
], | |
outputs=gr.JSON(label="Generated Questions"), | |
title="Learning Content Generation", | |
description="Generate questions based on user input and learning outcomes." | |
) | |
iface.launch() | |