Pranav0111 commited on
Commit
5b1e589
1 Parent(s): 5e1b314

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -3
app.py CHANGED
@@ -1,12 +1,16 @@
1
  import gradio as gr
2
  from transformers import pipeline
3
- import openai # Import if you are using OpenAI's API
4
  import random
 
5
  from datetime import datetime
6
 
7
  # Initialize sentiment analysis pipeline
8
  sentiment_analyzer = pipeline("sentiment-analysis", model="distilbert-base-uncased-finetuned-sst-2-english")
9
 
 
 
 
10
  class JournalCompanion:
11
  def __init__(self):
12
  self.entries = []
@@ -49,7 +53,7 @@ class JournalCompanion:
49
  prompt_request = f"Generate three reflective journal prompts for a person feeling {sentiment.lower()}."
50
  try:
51
  response = openai.Completion.create(
52
- engine="gpt-3.5-turbo",
53
  prompt=prompt_request,
54
  max_tokens=60,
55
  n=1
@@ -64,7 +68,7 @@ class JournalCompanion:
64
  affirmation_request = f"Generate an affirmation for someone who is feeling {sentiment.lower()}."
65
  try:
66
  response = openai.Completion.create(
67
- engine="gpt-3.5-turbo",
68
  prompt=affirmation_request,
69
  max_tokens=20,
70
  n=1
 
1
  import gradio as gr
2
  from transformers import pipeline
3
+ import openai
4
  import random
5
+ import os
6
  from datetime import datetime
7
 
8
  # Initialize sentiment analysis pipeline
9
  sentiment_analyzer = pipeline("sentiment-analysis", model="distilbert-base-uncased-finetuned-sst-2-english")
10
 
11
+ # Retrieve OpenAI API key from Hugging Face secret
12
+ openai.api_key = os.getenv("open_AI_API_key")
13
+
14
  class JournalCompanion:
15
  def __init__(self):
16
  self.entries = []
 
53
  prompt_request = f"Generate three reflective journal prompts for a person feeling {sentiment.lower()}."
54
  try:
55
  response = openai.Completion.create(
56
+ engine="text-davinci-003",
57
  prompt=prompt_request,
58
  max_tokens=60,
59
  n=1
 
68
  affirmation_request = f"Generate an affirmation for someone who is feeling {sentiment.lower()}."
69
  try:
70
  response = openai.Completion.create(
71
+ engine="text-davinci-003",
72
  prompt=affirmation_request,
73
  max_tokens=20,
74
  n=1