Update app.py
Browse files
app.py
CHANGED
@@ -6,7 +6,7 @@ if 'learning_objectives' not in st.session_state:
|
|
6 |
st.session_state.learning_objectives = ""
|
7 |
|
8 |
# Streamlit User Input Form
|
9 |
-
st.title("
|
10 |
|
11 |
# API Key Input
|
12 |
api_key = st.text_input("Enter your OpenAI API Key:", type="password")
|
@@ -18,65 +18,57 @@ model_choice = st.selectbox(
|
|
18 |
)
|
19 |
|
20 |
# Context, Subject, and Level
|
21 |
-
context = "
|
22 |
-
|
23 |
-
level = st.text_input("Education Level:", "High School")
|
24 |
|
25 |
# Initialize OpenAI API
|
26 |
if api_key:
|
27 |
openai.api_key = api_key
|
28 |
|
29 |
# Learning Objectives
|
30 |
-
st.write("###
|
31 |
# Initialize autogenerated objectives
|
32 |
-
|
33 |
# Initialize status placeholder
|
34 |
learning_status_placeholder = st.empty()
|
35 |
disable_button_bool = False
|
36 |
-
if
|
37 |
|
38 |
# Display status message
|
39 |
learning_status_placeholder.text("Generating learning objectives...")
|
40 |
# API call to generate objectives
|
41 |
-
|
42 |
model=model_choice,
|
43 |
messages=[
|
44 |
-
{"role": "user", "content": f"
|
45 |
]
|
46 |
)
|
47 |
# Extract the generated objectives from the API response
|
48 |
-
|
49 |
|
50 |
# Save generated objectives to session state
|
51 |
-
st.session_state.
|
52 |
|
53 |
# Display generated objectives
|
54 |
-
learning_status_placeholder.text(f"
|
55 |
|
56 |
# Generate Lesson Plan Button
|
57 |
-
if st.button("
|
58 |
|
59 |
# Construct the prompt as a dictionary
|
60 |
prompt_dict = {
|
61 |
"context": context,
|
62 |
-
"
|
63 |
-
"
|
64 |
-
"learning_objectives": st.session_state.learning_objectives,
|
65 |
"tasks": [
|
66 |
-
{"task": "
|
67 |
-
{"task": "
|
68 |
-
{"task": "
|
69 |
-
{"task": "
|
70 |
],
|
71 |
-
"output_format": """Present
|
72 |
-
\
|
73 |
-
\
|
74 |
-
\nSubject: RESTATED FROM ABOVE
|
75 |
-
\nObjectives: RESTATED FROM ABOVE
|
76 |
-
\nActivities:
|
77 |
-
\nAssessment: Application of knowledge and skills through a task
|
78 |
-
\nProcedure: Formatted as a list of steps and substeps
|
79 |
-
\nResources:
|
80 |
\nNotes:
|
81 |
|
82 |
"""
|
@@ -94,11 +86,11 @@ if st.button("Generate Lesson Plan") and api_key:
|
|
94 |
)
|
95 |
|
96 |
# Display status message
|
97 |
-
lesson_plan=st.text("
|
98 |
|
99 |
-
# Extract and display
|
100 |
-
assistant_reply =
|
101 |
-
|
102 |
|
103 |
-
# Citation
|
104 |
-
st.markdown("<sub>This app was created by [
|
|
|
6 |
st.session_state.learning_objectives = ""
|
7 |
|
8 |
# Streamlit User Input Form
|
9 |
+
st.title("Patent Claims Extraction")
|
10 |
|
11 |
# API Key Input
|
12 |
api_key = st.text_input("Enter your OpenAI API Key:", type="password")
|
|
|
18 |
)
|
19 |
|
20 |
# Context, Subject, and Level
|
21 |
+
context = "You are a patent claims identifier and extractor. You will freeform text, identify any claims contained therein that may be patentable. You identify , extract, print such claims, briefly explain why each claim is patentable."
|
22 |
+
userinput = st.text_input("Input Text:", "Mathematics")
|
|
|
23 |
|
24 |
# Initialize OpenAI API
|
25 |
if api_key:
|
26 |
openai.api_key = api_key
|
27 |
|
28 |
# Learning Objectives
|
29 |
+
st.write("### Patentable Claims:")
|
30 |
# Initialize autogenerated objectives
|
31 |
+
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:
|
57 |
|
58 |
# Construct the prompt as a dictionary
|
59 |
prompt_dict = {
|
60 |
"context": context,
|
61 |
+
"userinput": userinput,
|
62 |
+
"claims_extraction": st.session_state.claims_extraction,
|
|
|
63 |
"tasks": [
|
64 |
+
{"task": "Extract Claims", "objective": "extract any wordphrases in the text provided that could be considered a patentable claim"},
|
65 |
+
{"task": "Extract Every Claim", "objective": "Ensure each and every wordphrase with a claim is evaluated whether or not it is patentable"},
|
66 |
+
{"task": "Explain Your Choice", "objective": "Briefly explain why you have retained each claim"},
|
67 |
+
{"task": "Check Your Work", "objective": "Check your work to assure you have not forgotten any claims"}
|
68 |
],
|
69 |
+
"output_format": """Present in a structured format.
|
70 |
+
\nClaim:
|
71 |
+
\nExplanation:
|
|
|
|
|
|
|
|
|
|
|
|
|
72 |
\nNotes:
|
73 |
|
74 |
"""
|
|
|
86 |
)
|
87 |
|
88 |
# Display status message
|
89 |
+
lesson_plan=st.text("Extracting Patentable Claims...")
|
90 |
|
91 |
+
# Extract and display
|
92 |
+
assistant_reply = claims_extraction_response['choices'][0]['message']['content']
|
93 |
+
claims_extraction=st.text(assistant_reply.strip())
|
94 |
|
95 |
+
# Citation
|
96 |
+
st.markdown("<sub>This app was created by [Tonic](https://huggingface.co/tonic)</sub>", unsafe_allow_html=True)
|