MNGames commited on
Commit
e3463bc
1 Parent(s): b14ddab

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +36 -0
app.py ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import T5ForConditionalGeneration, T5Tokenizer
3
+
4
+ # Load the T5 model and tokenizer for question generation
5
+ model_name = "valhalla/t5-small-qg-prepend"
6
+ tokenizer = T5Tokenizer.from_pretrained(model_name)
7
+ model = T5ForConditionalGeneration.from_pretrained(model_name)
8
+
9
+ def generate_questions(email_text):
10
+ # Prepend "generate questions: " to the input text
11
+ input_text = "generate questions: " + email_text
12
+ input_ids = tokenizer.encode(input_text, return_tensors="pt")
13
+
14
+ # Generate questions
15
+ outputs = model.generate(
16
+ input_ids=input_ids,
17
+ max_length=512,
18
+ num_beams=4,
19
+ early_stopping=True
20
+ )
21
+
22
+ # Decode the generated text
23
+ questions = tokenizer.decode(outputs[0], skip_special_tokens=True)
24
+ return questions
25
+
26
+ # Create a Gradio interface
27
+ iface = gr.Interface(
28
+ fn=generate_questions,
29
+ inputs="textbox",
30
+ outputs="textbox",
31
+ title="Email Question Generator",
32
+ description="Input an email, and the AI will generate the biggest questions that probably need to be answered.",
33
+ )
34
+
35
+ # Launch the interface
36
+ iface.launch()