import gradio as gr from transformers import pipeline # Load FLAN-T5 XL model generator = pipeline("text2text-generation", model="google/flan-t5-xl") def generate_questions(prompt): input_text = ( f"You are a survey expert. Generate a numbered list of exactly 10 clear and concise survey questions " f"based on the following prompt:\n\n\"{prompt}\"" ) result = generator(input_text, max_length=512, num_return_sequences=1)[0]['generated_text'] lines = [line.strip() for line in result.split('\n') if line.strip()] questions = [] for line in lines: if line[0].isdigit() and '.' in line: parts = line.split('.', 1) if len(parts) == 2: questions.append(parts[1].strip()) elif len(questions) < 10: questions.append(line) if len(questions) == 10: break return questions + [""] * (10 - len(questions)) with gr.Blocks() as demo: gr.Markdown("## 🧠 Smart Survey Question Generator (FLAN-T5-XL)") prompt = gr.Textbox(label="Enter your custom prompt") generate = gr.Button("Generate 10 Questions") qboxes = [gr.Textbox(label=f"Q{i+1}", interactive=False) for i in range(10)] generate.click(fn=generate_questions, inputs=prompt, outputs=qboxes) demo.launch()