File size: 3,875 Bytes
56541bd
 
 
 
 
 
 
 
dd51e9f
56541bd
 
 
 
 
 
 
 
 
 
 
dd51e9f
1b8ed56
56541bd
 
 
 
 
 
dd51e9f
56541bd
dd51e9f
56541bd
 
 
dd51e9f
56541bd
 
 
 
dd51e9f
56541bd
 
dd51e9f
56541bd
 
 
dd51e9f
56541bd
 
1b8ed56
56541bd
 
dd51e9f
1b8ed56
56541bd
dd51e9f
56541bd
 
 
 
dd51e9f
1b8ed56
56541bd
dd51e9f
 
 
 
56541bd
dd51e9f
 
 
56541bd
 
 
 
1b8ed56
56541bd
 
 
 
 
 
 
 
 
 
 
 
 
dd51e9f
56541bd
dd51e9f
 
 
74663dc
dd51e9f
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
import streamlit as st
import openai

# Streamlit Session State
if 'learning_objectives' not in st.session_state:
    st.session_state.learning_objectives = ""

# Streamlit User Input Form
st.title("Patent Claims Extraction")

# API Key Input
api_key = st.text_input("Enter your OpenAI API Key:", type="password")

# Model Selection Dropdown
model_choice = st.selectbox(
    "Select the model you want to use:",
    ["gpt-3.5-turbo-0301", "gpt-3.5-turbo-0613", "gpt-3.5-turbo", "gpt-4-0314", "gpt-4-0613", "gpt-4"]
)

# Context, Subject, and Level
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."
userinput = st.text_input("Input Text:", "Freeform text here!")

# Initialize OpenAI API
if api_key:
    openai.api_key = api_key

# Learning Objectives
st.write("### Patentable Claims:")
# Initialize autogenerated objectives
claims_extraction = ""
# Initialize status placeholder
learning_status_placeholder = st.empty()
disable_button_bool = False
if userinput and api_key and st.button("Extract Claims",key="claims_extraction",disabled=disable_button_bool):

    # Display status message
    learning_status_placeholder.text("Generating learning objectives...")
    # API call to generate objectives
    claims_extraction_response = openai.ChatCompletion.create(
        model=model_choice,
        messages=[
            {"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."}
        ]
    )
    # Extract the generated objectives from the API response
    claims_extraction=claims_extraction_response['choices'][0]['message']['content']
    
    # Save generated objectives to session state
    # st.session_state.claims_extraction = claims_extraction.strip()
    
    # Display generated objectives
    learning_status_placeholder.text(f"Patentable Claims Extracted!\n{claims_extraction.strip()}")

# Generate Lesson Plan Button
if st.button("Extract Claims") and api_key:
    
    # Construct the prompt as a dictionary
    prompt_dict = {
        "context": context,
        "userinput": userinput,
        "claims_extraction": claims_extraction.strip(),  # Use the claims_extraction variable
        "tasks": [
            {"task": "Extract Claims", "objective": "extract any wordphrases in the text provided that could be considered a patentable claim"},
            {"task": "Extract Every Claim", "objective": "Ensure each and every wordphrase with a claim is evaluated whether or not it is patentable"},
            {"task": "Explain Your Choice", "objective": "Briefly explain why you have retained each claim"},
            {"task": "Check Your Work", "objective": "Check your work to assure you have not forgotten any claims"}
        ],
        "output_format": """Present in a structured format.
        \nClaim: 
        \nExplanation:
        \nNotes:
        
        """
    }

    
    # Convert the dictionary to a string
    prompt_str = str(prompt_dict)

    # API call to generate the lesson plan
    lesson_plan_response = openai.ChatCompletion.create(
        model=model_choice,
        messages=[
            {"role": "user", "content": f"Create a lesson plan based on the following parameters: {prompt_str}"}
        ]
    )

    # Display status message
    lesson_plan=st.text("Extracting Patentable Claims...")

    # Extract and display
    assistant_reply = claims_extraction_response['choices'][0]['message']['content']
    claims_extraction=st.text(assistant_reply.strip())

# Citation 
st.markdown("<sub>This app was created by [Tonic](https://huggingface.co/tonic)</sub>", unsafe_allow_html=True)