Spaces:
Runtime error
Runtime error
File size: 2,471 Bytes
1e60bec 1af8a4a 1e60bec 77eab50 37210a6 8f1bc12 1e60bec 8f1bc12 1e60bec cd3b854 1e60bec fa53630 1e60bec 0a93cce d8eee50 a2f9d4f cd3b854 a2f9d4f 5e41c07 d8eee50 a2f9d4f d8eee50 be85d9b d8eee50 be85d9b acd2391 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
from heapq import nlargest
import spacy
from spacy.lang.en.stop_words import STOP_WORDS
from string import punctuation
import gradio as gr
# Stopwords
stopwords = list(STOP_WORDS)
nlp = spacy.load('en_core_web_sm')
punctuation = punctuation + '\n'
import spacy
from spacy.lang.en.stop_words import STOP_WORDS
from string import punctuation
# Prediction
def prediction(text):
doc = nlp(text)
len1 = len(text)
tokens = [token.text for token in doc]
word_frequencies = {}
for word in doc:
if word.text.lower() not in stopwords:
if word.text.lower() not in punctuation:
if word.text not in word_frequencies.keys():
word_frequencies[word.text] = 1
else:
word_frequencies[word.text] += 1
max_frequency = max(word_frequencies.values())
for word in word_frequencies.keys():
word_frequencies[word] = word_frequencies[word]/max_frequency
sentence_tokens = [sent for sent in doc.sents]
sentence_scores = {}
for sent in sentence_tokens:
for word in sent:
if word.text.lower() in word_frequencies.keys():
if sent not in sentence_scores.keys():
sentence_scores[sent] = word_frequencies[word.text.lower()]
else:
sentence_scores[sent] += word_frequencies[word.text.lower()]
select_length = int(len(sentence_tokens)*0.3)
summary = nlargest(select_length, sentence_scores, key = sentence_scores.get)
org_len = len(text.split(' '))
summary = (str(summary[0]))
sum_len = len(summary.split(' '))
return summary,org_len,sum_len
#predicted_label, score = occ_predict("img1.jpg")
#inputs = gr.inputs.text(label)
#label = gr.outputs.Label(num_top_classes=2)
#EXAMPLES = ["img1.png","img2.png","img3.png","img10.png","img8.png","img9.png"]
#DESCRIPTION = "Occlusion means the act of closing, blocking or shutting something or the state of being closed or blocked"
#summary = prediction(text)
#print(summary)
outputs = [
gr.Textbox(lines =5,label = "Summarization of text"),
gr.Number(label="Word Count of given Text"),
gr.Number(label="Word Count of Summarized Text")
]
demo_app = gr.Interface(
fn=prediction,
inputs=gr.Textbox(lines =10,label = " Enter the Text", max_lines = 20),
outputs= outputs,
title = "Text Summarization",
#description = DESCRIPTION,
#cache_example = True,
#live = True,
theme = 'huggingface'
)
#if __name__ == "__main__":
demo_app.launch()
#demo_app.launch(debug=True, enable_queue = True)
|