Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,18 +1,9 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
import requests
|
| 3 |
import asyncio
|
| 4 |
-
import
|
| 5 |
-
import
|
| 6 |
-
import
|
| 7 |
-
|
| 8 |
-
# Create a new event loop for the current thread
|
| 9 |
-
loop = asyncio.new_event_loop()
|
| 10 |
-
asyncio.set_event_loop(loop)
|
| 11 |
-
|
| 12 |
-
# Apply nest_asyncio to the new event loop
|
| 13 |
-
nest_asyncio.apply(loop)
|
| 14 |
-
|
| 15 |
-
# Rest of your code remains the same...
|
| 16 |
|
| 17 |
# Function to split text into chunks based on token limit
|
| 18 |
def split_text_into_chunks(text, max_tokens=4000):
|
|
@@ -249,11 +240,10 @@ if uploaded_file is not None:
|
|
| 249 |
# Analyze the contract
|
| 250 |
if st.button("Start AI Review"):
|
| 251 |
with st.spinner("Analyzing contract..."):
|
| 252 |
-
# Get the API key from secrets.toml
|
| 253 |
-
|
| 254 |
-
|
| 255 |
-
|
| 256 |
-
st.error("API key not found in secrets.toml. Please add it.")
|
| 257 |
st.stop()
|
| 258 |
|
| 259 |
# Analyze the contract using the LLM
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
import requests
|
| 3 |
import asyncio
|
| 4 |
+
import pdfplumber # For PDF text extraction
|
| 5 |
+
import json # For parsing JSON response
|
| 6 |
+
import os # For environment variables
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
|
| 8 |
# Function to split text into chunks based on token limit
|
| 9 |
def split_text_into_chunks(text, max_tokens=4000):
|
|
|
|
| 240 |
# Analyze the contract
|
| 241 |
if st.button("Start AI Review"):
|
| 242 |
with st.spinner("Analyzing contract..."):
|
| 243 |
+
# Get the API key from environment variables or secrets.toml
|
| 244 |
+
api_key = os.getenv("OPENAI_API_KEY")
|
| 245 |
+
if not api_key:
|
| 246 |
+
st.error("OpenAI API key not found. Please set the OPENAI_API_KEY environment variable.")
|
|
|
|
| 247 |
st.stop()
|
| 248 |
|
| 249 |
# Analyze the contract using the LLM
|