|
import gradio as gr |
|
import aiohttp |
|
import asyncio |
|
import os |
|
|
|
|
|
API_URL = "https://api-inference.huggingface.co/models/Rahmat82/fastSUMMARIZER-t5-small-finetuned" |
|
SECRET_KEY = os.environ.get("summarizer") |
|
|
|
async def summarize(text): |
|
headers = {"Authorization": f"Bearer {SECRET_KEY}"} |
|
data = {"inputs": text, |
|
"options": { |
|
"max_new_tokens": 50, |
|
"min_length": 20, |
|
"max_length": 300, |
|
"length_penalty": 2.0, |
|
"num_beams": 3, |
|
"early_stopping": True |
|
} |
|
} |
|
async with aiohttp.ClientSession() as session: |
|
async with session.post(API_URL, headers=headers, json=data) as response: |
|
response.raise_for_status() |
|
result = await response.json() |
|
return result[0]["summary_text"] |
|
|
|
iface = gr.Interface( |
|
theme=gr.themes.Soft(), |
|
fn=summarize, |
|
title="Dialogue Summarizer", |
|
description="<b> NOTE: </b> Can be slower here 🐢 </b><h3>On GPU/CPU it takes <1s 🚀</h4> <h3>Please keep in mind that the input text should be at least few sentences long 🙂</h4>" , |
|
inputs=gr.Textbox(label="Write your text here", lines=10), |
|
outputs=gr.Textbox(label="Summary"), |
|
submit_btn=gr.Button("Summarize", variant="primary"), |
|
allow_flagging='never', |
|
|
|
examples=[ |
|
[""" |
|
The koala is regarded as the epitome of cuddliness. However, animal lovers will be saddened to hear that this lovable marsupial has been moved to the endangered species list. The Australian Koala Foundation estimates there are somewhere between 43,000-100,000 koalas left in the wild. Their numbers have been dwindling rapidly due to disease, loss of habitat, bushfires, being hit by cars, and other threats. Stuart Blanch from the World Wildlife Fund in Australia said: "Koalas have gone from no listing to vulnerable to endangered within a decade. That is a shockingly fast decline." He added that koalas risk "sliding toward extinction" unless there are "stronger laws…to protect their forest homes". The koala has huge cultural significance for Australia. Wikipedia writes: "The koala is well known worldwide and is a major draw for Australian zoos and wildlife parks. It has been featured in advertisements, games, cartoons, and as soft toys. It benefited the national tourism industry by over an estimated billion Australian dollars in 1998, a figure that has since grown." Despite this, efforts to protect the koala have been failing. Australia's Environment Minister Sussan Ley said there have been "many pressures on the koala," and that it is "vulnerable to climate change and to disease". She said the 2019-2020 bushfires, which killed at least 6,400 of the animals, were "a tipping point". |
|
"""], |
|
[""" |
|
Everybody knows that eating carrots is good for our eyesight. A new study suggests that grapes are also good for our eyes. Researchers from the National University of Singapore have found that eating just a few grapes a day can improve our vision. This is especially so for people who are older. Dr Eun Kim, the lead researcher, said: "Our study is the first to show that grape consumption beneficially impacts eye health in humans, which is very exciting, especially with a growing, ageing population." Dr Kim added that, "grapes are an easily accessible fruit that studies have shown can have a beneficial impact" on our eyesight. This is good news for people who don't really like carrots. The study is published in the journal "Food & Function". Thirty-four adults took part in a series of experiments over 16 weeks. Half of the participants ate one-and-a-half cups of grapes per day; the other half ate a placebo snack. Dr Kim did not tell the participants or the researchers whether she was testing the grapes or the snack. She thought that not revealing this information would give better test results. She found that people who ate the grapes had improved muscle strength around the retina. The retina passes information about light to the brain via electrical signals. It protects the eyes from damaging blue light. A lot of blue light comes from computer and smartphone screens, and from LED lights. |
|
"""] |
|
] |
|
) |
|
|
|
iface.launch() |
|
|