Rsamala commited on
Commit
f4e9a9a
·
1 Parent(s): 663efc9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -32
app.py CHANGED
@@ -1,46 +1,37 @@
1
  # Import the required libraries
2
  import openai
 
3
  import streamlit as st
4
 
5
  # Set the GPT-3 API key
6
- # In this case, st.secrets["pass"] is accessing the value of the "pass" secret.
7
 
8
- openai.api_key = st.secrets["pass"]
9
- # Create Text Area Widget to enable user to enter texts
 
10
  article_text = st.text_area("Enter your scientific texts to summarize")
11
- # Create Radio Buttons
12
- output_size = st.radio( label = "What kind of output do you want?",
13
- options= ["To-The-Point", "Concise", "Detailed"]
14
- )
15
- # First, we'll use an if statement to determine the desired output size
16
- # and set the out_token variable accordingly:
17
 
18
  if output_size == "To-The-Point":
19
- out_token = 50
20
  elif output_size == "Concise":
21
- out_token = 128
22
  else:
23
- out_token = 516
24
-
25
- # Next, we'll add a check to make sure that the input text is long enough
26
- # to summarize, and display a warning if it is not:
27
 
28
  if len(article_text)>100:
29
- # Generate the summary
30
- # .......
 
 
 
 
 
 
 
 
 
 
31
  else:
32
- st.warning("Not enough words to summarize!")
33
- if st.button("Generate Summary",type='primary'):
34
-
35
- # Use GPT-3 to generate a summary of the article
36
- response = openai.Completion.create(
37
- engine = "text-davinci-002",
38
- prompt = "Please summarize this scientific article for me in a few sentences: "+ article_text,
39
- max_tokens = out_token,
40
- temperature = 0.5)
41
-
42
- # Print the generated summary
43
- res = response["choices"][0]["text"]
44
- st.success(res)
45
- # Give user the option to download result
46
- st.download_button('Download result', res)
 
1
  # Import the required libraries
2
  import openai
3
+ # import os
4
  import streamlit as st
5
 
6
  # Set the GPT-3 API key
7
+ openai.api_key = st.secrets["pass"]
8
 
9
+ # Read the text of the article from a file
10
+ # with open("article.txt", "r") as f:
11
+ # article_text = f.read()
12
  article_text = st.text_area("Enter your scientific texts to summarize")
13
+ output_size = st.radio(label = "What kind of output do you want?",
14
+ options= ["To-The-Point", "Concise", "Detailed"])
 
 
 
 
15
 
16
  if output_size == "To-The-Point":
17
+ out_token = 50
18
  elif output_size == "Concise":
19
+ out_token = 128
20
  else:
21
+ out_token = 516
 
 
 
22
 
23
  if len(article_text)>100:
24
+ if st.button("Generate Summary",type='primary'):
25
+ # Use GPT-3 to generate a summary of the article
26
+ response = openai.Completion.create(
27
+ engine="text-davinci-002",
28
+ prompt="Please summarize this scientific article for me in a few sentences: " + article_text,
29
+ max_tokens = out_token,
30
+ temperature = 0.5,
31
+ )
32
+ # Print the generated summary
33
+ res = response["choices"][0]["text"]
34
+ st.success(res)
35
+ st.download_button('Download result', res)
36
  else:
37
+ st.warning("Not enough words to summarize!")