File size: 1,122 Bytes
e3463bc |
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 |
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()
|