File size: 1,456 Bytes
58d8dc0
c082346
 
3920a1a
ea8f97d
e0ac754
c082346
 
 
 
 
 
 
 
 
 
 
 
 
58d8dc0
3e4d670
c082346
785ddb0
c082346
 
58d8dc0
 
0934e7e
58d8dc0
 
c082346
 
 
 
 
 
58d8dc0
 
 
c082346
58d8dc0
 
 
 
 
785ddb0
c082346
785ddb0
58d8dc0
 
0934e7e
c082346
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
import streamlit as st
import json
import requests
import os

API_TOKEN = os.environ.get("API_TOKEN")



headers = {"Authorization": f"Bearer {API_TOKEN}"}
API_URL = "https://api-inference.huggingface.co/models/sabre-code/pegasus-large-cnn-dailymail"


def query(payload):
    data = json.dumps(payload)
    response = requests.request("POST", API_URL, headers=headers, data=data)
    return json.loads(response.content.decode("utf-8"))



st.set_page_config(layout='wide')
st.title("Text Summarisation App PEGASUS-large")
st.subheader('Input text below to be summarised', divider='rainbow')


# Create a text input widget
text_input = st.text_area(label="Input Text", height=200)
generated_summary = ""
# Define a function to generate the summary
def generate_summary(text):
    def query(payload):
        data = json.dumps(payload)
        response = requests.request("POST", API_URL, headers=headers, data=data)
        return json.loads(response.content.decode("utf-8"))
    
    data = query({"inputs": text})
    
    
    # Return the generated summary
    return data

# Add a button to trigger the generation of the summary
generate_button = st.button(label="Generate Summary")
if generate_button:
    # Call the generate_summary function when the button is clicked
    generated_summary = generate_summary(text_input)
    #st.success("Summary Generated!")


# Display the generated summary
st.markdown("## Summary")
st.success(generated_summary)