Spaces:
Runtime error
Runtime error
summarize article
Browse files- app.py +43 -0
- requirements.txt +2 -0
- tensora_logo.png +0 -0
app.py
CHANGED
|
@@ -0,0 +1,43 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
from dotenv import load_dotenv
|
| 3 |
+
import requests
|
| 4 |
+
import os
|
| 5 |
+
from st_copy_to_clipboard import st_copy_to_clipboard
|
| 6 |
+
import pyperclip
|
| 7 |
+
|
| 8 |
+
load_dotenv()
|
| 9 |
+
|
| 10 |
+
def summarize(article):
|
| 11 |
+
headers = {'Content-Type':'application/json', 'Authorization':('Bearer '+ os.getenv("API_KEY")), 'azureml-model-deployment': 'heute-summary-api' }
|
| 12 |
+
data = {'article': article}
|
| 13 |
+
try:
|
| 14 |
+
with st.spinner("Summarizing the article..."):
|
| 15 |
+
response = requests.post(os.getenv("API_URL"), headers=headers, json=data)
|
| 16 |
+
article_summary = response.json()
|
| 17 |
+
return article_summary["summary"]
|
| 18 |
+
except Exception as e:
|
| 19 |
+
print(e)
|
| 20 |
+
st.error("An error occurred while trying to summarize the article. Please try again later.", icon="🚨")
|
| 21 |
+
return ""
|
| 22 |
+
|
| 23 |
+
def summary_btn_handler():
|
| 24 |
+
summary = summarize(st.session_state["article"])
|
| 25 |
+
st.session_state["summary"] = summary
|
| 26 |
+
|
| 27 |
+
if "summary" not in st.session_state:
|
| 28 |
+
st.session_state["summary"] = ""
|
| 29 |
+
|
| 30 |
+
col1, col2 = st.columns([2, 1])
|
| 31 |
+
|
| 32 |
+
col1.title("AI - Summarizer")
|
| 33 |
+
col2.image("tensora_logo.png")
|
| 34 |
+
|
| 35 |
+
st.text_area("Enter your article to summarize", height=200, key="article")
|
| 36 |
+
st.button("Summarize", key="summarize_btn", on_click=summary_btn_handler, disabled=not st.session_state["article"])
|
| 37 |
+
st.write(st.session_state["summary"])
|
| 38 |
+
if len(st.session_state["summary"]) > 0:
|
| 39 |
+
copy_col1, copy_col2 = st.columns([2, 1])
|
| 40 |
+
if copy_col1.button("Copy to clipboard", key="copy_btn"):
|
| 41 |
+
pyperclip.copy(st.session_state["summary"])
|
| 42 |
+
with copy_col2:
|
| 43 |
+
st.success('Text copied successfully!')
|
requirements.txt
CHANGED
|
@@ -1 +1,3 @@
|
|
| 1 |
streamlit
|
|
|
|
|
|
|
|
|
| 1 |
streamlit
|
| 2 |
+
python-dotenv
|
| 3 |
+
pyperclip
|
tensora_logo.png
ADDED
|