File size: 2,804 Bytes
de8638e
 
 
 
7d6861b
de8638e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7d6861b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
de8638e
 
 
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
import gradio as gr
import requests

# API endpoint
API_URL = "https://api-inference.huggingface.co/models/Rahmat82/8bit-fastSUMMARIZER-t5-small-finetuned-on-xsum"
import os
SECRET_KEY = os.environ.get("summarizer")

def summarize(text):
    headers = {"Authorization": f"Bearer {SECRET_KEY}"}
    data = {"inputs": text}
    response = requests.post(API_URL, headers=headers, json=data)

    if response.status_code == 200:
        return response.json()[0]["generated_text"]
    else:
        return "Error occurred. Please try again."

iface = gr.Interface(
    theme=gr.themes.Soft(),
    fn=summarize,
    title="Dialogue Summarizer",
    description="<b> NOTE: </b> Can be a bit slower here 🐢 <h3>On GPU it is much faster 🚀</h3>",
    inputs=gr.Textbox(label="Write your dialogue text here", lines=10),
    outputs=gr.Textbox(label="Summary"),
    submit_btn=gr.Button("Summarize", variant="primary"),
    allow_flagging='never',
    
     examples=[
        ["""
For 265 years, 104 letters written to French sailors sat on a shelf in the U.K. They were never opened. 
They have just been read for the first time. The letters were on a French warship captured by Britain in 1758. 
The French sailors did not have time to open and read their mail. The letters were put in storage in an archive and forgotten about. 
They gathered dust for two and a half centuries. A researcher said many of the letters were love letters. A group of researchers studied the letters. 
They said the writing gave a rare look back into history. The writers were rich and poor. They were fiancés, parents, siblings and wives. 
They all had different levels of literacy. A researcher said the letters showed how we manage things like pandemics and wars. 
He said the letters were similar to what people write about today. They were about staying in touch, caring for people, and keeping passion alive.
"""],
        ["""
Carrots are good for our eyes. A new study from the National University of Singapore says grapes are also good. 
It says eating a few grapes a day can help our vision. A researcher said: "Grape consumption beneficially impacts eye health in humans." 
She said this was good as more people are getting older. She added that we can easily buy grapes. This research is good news for people who don't like carrots.
Thirty-four adults took part in the testing. Half of them ate grapes every day; the other half ate a placebo snack. 
None of them knew if the tests were on the grapes or the snack. This gave better test results. The people who ate the grapes had better muscle strength around the retina. 
The retina sends information about light to the brain. It protects the eyes from blue light, which damages the eye. A lot of blue light comes from computer screens.
"""]
    ]
)

iface.launch()