Spaces:
Sleeping
Sleeping
| import gradio as gr | |
| from transformers import pipeline | |
| # Načtení textového generátoru | |
| generator = pipeline("text-generation", model="utter-project/EuroLLM-1.7B") | |
| def generate_quiz(subject, num_questions, difficulty): | |
| print(" ******* ") | |
| print("button clicked") | |
| questions = [] | |
| for _ in range(int(num_questions)): # Cyklus pro generování specifikovaného počtu otázek | |
| print("generate question") | |
| prompt = f"Generuj otázku na téma: '{subject}'. Vytvoř jednoduchou otázku k danému tématu. " | |
| generated = generator(prompt, max_length=50, num_return_sequences=1) | |
| questions.append(generated[0]['generated_text']) | |
| print("generate question - done") | |
| return questions | |
| def evaluate_quiz(answers): | |
| # Zjednodušené hodnocení odpovědí | |
| correct_answers_count = sum([1 for answer in answers if answer.strip()]) | |
| return f"Vyhodnocení: Správně zodpovězeno {correct_answers_count} z {len(answers)} otázek." | |
| # Definování Gradio komponentů | |
| with gr.Blocks() as demo: | |
| with gr.Row(): | |
| input_subject = gr.Textbox(label="Obor", placeholder="Např. matematika") | |
| input_num_questions = gr.Number(label="Počet otázek", value=5) | |
| input_difficulty = gr.Dropdown(choices=["lehka", "stredni", "tezka"], label="Obtížnost") | |
| questions_output = gr.Textbox(lines=10) | |
| generate_btn = gr.Button("Generovat otázky") | |
| generate_btn.click(fn=generate_quiz, | |
| inputs=[input_subject, input_num_questions, input_difficulty], | |
| outputs=questions_output) | |
| with gr.Column(): | |
| answer_inputs = [gr.Textbox(label=f"Odpověď na otázku {i+1}") for i in range(5)] | |
| evaluate_btn = gr.Button("Vyhodnotit odpovědi") | |
| evaluation_output = gr.Textbox(label="Výsledek") | |
| evaluate_btn.click(fn=evaluate_quiz, inputs=answer_inputs, outputs=evaluation_output) | |
| print(" ******* ") | |
| print("start") | |
| print(" ******* ") | |
| demo.launch() |