|
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 = "/static-proxy?url=https%3A%2F%2Fapi-inference.huggingface.co%2Fmodels%2Fsabre-code%2Fpegasus-large-cnn-dailymail%26quot%3B%3C%2Fspan%3E%3C!-- HTML_TAG_END --> |
|
|
|
|
|
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') |
|
|
|
|
|
|
|
text_input = st.text_area(label="Input Text", height=200) |
|
generated_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 data |
|
|
|
|
|
generate_button = st.button(label="Generate Summary") |
|
if generate_button: |
|
|
|
generated_summary = generate_summary(text_input) |
|
|
|
|
|
|
|
|
|
st.markdown("## Summary") |
|
st.success(generated_summary) |