falconX90 commited on
Commit
2679c7b
·
1 Parent(s): 570b976

commit change

Browse files
Files changed (1) hide show
  1. app.py +45 -47
app.py CHANGED
@@ -1,8 +1,6 @@
1
- ```python
2
  import streamlit as st
3
  import requests
4
  import os
5
- from transformers import pipeline
6
 
7
  huggingface_token = os.getenv('HF_TOKEN')
8
 
@@ -14,11 +12,11 @@ def query(payload):
14
  response = requests.post(API_URL, headers=headers, json=payload)
15
  return response.json()
16
 
17
- output = query({
18
- "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.",
19
- })
20
 
21
- print(output)
22
 
23
 
24
  st.title("Text Summarization App")
@@ -42,45 +40,45 @@ if button and sentence:
42
  # return model
43
 
44
 
45
- def generate_chunks(inp_str):
46
- max_chunk = 500
47
- inp_str = inp_str.replace('.', '.<eos>')
48
- inp_str = inp_str.replace('?', '?<eos>')
49
- inp_str = inp_str.replace('!', '!<eos>')
50
 
51
- sentences = inp_str.split('<eos>')
52
- current_chunk = 0
53
- chunks = []
54
- for sentence in sentences:
55
- if len(chunks) == current_chunk + 1:
56
- if len(chunks[current_chunk]) + len(sentence.split(' ')) <= max_chunk:
57
- chunks[current_chunk].extend(sentence.split(' '))
58
- else:
59
- current_chunk += 1
60
- chunks.append(sentence.split(' '))
61
- else:
62
- chunks.append(sentence.split(' '))
63
-
64
- for chunk_id in range(len(chunks)):
65
- chunks[chunk_id] = ' '.join(chunks[chunk_id])
66
- return chunks
67
-
68
-
69
- summarizer = load_summarizer()
70
- st.title("Summarize Text")
71
- sentence = st.text_area('Please paste your article :', height=30)
72
- button = st.button("Summarize")
73
-
74
- max = st.sidebar.slider('Select max', 50, 500, step=10, value=150)
75
- min = st.sidebar.slider('Select min', 10, 450, step=10, value=50)
76
- do_sample = st.sidebar.checkbox("Do sample", value=False)
77
- with st.spinner("Generating Summary.."):
78
- if button and sentence:
79
- chunks = generate_chunks(sentence)
80
- res = summarizer(chunks,
81
- max_length=max,
82
- min_length=min,
83
- do_sample=do_sample)
84
- text = ' '.join([summ['summary_text'] for summ in res])
85
- # st.write(result[0]['summary_text'])
86
- st.write(text)
 
 
1
  import streamlit as st
2
  import requests
3
  import os
 
4
 
5
  huggingface_token = os.getenv('HF_TOKEN')
6
 
 
12
  response = requests.post(API_URL, headers=headers, json=payload)
13
  return response.json()
14
 
15
+ # output = query({
16
+ # "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.",
17
+ # })
18
 
19
+ # print(output)
20
 
21
 
22
  st.title("Text Summarization App")
 
40
  # return model
41
 
42
 
43
+ # def generate_chunks(inp_str):
44
+ # max_chunk = 500
45
+ # inp_str = inp_str.replace('.', '.<eos>')
46
+ # inp_str = inp_str.replace('?', '?<eos>')
47
+ # inp_str = inp_str.replace('!', '!<eos>')
48
 
49
+ # sentences = inp_str.split('<eos>')
50
+ # current_chunk = 0
51
+ # chunks = []
52
+ # for sentence in sentences:
53
+ # if len(chunks) == current_chunk + 1:
54
+ # if len(chunks[current_chunk]) + len(sentence.split(' ')) <= max_chunk:
55
+ # chunks[current_chunk].extend(sentence.split(' '))
56
+ # else:
57
+ # current_chunk += 1
58
+ # chunks.append(sentence.split(' '))
59
+ # else:
60
+ # chunks.append(sentence.split(' '))
61
+
62
+ # for chunk_id in range(len(chunks)):
63
+ # chunks[chunk_id] = ' '.join(chunks[chunk_id])
64
+ # return chunks
65
+
66
+
67
+ # summarizer = load_summarizer()
68
+ # st.title("Summarize Text")
69
+ # sentence = st.text_area('Please paste your article :', height=30)
70
+ # button = st.button("Summarize")
71
+
72
+ # max = st.sidebar.slider('Select max', 50, 500, step=10, value=150)
73
+ # min = st.sidebar.slider('Select min', 10, 450, step=10, value=50)
74
+ # do_sample = st.sidebar.checkbox("Do sample", value=False)
75
+ # with st.spinner("Generating Summary.."):
76
+ # if button and sentence:
77
+ # chunks = generate_chunks(sentence)
78
+ # res = summarizer(chunks,
79
+ # max_length=max,
80
+ # min_length=min,
81
+ # do_sample=do_sample)
82
+ # text = ' '.join([summ['summary_text'] for summ in res])
83
+ # # st.write(result[0]['summary_text'])
84
+ # st.write(text)