Spaces:
Runtime error
Runtime error
import streamlit as st | |
from dotenv import load_dotenv | |
import requests | |
import os | |
import pyperclip | |
load_dotenv() | |
def summarize(article): | |
headers = {'Content-Type':'application/json', 'Authorization':('Bearer '+ os.getenv("API_KEY")), 'azureml-model-deployment': 'heute-summary-api' } | |
data = {'article': article} | |
try: | |
with st.spinner("Summarizing the article..."): | |
response = requests.post(os.getenv("API_URL"), headers=headers, json=data) | |
article_summary = response.json() | |
return article_summary["summary"] | |
except Exception as e: | |
print(e) | |
st.error("An error occurred while trying to summarize the article. Please try again later.", icon="π¨") | |
return "" | |
def summary_btn_handler(): | |
summary = summarize(st.session_state["article"]) | |
st.session_state["summary"] = summary | |
if "summary" not in st.session_state: | |
st.session_state["summary"] = "" | |
col1, col2 = st.columns([2, 1]) | |
col1.title("AI - Summarizer") | |
col2.image("tensora_logo.png") | |
st.text_area("Enter your article to summarize", height=200, key="article") | |
st.button("Summarize", key="summarize_btn", on_click=summary_btn_handler, disabled=not st.session_state["article"]) | |
st.write(st.session_state["summary"]) | |
if len(st.session_state["summary"]) > 0: | |
copy_col1, copy_col2 = st.columns([2, 1]) | |
if copy_col1.button("Copy to clipboard", key="copy_btn"): | |
pyperclip.copy(st.session_state["summary"]) | |
with copy_col2: | |
st.success('Text copied successfully!') | |