import gradio as gr from transformers import T5ForConditionalGeneration, T5Tokenizer # Load the T5 model and tokenizer for question generation model_name = "valhalla/t5-small-qg-prepend" tokenizer = T5Tokenizer.from_pretrained(model_name) model = T5ForConditionalGeneration.from_pretrained(model_name) def generate_questions(email_text): # Prepend "generate questions: " to the input text input_text = "generate questions: " + email_text input_ids = tokenizer.encode(input_text, return_tensors="pt") # Generate questions outputs = model.generate( input_ids=input_ids, max_length=512, num_beams=4, early_stopping=True ) # Decode the generated text questions = tokenizer.decode(outputs[0], skip_special_tokens=True) return questions # Create a Gradio interface iface = gr.Interface( fn=generate_questions, inputs="textbox", outputs="textbox", title="Email Question Generator", description="Input an email, and the AI will generate the biggest questions that probably need to be answered.", ) # Launch the interface iface.launch()