Commit
·
c082346
1
Parent(s):
3e4d670
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,29 +1,49 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
|
| 4 |
st.set_page_config(layout='wide')
|
| 5 |
-
st.title("Text
|
| 6 |
st.subheader('Input text below to be summarised', divider='rainbow')
|
|
|
|
|
|
|
| 7 |
# Create a text input widget
|
| 8 |
text_input = st.text_area(label="Input Text", height=200)
|
| 9 |
generated_summary = ""
|
| 10 |
# Define a function to generate the summary
|
| 11 |
def generate_summary(text):
|
| 12 |
-
|
| 13 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
|
| 15 |
|
| 16 |
# Return the generated summary
|
| 17 |
-
return
|
| 18 |
|
| 19 |
# Add a button to trigger the generation of the summary
|
| 20 |
generate_button = st.button(label="Generate Summary")
|
| 21 |
if generate_button:
|
| 22 |
# Call the generate_summary function when the button is clicked
|
| 23 |
generated_summary = generate_summary(text_input)
|
| 24 |
-
st.success("Summary Generated!")
|
| 25 |
|
| 26 |
|
| 27 |
# Display the generated summary
|
| 28 |
st.markdown("## Summary")
|
| 29 |
-
st.
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
+
import json
|
| 3 |
+
import requests
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
headers = {"Authorization": f"Bearer {API_TOKEN}"}
|
| 8 |
+
API_URL = "https://api-inference.huggingface.co/models/sabre-code/pegasus-large-cnn-dailymail"
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
def query(payload):
|
| 12 |
+
data = json.dumps(payload)
|
| 13 |
+
response = requests.request("POST", API_URL, headers=headers, data=data)
|
| 14 |
+
return json.loads(response.content.decode("utf-8"))
|
| 15 |
+
|
| 16 |
+
|
| 17 |
|
| 18 |
st.set_page_config(layout='wide')
|
| 19 |
+
st.title("Text Summarisation App PEGASUS-large")
|
| 20 |
st.subheader('Input text below to be summarised', divider='rainbow')
|
| 21 |
+
|
| 22 |
+
|
| 23 |
# Create a text input widget
|
| 24 |
text_input = st.text_area(label="Input Text", height=200)
|
| 25 |
generated_summary = ""
|
| 26 |
# Define a function to generate the summary
|
| 27 |
def generate_summary(text):
|
| 28 |
+
def query(payload):
|
| 29 |
+
data = json.dumps(payload)
|
| 30 |
+
response = requests.request("POST", API_URL, headers=headers, data=data)
|
| 31 |
+
return json.loads(response.content.decode("utf-8"))
|
| 32 |
+
|
| 33 |
+
data = query({"inputs": text})
|
| 34 |
|
| 35 |
|
| 36 |
# Return the generated summary
|
| 37 |
+
return data
|
| 38 |
|
| 39 |
# Add a button to trigger the generation of the summary
|
| 40 |
generate_button = st.button(label="Generate Summary")
|
| 41 |
if generate_button:
|
| 42 |
# Call the generate_summary function when the button is clicked
|
| 43 |
generated_summary = generate_summary(text_input)
|
| 44 |
+
#st.success("Summary Generated!")
|
| 45 |
|
| 46 |
|
| 47 |
# Display the generated summary
|
| 48 |
st.markdown("## Summary")
|
| 49 |
+
st.success(generated_summary)
|