Update app.py
Browse files
app.py
CHANGED
@@ -7,24 +7,28 @@ tokenizer = BartTokenizer.from_pretrained(model_name)
|
|
7 |
model = BartForConditionalGeneration.from_pretrained(model_name)
|
8 |
|
9 |
def detect_questions(email_text):
|
10 |
-
#
|
11 |
-
|
12 |
-
|
|
|
|
|
13 |
|
14 |
-
def
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
|
|
|
|
|
|
20 |
|
21 |
def process_email(email_text):
|
|
|
22 |
questions = detect_questions(email_text)
|
23 |
-
responses = {}
|
24 |
|
25 |
-
|
26 |
-
|
27 |
-
responses[question] = response
|
28 |
|
29 |
return responses
|
30 |
|
@@ -32,8 +36,8 @@ iface = gr.Interface(
|
|
32 |
fn=process_email,
|
33 |
inputs="textbox",
|
34 |
outputs="text",
|
35 |
-
title="Email Question Responder",
|
36 |
-
description="Input an email, and the AI will detect questions and provide possible
|
37 |
)
|
38 |
|
39 |
iface.launch()
|
|
|
7 |
model = BartForConditionalGeneration.from_pretrained(model_name)
|
8 |
|
9 |
def detect_questions(email_text):
|
10 |
+
# Use the BART model to generate questions from the email text
|
11 |
+
inputs = tokenizer("generate questions: " + email_text, return_tensors="pt", max_length=1024, truncation=True)
|
12 |
+
questions = model.generate(inputs["input_ids"], num_beams=4, max_length=50, early_stopping=True)
|
13 |
+
questions = tokenizer.decode(questions[0], skip_special_tokens=True)
|
14 |
+
return questions.split("##")
|
15 |
|
16 |
+
def generate_responses(questions):
|
17 |
+
responses = {}
|
18 |
+
for question in questions:
|
19 |
+
# Generate a response for each question using the BART model
|
20 |
+
inputs = tokenizer(question, return_tensors="pt", max_length=1024, truncation=True)
|
21 |
+
response = model.generate(inputs["input_ids"], num_beams=4, max_length=200, early_stopping=True)
|
22 |
+
response = tokenizer.decode(response[0], skip_special_tokens=True)
|
23 |
+
responses[question] = response
|
24 |
+
return responses
|
25 |
|
26 |
def process_email(email_text):
|
27 |
+
# Detect questions from the email
|
28 |
questions = detect_questions(email_text)
|
|
|
29 |
|
30 |
+
# Generate responses to the detected questions
|
31 |
+
responses = generate_responses(questions)
|
|
|
32 |
|
33 |
return responses
|
34 |
|
|
|
36 |
fn=process_email,
|
37 |
inputs="textbox",
|
38 |
outputs="text",
|
39 |
+
title="Email Question Detector and Responder",
|
40 |
+
description="Input an email, and the AI will detect questions and provide possible responses.",
|
41 |
)
|
42 |
|
43 |
iface.launch()
|