Update app.py
Browse files
app.py
CHANGED
@@ -1,27 +1,23 @@
|
|
1 |
-
import re
|
2 |
import gradio as gr
|
3 |
from transformers import pipeline, BartTokenizer, BartForConditionalGeneration
|
4 |
|
5 |
-
# Load the BART model and tokenizer for text generation
|
6 |
-
model_name = "facebook/bart-
|
7 |
tokenizer = BartTokenizer.from_pretrained(model_name)
|
8 |
model = BartForConditionalGeneration.from_pretrained(model_name)
|
9 |
|
10 |
-
# Question detection function
|
11 |
def detect_questions(email_text):
|
12 |
-
#
|
13 |
-
questions =
|
14 |
return questions
|
15 |
|
16 |
-
# Generate answers using the BART model
|
17 |
def generate_answers(question):
|
18 |
-
#
|
19 |
inputs = tokenizer(question, return_tensors="pt", max_length=1024, truncation=True)
|
20 |
summary_ids = model.generate(inputs["input_ids"], num_beams=4, max_length=50, early_stopping=True)
|
21 |
answer = tokenizer.decode(summary_ids[0], skip_special_tokens=True)
|
22 |
return answer
|
23 |
|
24 |
-
# Main function to handle the email input
|
25 |
def process_email(email_text):
|
26 |
questions = detect_questions(email_text)
|
27 |
responses = {}
|
@@ -32,14 +28,12 @@ def process_email(email_text):
|
|
32 |
|
33 |
return responses
|
34 |
|
35 |
-
# Create a Gradio interface
|
36 |
iface = gr.Interface(
|
37 |
fn=process_email,
|
38 |
inputs="textbox",
|
39 |
-
outputs="
|
40 |
-
title="Email Question
|
41 |
-
description="Input an email, and the AI will detect questions and provide
|
42 |
)
|
43 |
|
44 |
-
# Launch the interface
|
45 |
iface.launch()
|
|
|
|
|
1 |
import gradio as gr
|
2 |
from transformers import pipeline, BartTokenizer, BartForConditionalGeneration
|
3 |
|
4 |
+
# Load the BART model and tokenizer for text generation
|
5 |
+
model_name = "facebook/bart-small"
|
6 |
tokenizer = BartTokenizer.from_pretrained(model_name)
|
7 |
model = BartForConditionalGeneration.from_pretrained(model_name)
|
8 |
|
|
|
9 |
def detect_questions(email_text):
|
10 |
+
# Simple heuristic to detect questions
|
11 |
+
questions = [sentence.strip() + "?" for sentence in email_text.split(".") if "?" in sentence]
|
12 |
return questions
|
13 |
|
|
|
14 |
def generate_answers(question):
|
15 |
+
# Generate an answer for the given question using the BART model
|
16 |
inputs = tokenizer(question, return_tensors="pt", max_length=1024, truncation=True)
|
17 |
summary_ids = model.generate(inputs["input_ids"], num_beams=4, max_length=50, early_stopping=True)
|
18 |
answer = tokenizer.decode(summary_ids[0], skip_special_tokens=True)
|
19 |
return answer
|
20 |
|
|
|
21 |
def process_email(email_text):
|
22 |
questions = detect_questions(email_text)
|
23 |
responses = {}
|
|
|
28 |
|
29 |
return responses
|
30 |
|
|
|
31 |
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 answers.",
|
37 |
)
|
38 |
|
|
|
39 |
iface.launch()
|