Spaces:
Paused
Paused
File size: 1,944 Bytes
20cde61 0c05a2a 20cde61 0c05a2a 20cde61 |
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 |
import gradio as gr
import random
from llm import get_prompt, get_responce
def generate_questions(question_type):
prompt, seed = get_prompt(question_type)
questions = get_responce(prompt)
return questions, seed
def process_question_type(question_type):
questions, seed = generate_questions(question_type)
formatted_questions = []
for question in questions:
question_text = question["question"]
options = question.get("options", {})
answer = question["answer"]
correction = question.get("correction", "")
question_display = {
"Question": question_text,
"Answer": answer,
"Correction": correction,
"Options": options if options else None,
}
formatted_questions.append(question_display)
return formatted_questions, seed
def main():
question_types = [
"Choose the correct meaning of the word",
"Personal response",
"Give reasons",
"Fill in the blanks",
"True or False",
]
# Create a Gradio interface
with gr.Blocks() as demo:
gr.Markdown("<h1>Select Question Type</h1>")
question_type = gr.Dropdown(choices=question_types, label="Question Type", value=question_types[0])
generate_button = gr.Button("Generate Questions")
output = gr.Textbox(label="Generated Questions", interactive=False)
seed_output = gr.Textbox(label="Seed Number", interactive=False)
def generate():
questions, seed = process_question_type(question_type.value)
formatted_output = "\n".join([f"{q['Question']} - Answer: {q['Answer']}, Correction: {q['Correction']}" for q in questions])
return formatted_output, seed
generate_button.click(generate, outputs=[output, seed_output])
demo.launch()
if __name__ == "__main__":
main() |