Ashar086 commited on
Commit
248864a
·
verified ·
1 Parent(s): 2b6c1dd

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -17
app.py CHANGED
@@ -1,18 +1,9 @@
1
  import streamlit as st
2
  import requests
3
  import asyncio
4
- import nest_asyncio
5
- import pdfplumber
6
- import json
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
- if "api" in st.secrets and "key" in st.secrets["api"]:
254
- api_key = st.secrets["api"]["key"]
255
- else:
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