funnyPhani
commited on
Commit
•
827697f
1
Parent(s):
743bee3
Update app.py
Browse files
app.py
CHANGED
@@ -1,7 +1,60 @@
|
|
1 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2 |
|
3 |
-
|
4 |
-
|
5 |
|
6 |
-
|
7 |
-
|
|
|
|
|
|
|
|
|
|
1 |
+
def data_summarizer(input_eng):
|
2 |
+
try:
|
3 |
+
import requests
|
4 |
+
from bs4 import BeautifulSoup
|
5 |
+
from googletrans import Translator
|
6 |
+
import warnings
|
7 |
+
from transformers import pipeline
|
8 |
+
# sentiment = pipeline("sentiment-analysis")
|
9 |
+
from transformers import PegasusForConditionalGeneration, AutoTokenizer
|
10 |
+
tokenizer = AutoTokenizer.from_pretrained("google/pegasus-xsum")
|
11 |
+
warnings.filterwarnings("ignore")
|
12 |
+
# from gensim.summarization.summarizer import summarize
|
13 |
+
from gensim.summarization import keywords
|
14 |
+
from textblob import TextBlob
|
15 |
+
translator = Translator()
|
16 |
+
# from transformers import pipeline
|
17 |
+
# summarizer = pipeline("summarization")
|
18 |
+
from transformers import PegasusForConditionalGeneration, PegasusTokenizer
|
19 |
+
from transformers import PegasusForConditionalGeneration, AutoTokenizer
|
20 |
+
tokenizer = AutoTokenizer.from_pretrained("google/pegasus-xsum")
|
21 |
+
# tokenizer = PegasusTokenizer.from_pretrained("google/pegasus-xsum")
|
22 |
+
model = PegasusForConditionalGeneration.from_pretrained("google/pegasus-xsum")
|
23 |
+
translation=translator.translate(input_eng, dest = "en")
|
24 |
+
tokens = tokenizer(translation.text, truncation=True, padding="longest", return_tensors="pt")
|
25 |
+
# Summarize
|
26 |
+
summary = model.generate(**tokens)
|
27 |
+
# Decode summary
|
28 |
+
text = tokenizer.decode(summary[0]).replace("<pad> ","").replace("</s>","")
|
29 |
+
# summary = summarizer(translation.text)
|
30 |
+
# print(summary[0]['summary_text'])
|
31 |
+
translator = Translator()
|
32 |
+
# text = summary[0]['summary_text']
|
33 |
+
# print(keywords(text,words = 5,lemmatize=False))
|
34 |
+
key = keywords(text,words = 5,lemmatize=False)
|
35 |
+
# print(key)
|
36 |
+
translator = Translator()
|
37 |
+
keys = translator.translate(key, dest = translator.detect(input_eng).lang)
|
38 |
+
# print("keywords".center(50,"-"))
|
39 |
+
# print(keys.text,end = " ")
|
40 |
+
translator = Translator()
|
41 |
+
out = translator.translate(text, dest = translator.detect(input_eng).lang)
|
42 |
+
# senti = sentiment(text)[0]['label']
|
43 |
+
analysis=TextBlob(text)
|
44 |
+
#print(analysis.polarity)
|
45 |
+
# print(analysis.sentiment)
|
46 |
+
# print(f"Sentiment: {'Positive' if analysis.polarity > 0 else 'Negative' if analysis.polarity < 0 else 'Neutral' }")
|
47 |
+
# return {"Output_summary :":out.text,"Keywords":keys.text.replace("\n",","),"Sentiment":f"{'Positive' if analysis.polarity > 0 else 'Negative' if analysis.polarity < 0 else 'Neutral' }"}
|
48 |
+
# print(translation.text)
|
49 |
+
# print(translation.extra_data)
|
50 |
+
return f"{'Positive' if analysis.polarity > 0 else 'Negative' if analysis.polarity < 0 else 'Neutral' }", keys.text.replace("\n",","), out.text.strip()
|
51 |
|
52 |
+
except Exception as e:
|
53 |
+
raise e
|
54 |
|
55 |
+
# input_eng = input()
|
56 |
+
# data_summarizer(input_eng)
|
57 |
+
import gradio as gr
|
58 |
+
interface = gr.Interface(fn=data_summarizer,
|
59 |
+
inputs=gr.inputs.Textbox(lines=20, placeholder='Past your input text...'),outputs=['text',"text","text"])
|
60 |
+
interface.launch(inline = False)
|