Update app.py
Browse files
app.py
CHANGED
@@ -9,6 +9,7 @@ import tempfile
|
|
9 |
import io
|
10 |
import requests
|
11 |
import json
|
|
|
12 |
|
13 |
def chunk_text(text, chunk_size=2000):
|
14 |
chunks = []
|
@@ -30,16 +31,6 @@ st.title("Patent Claims Extraction")
|
|
30 |
# API Key Input
|
31 |
api_key = st.text_input("Enter your OpenAI API Key:", type="password")
|
32 |
|
33 |
-
# Camera Input
|
34 |
-
image = st.camera_input("Camera input")
|
35 |
-
|
36 |
-
with tempfile.NamedTemporaryFile(delete=False, suffix=".jpg") as tf:
|
37 |
-
if image:
|
38 |
-
tf.write(image.read())
|
39 |
-
temp_image_path = tf.name
|
40 |
-
else:
|
41 |
-
temp_image_path = None
|
42 |
-
|
43 |
# Audio Recording
|
44 |
audio = st.audio_recorder("Click to record audio", "Click to stop recording")
|
45 |
|
@@ -47,13 +38,20 @@ submit_button = st.button("Use this audio")
|
|
47 |
|
48 |
if submit_button:
|
49 |
model = whisper.load_model("base")
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
54 |
|
55 |
-
|
56 |
-
|
57 |
|
58 |
# Model Selection Dropdown
|
59 |
model_choice = st.selectbox(
|
@@ -108,47 +106,6 @@ if userinput and api_key and st.button("Extract Claims", key="claims_extraction"
|
|
108 |
# Display generated objectives for all chunks
|
109 |
learning_status_placeholder.text(f"Patentable Claims Extracted!\n{all_extracted_claims.strip()}")
|
110 |
|
111 |
-
# Claims Extraction
|
112 |
-
if st.button("Extract Claims") and api_key and transcript:
|
113 |
-
# You should have 'transcript' available at this point
|
114 |
-
# Ensure 'transcript' is defined before this block.
|
115 |
-
|
116 |
-
# Split the user input into chunks
|
117 |
-
input_chunks = chunk_text(transcript) # Use 'transcript' instead of 'userinput'
|
118 |
-
|
119 |
-
# Initialize a variable to store the extracted claims
|
120 |
-
all_extracted_claims = ""
|
121 |
-
|
122 |
-
for chunk in input_chunks:
|
123 |
-
# Display status message for the current chunk
|
124 |
-
learning_status_placeholder.text(f"Extracting Patentable Claims for chunk {input_chunks.index(chunk) + 1}...")
|
125 |
-
|
126 |
-
# API call to generate objectives for the current chunk
|
127 |
-
claims_extraction_response = openai.ChatCompletion.create(
|
128 |
-
model=model_choice,
|
129 |
-
messages=[
|
130 |
-
{"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."}
|
131 |
-
]
|
132 |
-
)
|
133 |
-
|
134 |
-
# Extract the generated objectives from the API response
|
135 |
-
claims_extraction = claims_extraction_response['choices'][0]['message']['content']
|
136 |
-
|
137 |
-
# Append the extracted claims from the current chunk to the overall results
|
138 |
-
all_extracted_claims += claims_extraction.strip()
|
139 |
-
|
140 |
-
# Save the generated objectives to session state
|
141 |
-
st.session_state.claims_extraction = all_extracted_claims
|
142 |
-
|
143 |
-
# Display generated objectives for all chunks
|
144 |
-
learning_status_placeholder.text(f"Patentable Claims Extracted!\n{all_extracted_claims.strip()}")
|
145 |
-
|
146 |
-
# Display status message
|
147 |
-
lesson_plan = st.text("Extracting Patentable Claims...")
|
148 |
-
|
149 |
-
# Extract and display
|
150 |
-
assistant_reply = claims_extraction_response['choices'][0]['message']['content']
|
151 |
-
claims_extraction = st.text(assistant_reply.strip())
|
152 |
|
153 |
# Citation
|
154 |
st.markdown("<sub>This app was created by [Taylor Ennen](https://github.com/taylor-ennen/GPT-Streamlit-MVP) & [Tonic](https://huggingface.co/tonic)</sub>", unsafe_allow_html=True)
|
|
|
9 |
import io
|
10 |
import requests
|
11 |
import json
|
12 |
+
import openai
|
13 |
|
14 |
def chunk_text(text, chunk_size=2000):
|
15 |
chunks = []
|
|
|
31 |
# API Key Input
|
32 |
api_key = st.text_input("Enter your OpenAI API Key:", type="password")
|
33 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
34 |
# Audio Recording
|
35 |
audio = st.audio_recorder("Click to record audio", "Click to stop recording")
|
36 |
|
|
|
38 |
|
39 |
if submit_button:
|
40 |
model = whisper.load_model("base")
|
41 |
+
audio_data = audio.export().read()
|
42 |
+
audio_bytes_io = io.BytesIO(audio_data)
|
43 |
+
|
44 |
+
with tempfile.NamedTemporaryFile(delete=False, suffix=".wav") as audio_file:
|
45 |
+
audio_file.write(audio_bytes_io.read())
|
46 |
+
audio_file_path = audio_file.name
|
47 |
+
st.audio(audio_file_path, format="audio/wav")
|
48 |
+
st.info("Transcribing...")
|
49 |
+
st.success("Transcription complete")
|
50 |
+
result = model.transcribe(audio_file_path)
|
51 |
+
transcript = result['text']
|
52 |
|
53 |
+
with st.expander("See transcript"):
|
54 |
+
st.markdown(transcript)
|
55 |
|
56 |
# Model Selection Dropdown
|
57 |
model_choice = st.selectbox(
|
|
|
106 |
# Display generated objectives for all chunks
|
107 |
learning_status_placeholder.text(f"Patentable Claims Extracted!\n{all_extracted_claims.strip()}")
|
108 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
109 |
|
110 |
# Citation
|
111 |
st.markdown("<sub>This app was created by [Taylor Ennen](https://github.com/taylor-ennen/GPT-Streamlit-MVP) & [Tonic](https://huggingface.co/tonic)</sub>", unsafe_allow_html=True)
|