|
import gradio as gr |
|
from transformers import T5ForConditionalGeneration, T5Tokenizer |
|
|
|
|
|
model_name = "valhalla/t5-small-qg-prepend" |
|
tokenizer = T5Tokenizer.from_pretrained(model_name) |
|
model = T5ForConditionalGeneration.from_pretrained(model_name) |
|
|
|
def generate_questions(email_text): |
|
|
|
input_text = "generate questions: " + email_text |
|
input_ids = tokenizer.encode(input_text, return_tensors="pt") |
|
|
|
|
|
outputs = model.generate( |
|
input_ids=input_ids, |
|
max_length=512, |
|
num_beams=4, |
|
early_stopping=True |
|
) |
|
|
|
|
|
questions = tokenizer.decode(outputs[0], skip_special_tokens=True) |
|
return questions |
|
|
|
|
|
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.", |
|
) |
|
|
|
|
|
iface.launch() |
|
|