Spaces:
Sleeping
Sleeping
File size: 4,326 Bytes
8047655 2b78cfb 8047655 6479586 8047655 2b78cfb 8047655 2b78cfb c38947c 8047655 6479586 7992bbe 8047655 2b78cfb 8047655 6479586 b7621e0 8047655 6479586 2868373 8047655 |
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 |
import gradio as gr
import requests
API_KEY = "Prep@123"
LCG_SERVICE_URL_v1 = "http://bore.testsprep.online:8082/v1/theory_lcg"
LCG_SERVICE_URL_v2 = "http://bore.testsprep.online:8081/v1/theory_lcg"
LCG_SERVICE_URL_v3 = "http://bore.testsprep.online:8083/v1/theory_lcg"
MODEL2SERVICE = {
'llama-3.1-sft-awq': LCG_SERVICE_URL_v1,
'hermes-3-llama3.1-sft-lora': LCG_SERVICE_URL_v2,
'qwen2-1.5b-full-sft': LCG_SERVICE_URL_v3
}
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": config["model_name"],
"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
}
try:
response = requests.post(MODEL2SERVICE[config["model_name"]], headers=headers, json=data)
return response.json()["data"]
except:
return {"message": f"Hiện tại chúng tôi chưa hỗ trợ mô hình {config['model_name']}."}
def generate_questions(model_name, user_level, num_questions, question_type, language, explanation_language, context,
learning_outcomes, mode):
if mode == "Reviewing" and not context.strip():
return {"error": "Với chế độ Reviewing, Context không được để trống."}
config = {
"model_name": model_name,
"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(list(MODEL2SERVICE.keys()), label="Model Usage", value=0),
gr.Dropdown(["beginner", "intermediate", "advanced"], label="User Level", value=0),
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 (Lesson content or Reading comprehension passage)"),
gr.Textbox(lines=5, value=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()
|