Update app.py
Browse files
app.py
CHANGED
@@ -1,7 +1,6 @@
|
|
1 |
import streamlit as st
|
2 |
-
import
|
3 |
import numpy as np
|
4 |
-
import wave
|
5 |
import whisper
|
6 |
import os
|
7 |
import streamlit.components.v1 as components
|
@@ -32,49 +31,85 @@ st.title("Patent Claims Extraction")
|
|
32 |
# API Key Input
|
33 |
api_key = st.text_input("Enter your OpenAI API Key:", type="password")
|
34 |
|
35 |
-
# Audio
|
36 |
-
|
37 |
-
|
38 |
-
audio_frames = []
|
39 |
|
40 |
-
|
41 |
-
|
42 |
-
print(status, flush=True)
|
43 |
-
if any(indata):
|
44 |
-
audio_frames.append(indata.copy())
|
45 |
|
46 |
-
|
47 |
-
|
|
|
48 |
|
49 |
-
|
50 |
-
with
|
51 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
52 |
|
53 |
-
|
|
|
54 |
|
55 |
-
|
56 |
-
|
57 |
-
with wave.open("recorded_audio.wav", "wb") as wf:
|
58 |
-
wf.setnchannels(1)
|
59 |
-
wf.setsampwidth(2)
|
60 |
-
wf.setframerate(44100)
|
61 |
-
wf.writeframes(audio_data.tobytes())
|
62 |
|
63 |
-
#
|
64 |
-
|
65 |
-
model
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
77 |
|
|
|
|
|
|
|
|
|
|
|
78 |
with st.expander("See transcript"):
|
79 |
st.markdown(transcript)
|
80 |
|
@@ -86,7 +121,7 @@ model_choice = st.selectbox(
|
|
86 |
|
87 |
# Context, Subject, and Level
|
88 |
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."
|
89 |
-
userinput = st.text_input("Input Text:", "Freeform text here!")
|
90 |
|
91 |
# Initialize OpenAI API
|
92 |
if api_key:
|
@@ -132,4 +167,4 @@ if userinput and api_key and st.button("Extract Claims", key="claims_extraction"
|
|
132 |
learning_status_placeholder.text(f"Patentable Claims Extracted!\n{all_extracted_claims.strip()}")
|
133 |
|
134 |
# Citation
|
135 |
-
st.markdown("<sub>This app was created by [Taylor Ennen](https://github.com/taylor-ennen/GPT-Streamlit-MVP)
|
|
|
1 |
import streamlit as st
|
2 |
+
import gradio as gr
|
3 |
import numpy as np
|
|
|
4 |
import whisper
|
5 |
import os
|
6 |
import streamlit.components.v1 as components
|
|
|
31 |
# API Key Input
|
32 |
api_key = st.text_input("Enter your OpenAI API Key:", type="password")
|
33 |
|
34 |
+
# Audio Upload
|
35 |
+
audio_file = st.file_uploader("Upload an audio file", type=["mp3", "wav", "ogg"])
|
36 |
+
audio_data = None
|
|
|
37 |
|
38 |
+
if audio_file is not None:
|
39 |
+
audio_data = audio_file.read()
|
|
|
|
|
|
|
40 |
|
41 |
+
# Moved the submit_button check here
|
42 |
+
if 'submit_button' in st.session_state:
|
43 |
+
model = whisper.load_model("base")
|
44 |
|
45 |
+
if audio_data:
|
46 |
+
with tempfile.NamedTemporaryFile(delete=False, suffix=".wav") as audio_file:
|
47 |
+
audio_file.write(audio_data)
|
48 |
+
audio_file_path = audio_file.name
|
49 |
+
st.audio(audio_file_path, format="audio/wav")
|
50 |
+
st.info("Transcribing...")
|
51 |
+
st.success("Transcription complete")
|
52 |
+
result = model.transcribe(audio_file_path)
|
53 |
+
transcript = result['text']
|
54 |
|
55 |
+
with st.expander("See transcript"):
|
56 |
+
st.markdown(transcript)
|
57 |
|
58 |
+
# Update the user input field with the transcription
|
59 |
+
userinput = st.text_area("Input Text:", transcript)
|
|
|
|
|
|
|
|
|
|
|
60 |
|
61 |
+
# Model Selection Dropdown
|
62 |
+
model_choice = st.selectbox(
|
63 |
+
"Select the model you want to use:",
|
64 |
+
["gpt-3.5-turbo-0301", "gpt-3.5-turbo-0613", "gpt-3.5-turbo", "gpt-4-0314", "gpt-4-0613", "gpt-4"]
|
65 |
+
)
|
66 |
+
|
67 |
+
# Context, Subject, and Level
|
68 |
+
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."
|
69 |
+
# userinput = st.text_input("Input Text:", "Freeform text here!") # Commented out, as it's updated above
|
70 |
+
|
71 |
+
# Initialize OpenAI API
|
72 |
+
if api_key:
|
73 |
+
openai.api_key = api_key
|
74 |
+
|
75 |
+
# Learning Objectives
|
76 |
+
st.write("### Patentable Claims:")
|
77 |
+
# Initialize autogenerated objectives
|
78 |
+
claims_extraction = ""
|
79 |
+
# Initialize status placeholder
|
80 |
+
learning_status_placeholder = st.empty()
|
81 |
+
disable_button_bool = False
|
82 |
+
|
83 |
+
if userinput and api_key and st.button("Extract Claims", key="claims_extraction", disabled=disable_button_bool):
|
84 |
+
# Split the user input into chunks
|
85 |
+
input_chunks = chunk_text(userinput)
|
86 |
+
|
87 |
+
# Initialize a variable to store the extracted claims
|
88 |
+
all_extracted_claims = ""
|
89 |
+
|
90 |
+
for chunk in input_chunks:
|
91 |
+
# Display status message for the current chunk
|
92 |
+
learning_status_placeholder.text(f"Extracting Patentable Claims for chunk {input_chunks.index(chunk) + 1}...")
|
93 |
+
|
94 |
+
# API call to generate objectives for the current chunk
|
95 |
+
claims_extraction_response = openai.ChatCompletion.create(
|
96 |
+
model=model_choice,
|
97 |
+
messages=[
|
98 |
+
{"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."}
|
99 |
+
]
|
100 |
+
)
|
101 |
+
|
102 |
+
# Extract the generated objectives from the API response
|
103 |
+
claims_extraction = claims_extraction_response['choices'][0]['message']['content']
|
104 |
+
|
105 |
+
# Append the extracted claims from the current chunk to the overall results
|
106 |
+
all_extracted_claims += claims_extraction.strip()
|
107 |
|
108 |
+
# Save the generated objectives to session state
|
109 |
+
st.session_state.claims_extraction = all_extracted_claims
|
110 |
+
|
111 |
+
# Display generated objectives for all chunks
|
112 |
+
learning_status_placeholder.text(f"Patentable Claims Extracted!\n{all_extracted_claims.strip()}")
|
113 |
with st.expander("See transcript"):
|
114 |
st.markdown(transcript)
|
115 |
|
|
|
121 |
|
122 |
# Context, Subject, and Level
|
123 |
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."
|
124 |
+
# userinput = st.text_input("Input Text:", "Freeform text here!") # Commented out, as it's updated above
|
125 |
|
126 |
# Initialize OpenAI API
|
127 |
if api_key:
|
|
|
167 |
learning_status_placeholder.text(f"Patentable Claims Extracted!\n{all_extracted_claims.strip()}")
|
168 |
|
169 |
# Citation
|
170 |
+
st.markdown("<sub>This app was created by [Taylor Ennen](https://github.com/taylor-ennen/GPT-Streamlit-MVP)</sub>")
|