Tonic commited on
Commit
9f4d7d7
1 Parent(s): 7e766dc

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +39 -18
app.py CHANGED
@@ -1,6 +1,16 @@
1
  import streamlit as st
2
  import openai
3
 
 
 
 
 
 
 
 
 
 
 
4
  # Streamlit Session State
5
  if 'learning_objectives' not in st.session_state:
6
  st.session_state.learning_objectives = ""
@@ -32,25 +42,36 @@ claims_extraction = ""
32
  # Initialize status placeholder
33
  learning_status_placeholder = st.empty()
34
  disable_button_bool = False
35
- if userinput and api_key and st.button("Extract Claims",key="claims_extraction",disabled=disable_button_bool):
36
-
37
- # Display status message
38
- learning_status_placeholder.text("Generating learning objectives...")
39
- # API call to generate objectives
40
- claims_extraction_response = openai.ChatCompletion.create(
41
- model=model_choice,
42
- messages=[
43
- {"role": "user", "content": f"Extract any patentable claims from the following: \n {userinput}. \n extract each claim. Briefly explain why you extracted this wordphrase. Exclude any additional commentary."}
44
- ]
45
- )
46
- # Extract the generated objectives from the API response
47
- claims_extraction=claims_extraction_response['choices'][0]['message']['content']
48
 
49
- # Save generated objectives to session state
50
- # st.session_state.claims_extraction = claims_extraction.strip()
51
-
52
- # Display generated objectives
53
- learning_status_placeholder.text(f"Patentable Claims Extracted!\n{claims_extraction.strip()}")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
54
 
55
  # Generate Lesson Plan Button
56
  if st.button("Extract Claims") and api_key:
 
1
  import streamlit as st
2
  import openai
3
 
4
+ def chunk_text(text, chunk_size=2000):
5
+ chunks = []
6
+ start = 0
7
+ while start < len(text):
8
+ end = start + chunk_size
9
+ chunk = text[start:end]
10
+ chunks.append(chunk)
11
+ start = end
12
+ return chunks
13
+
14
  # Streamlit Session State
15
  if 'learning_objectives' not in st.session_state:
16
  st.session_state.learning_objectives = ""
 
42
  # Initialize status placeholder
43
  learning_status_placeholder = st.empty()
44
  disable_button_bool = False
45
+ if userinput and api_key and st.button("Extract Claims", key="claims_extraction", disabled=disable_button_bool):
46
+ # Split the user input into chunks
47
+ input_chunks = chunk_text(userinput)
 
 
 
 
 
 
 
 
 
 
48
 
49
+ # Initialize a variable to store the extracted claims
50
+ all_extracted_claims = ""
51
+
52
+ for chunk in input_chunks:
53
+ # Display status message for the current chunk
54
+ learning_status_placeholder.text(f"Extracting Patentable Claims for chunk {input_chunks.index(chunk) + 1}...")
55
+
56
+ # API call to generate objectives for the current chunk
57
+ claims_extraction_response = openai.ChatCompletion.create(
58
+ model=model_choice,
59
+ messages=[
60
+ {"role": "user", "content": f"Extract any patentable claims from the following: \n {chunk}. \n extract each claim. Briefly explain why you extracted this word phrase. Exclude any additional commentary."}
61
+ ]
62
+ )
63
+
64
+ # Extract the generated objectives from the API response
65
+ claims_extraction = claims_extraction_response['choices'][0]['message']['content']
66
+
67
+ # Append the extracted claims from the current chunk to the overall results
68
+ all_extracted_claims += claims_extraction.strip()
69
+
70
+ # Save the generated objectives to session state
71
+ st.session_state.claims_extraction = all_extracted_claims
72
+
73
+ # Display generated objectives for all chunks
74
+ learning_status_placeholder.text(f"Patentable Claims Extracted!\n{all_extracted_claims.strip()}")
75
 
76
  # Generate Lesson Plan Button
77
  if st.button("Extract Claims") and api_key: