prernajeet01 commited on
Commit
0b9141c
·
verified ·
1 Parent(s): 89fb16c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -4
app.py CHANGED
@@ -19,7 +19,9 @@ def initialize_openai():
19
  if not api_key:
20
  return "Error: OPENAI_API_KEY not found in environment variables"
21
 
 
22
  client = OpenAI(api_key=api_key)
 
23
  # Test the API key with a simple request
24
  response = client.chat.completions.create(
25
  model="gpt-3.5-turbo",
@@ -28,7 +30,7 @@ def initialize_openai():
28
  )
29
  return True
30
  except Exception as e:
31
- return str(e)
32
 
33
  def analyze_journal_entry(entry_data):
34
  """Analyze a single journal entry using OpenAI"""
@@ -227,9 +229,9 @@ def generate_report(results, summary_stats):
227
 
228
  ## Summary
229
  - Total Entries Analyzed: {summary_stats['total_entries']}
230
- - High Risk Entries: {summary_stats['high_risk_count']} ({round(summary_stats['high_risk_count']/summary_stats['total_entries']*100, 1)}%)
231
- - Medium Risk Entries: {summary_stats['medium_risk_count']} ({round(summary_stats['medium_risk_count']/summary_stats['total_entries']*100, 1)}%)
232
- - Low Risk Entries: {summary_stats['low_risk_count']} ({round(summary_stats['low_risk_count']/summary_stats['total_entries']*100, 1)}%)
233
  - Processing Time: {summary_stats['processing_time']} seconds
234
 
235
  ## Issues By Type
 
19
  if not api_key:
20
  return "Error: OPENAI_API_KEY not found in environment variables"
21
 
22
+ # Initialize the client without any additional parameters that might cause issues
23
  client = OpenAI(api_key=api_key)
24
+
25
  # Test the API key with a simple request
26
  response = client.chat.completions.create(
27
  model="gpt-3.5-turbo",
 
30
  )
31
  return True
32
  except Exception as e:
33
+ return f"OpenAI initialization error: {str(e)}"
34
 
35
  def analyze_journal_entry(entry_data):
36
  """Analyze a single journal entry using OpenAI"""
 
229
 
230
  ## Summary
231
  - Total Entries Analyzed: {summary_stats['total_entries']}
232
+ - High Risk Entries: {summary_stats['high_risk_count']} ({round(summary_stats['high_risk_count']/summary_stats['total_entries']*100, 1) if summary_stats['total_entries'] > 0 else 0}%)
233
+ - Medium Risk Entries: {summary_stats['medium_risk_count']} ({round(summary_stats['medium_risk_count']/summary_stats['total_entries']*100, 1) if summary_stats['total_entries'] > 0 else 0}%)
234
+ - Low Risk Entries: {summary_stats['low_risk_count']} ({round(summary_stats['low_risk_count']/summary_stats['total_entries']*100, 1) if summary_stats['total_entries'] > 0 else 0}%)
235
  - Processing Time: {summary_stats['processing_time']} seconds
236
 
237
  ## Issues By Type