Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import torch
|
| 2 |
+
import gradio as gr
|
| 3 |
+
|
| 4 |
+
|
| 5 |
+
# Use a pipeline as a high-level helper
|
| 6 |
+
from transformers import pipeline
|
| 7 |
+
|
| 8 |
+
text_summary = pipline(task:"summarization", model=sshleifer/distilbart-cnn-12-6", torch_dtype=torch.bfloat16)
|
| 9 |
+
|
| 10 |
+
# Run locally
|
| 11 |
+
# model_path = ("../Models/models--sshleifer--distilbart-cnn-12-6/snapshots/"
|
| 12 |
+
# "a4f8f3ea906ed274767e9906dbaede7531d660ff")
|
| 13 |
+
# text_summary = pipeline("summarization", model=model_path,
|
| 14 |
+
# torch_dtype=torch.bfloat16)
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
text="""
|
| 18 |
+
In probability theory and statistics, Bayes' theorem (alternatively Bayes'
|
| 19 |
+
law or Bayes' rule), named after Thomas Bayes, describes the probability of
|
| 20 |
+
an event, based on prior knowledge of conditions that might be related to
|
| 21 |
+
the event.[1] For example, if the risk of developing health problems is
|
| 22 |
+
known to increase with age, Bayes' theorem allows the risk to an individual
|
| 23 |
+
of a known age to be assessed more accurately by conditioning it relative
|
| 24 |
+
to their age, rather than assuming that the individual is typical of the
|
| 25 |
+
population as a whole.
|
| 26 |
+
|
| 27 |
+
One of the many applications of Bayes' theorem is Bayesian inference,
|
| 28 |
+
a particular approach to statistical inference. When applied, the
|
| 29 |
+
probabilities involved in the theorem may have different probability
|
| 30 |
+
interpretations. With Bayesian probability interpretation, the theorem
|
| 31 |
+
expresses how a degree of belief, expressed as a probability, should
|
| 32 |
+
rationally change to account for the availability of related evidence.
|
| 33 |
+
Bayesian inference is fundamental to Bayesian statistics. It has been
|
| 34 |
+
considered to be "to the theory of probability what Pythagoras's theorem
|
| 35 |
+
is to geometry."[2]
|
| 36 |
+
|
| 37 |
+
Based on Bayes law both the prevalence of a disease in a given population
|
| 38 |
+
and the error rate of an infectious disease test have to be taken into account
|
| 39 |
+
to evaluate the meaning of a positive test result correctly and avoid the
|
| 40 |
+
base-rate fallacy.
|
| 41 |
+
"""
|
| 42 |
+
|
| 43 |
+
# returns a list
|
| 44 |
+
# print(text_summary(text))
|
| 45 |
+
|
| 46 |
+
def summary(input):
|
| 47 |
+
output = text_summary(input)
|
| 48 |
+
return output[0]['summary_text']
|
| 49 |
+
|
| 50 |
+
gr.close_all()
|
| 51 |
+
|
| 52 |
+
# demo = gr.Interface(fn=summary, inputs="text", outputs="text")
|
| 53 |
+
demo = gr.Interface(fn=summary,
|
| 54 |
+
inputs=[gr.Textbox(label="Input text to summarize",
|
| 55 |
+
lines=6)],
|
| 56 |
+
outputs=[gr.Textbox(label="Summarized text",
|
| 57 |
+
lines=4)],
|
| 58 |
+
title="@KitwanaAkil Project 1: Text Summarizer",
|
| 59 |
+
description="This application will be used to summarize text.")
|
| 60 |
+
demo.launch()
|