Spaces:
Runtime error
Runtime error
File size: 1,819 Bytes
8e0affa 5748770 0da2675 20b6df0 0da2675 20b6df0 0da2675 20b6df0 8916695 0da2675 20b6df0 8916695 0da2675 fb4f8c6 8e0affa 20b6df0 8e0affa 64f001b 8e0affa 5748770 20b6df0 fb4f8c6 36c9b26 5748770 0b1a1c5 0da2675 8497bb0 d662828 bd62b5b 20b6df0 36c9b26 bd62b5b 20b6df0 |
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 |
import gradio as gr
import wikipedia
from transformers import pipeline
import os
# Setting to use the 0th GPU
os.environ["CUDA_VISIBLE_DEVICES"] = "0"
def summarize(text):
# Setting to use the bart-large-cnn model for summarization
summarizer = pipeline("summarization")
# To use the t5-base model for summarization:
# summarizer = pipeline("summarization", model="t5-base", tokenizer="t5-base", framework="tf")
summary_text = summarizer(text, max_length=100, min_length=5, do_sample=False)[0]['summary_text']
print(f'Length of initial text: {len(text)}')
print(f'Length of summary: {len(summary_text)}')
print(summary_text)
return summary_text
def greet(name):
return "Hello " + name.orig_name + "!"
def get_ocr():
return ''
def search_wiki(text):
return wikipedia.search(text)
def get_wiki(search_term):
# text = wikipedia.summary(search_term)
orig_text_len = len(search_term)
text = summarize(search_term)
sum_length = len(text)
return [text, orig_text_len, sum_length]
# def inference(file):
# get_ocr()
# model = AutoModelForSeq2SeqLM.from_pretrained("sgugger/my-awesome-model")
out_sum_text = gr.Textbox(label='Summarized Text', lines=15)
out_orig_test_len = gr.Number(label='Original Text Length')
out_sum_text_len = gr.Number(label='Summarized Text Length')
iface = gr.Interface(fn=get_wiki,
inputs=gr.Textbox(lines=50, placeholder="Paste article here....", label='Article to Summarize'),
outputs=[out_sum_text, out_orig_test_len, out_sum_text_len],
title='Article Summary',
description='Paste in an article and it will be summarized.'
)
iface.launch() # To create a public link, set `share=True` in `launch()`.
|