eaglelandsonce commited on
Commit
743200b
1 Parent(s): c2e02ef

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -9
app.py CHANGED
@@ -3,7 +3,7 @@ from transformers import AutoTokenizer, AutoModelForSeq2SeqLM, pipeline, AutoMod
3
  import torch
4
  import fitz # PyMuPDF
5
  from docx import Document
6
- import openai
7
 
8
  # Load models and tokenizers
9
  summarizer_model_name = "facebook/bart-large-cnn"
@@ -101,24 +101,20 @@ if uploaded_file is not None:
101
  "average_predictions": avg_predictions.tolist() # Convert tensor to list for JSON serialization
102
  }
103
 
104
- openai.api_key = openai_key
105
 
106
  decision_prompt = f"""
107
  Analyze the following legal document analysis data and provide a decision and reasoning:
108
-
109
  Summary of the Document:
110
  {full_summary}
111
-
112
  Classification Result:
113
  {classification_result}
114
-
115
  Average Predictions:
116
  {avg_predictions.tolist()}
117
-
118
  Based on the above analysis, provide the judge's decision and reasoning in a detailed manner.
119
  """
120
 
121
- response = openai.ChatCompletion.create(
122
  model="gpt-4",
123
  messages=[
124
  {"role": "system", "content": "You are a legal expert analyzing the case."},
@@ -127,10 +123,10 @@ if uploaded_file is not None:
127
  max_tokens=500
128
  )
129
 
130
- decision_and_reasoning = response['choices'][0]['message']['content'].strip()
131
  st.write(decision_and_reasoning)
132
 
133
  else:
134
  st.write("Please input a legal document for analysis.")
135
  else:
136
- st.write("Please enter your OpenAI API key.")
 
3
  import torch
4
  import fitz # PyMuPDF
5
  from docx import Document
6
+ from openai import OpenAI
7
 
8
  # Load models and tokenizers
9
  summarizer_model_name = "facebook/bart-large-cnn"
 
101
  "average_predictions": avg_predictions.tolist() # Convert tensor to list for JSON serialization
102
  }
103
 
104
+ client = OpenAI(api_key=openai_key)
105
 
106
  decision_prompt = f"""
107
  Analyze the following legal document analysis data and provide a decision and reasoning:
 
108
  Summary of the Document:
109
  {full_summary}
 
110
  Classification Result:
111
  {classification_result}
 
112
  Average Predictions:
113
  {avg_predictions.tolist()}
 
114
  Based on the above analysis, provide the judge's decision and reasoning in a detailed manner.
115
  """
116
 
117
+ response = client.chat.completions.create(
118
  model="gpt-4",
119
  messages=[
120
  {"role": "system", "content": "You are a legal expert analyzing the case."},
 
123
  max_tokens=500
124
  )
125
 
126
+ decision_and_reasoning = response.choices[0].message.content.strip()
127
  st.write(decision_and_reasoning)
128
 
129
  else:
130
  st.write("Please input a legal document for analysis.")
131
  else:
132
+ st.write("Please enter your OpenAI API key.")