import streamlit as st import requests import os huggingface_token = os.getenv('HF_TOKEN') API_URL = "https://api-inference.huggingface.co/models/facebook/bart-large-cnn" headers = {"Authorization": f"Bearer {huggingface_token}"} def query(payload): response = requests.post(API_URL, headers=headers, json=payload) return response.json() # output = query({ # "inputs": "The tower is 324 metres (1,063 ft) tall, about the same height as an 81-storey building, and the tallest structure in Paris. Its base is square, measuring 125 metres (410 ft) on each side. During its construction, the Eiffel Tower surpassed the Washington Monument to become the tallest man-made structure in the world, a title it held for 41 years until the Chrysler Building in New York City was finished in 1930. It was the first structure to reach a height of 300 metres. Due to the addition of a broadcasting aerial at the top of the tower in 1957, it is now taller than the Chrysler Building by 5.2 metres (17 ft). Excluding transmitters, the Eiffel Tower is the second tallest free-standing structure in France after the Millau Viaduct.", # }) # print(output) st.title("Text Summarization App") sentence = st.text_area('Please paste your article :', height=200) output = query({ "inputs": sentence, }) button = st.button("Summarize", type="primary") # st.write(output[0]["summary_text"]) if button and sentence: st.write(output[0]["summary_text"]) # @st.cache_data(allow_output_mutation=True) # def load_summarizer(): # model = pipeline("summarization", device=0) # return model # def generate_chunks(inp_str): # max_chunk = 500 # inp_str = inp_str.replace('.', '.') # inp_str = inp_str.replace('?', '?') # inp_str = inp_str.replace('!', '!') # sentences = inp_str.split('') # current_chunk = 0 # chunks = [] # for sentence in sentences: # if len(chunks) == current_chunk + 1: # if len(chunks[current_chunk]) + len(sentence.split(' ')) <= max_chunk: # chunks[current_chunk].extend(sentence.split(' ')) # else: # current_chunk += 1 # chunks.append(sentence.split(' ')) # else: # chunks.append(sentence.split(' ')) # for chunk_id in range(len(chunks)): # chunks[chunk_id] = ' '.join(chunks[chunk_id]) # return chunks # summarizer = load_summarizer() # st.title("Summarize Text") # sentence = st.text_area('Please paste your article :', height=30) # button = st.button("Summarize") # max = st.sidebar.slider('Select max', 50, 500, step=10, value=150) # min = st.sidebar.slider('Select min', 10, 450, step=10, value=50) # do_sample = st.sidebar.checkbox("Do sample", value=False) # with st.spinner("Generating Summary.."): # if button and sentence: # chunks = generate_chunks(sentence) # res = summarizer(chunks, # max_length=max, # min_length=min, # do_sample=do_sample) # text = ' '.join([summ['summary_text'] for summ in res]) # # st.write(result[0]['summary_text']) # st.write(text)