File size: 2,537 Bytes
d6146bb
 
 
 
 
 
 
576b922
231bf1e
d6146bb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import torch
import gradio as gr


# Use a pipeline as a high-level helper
from transformers import pipeline

text_summary = pipeline("summarization", model="sshleifer/distilbart-cnn-12-6", torch_dtype=torch.bfloat16)


# Run locally
# model_path = ("../Models/models--sshleifer--distilbart-cnn-12-6/snapshots/"
#               "a4f8f3ea906ed274767e9906dbaede7531d660ff")
# text_summary = pipeline("summarization", model=model_path,
#                 torch_dtype=torch.bfloat16)


text="""
In probability theory and statistics, Bayes' theorem (alternatively Bayes' 
law or Bayes' rule), named after Thomas Bayes, describes the probability of 
an event, based on prior knowledge of conditions that might be related to 
the event.[1] For example, if the risk of developing health problems is 
known to increase with age, Bayes' theorem allows the risk to an individual 
of a known age to be assessed more accurately by conditioning it relative 
to their age, rather than assuming that the individual is typical of the 
population as a whole.

One of the many applications of Bayes' theorem is Bayesian inference, 
a particular approach to statistical inference. When applied, the 
probabilities involved in the theorem may have different probability 
interpretations. With Bayesian probability interpretation, the theorem 
expresses how a degree of belief, expressed as a probability, should 
rationally change to account for the availability of related evidence. 
Bayesian inference is fundamental to Bayesian statistics. It has been 
considered to be "to the theory of probability what Pythagoras's theorem 
is to geometry."[2]

Based on Bayes law both the prevalence of a disease in a given population 
and the error rate of an infectious disease test have to be taken into account 
to evaluate the meaning of a positive test result correctly and avoid the 
base-rate fallacy.
"""

# returns a list
# print(text_summary(text))

def summary(input):
    output = text_summary(input)
    return output[0]['summary_text']

gr.close_all()

# demo = gr.Interface(fn=summary, inputs="text", outputs="text")
demo = gr.Interface(fn=summary,
                    inputs=[gr.Textbox(label="Input text to summarize",
                                       lines=6)],
                    outputs=[gr.Textbox(label="Summarized text",
                                        lines=4)],
                    title="@KitwanaAkil Project 1: Text Summarizer",
                    description="This application will be used to summarize text.")
demo.launch()