import gradio as gr from transformers import BartTokenizer, BartForConditionalGeneration model_name = "chikki2004/bart-mcq-generator" tokenizer = BartTokenizer.from_pretrained(model_name) model = BartForConditionalGeneration.from_pretrained(model_name) def generate_mcq(input_text, num_questions): prompt = f"Topic: Unknown. Content: {input_text} Generate {num_questions} MCQs." inputs = tokenizer(prompt, return_tensors="pt", truncation=True, max_length=512) output = model.generate(**inputs, max_length=512, num_beams=4, early_stopping=True) return tokenizer.decode(output[0], skip_special_tokens=True) iface = gr.Interface( fn=generate_mcq, inputs=[ gr.Textbox(label="Topic Content / Paragraph", lines=10, placeholder="Paste educational content here..."), gr.Slider(minimum=1, maximum=5, step=1, value=2, label="Number of Questions") ], outputs="text", title="Quiz Generator", description="Paste a topic content (e.g., Photosynthesis) and select how many MCQs you want." ) iface.launch()