nniehaus commited on
Commit
8d3cc4d
·
verified ·
1 Parent(s): 80defbf

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -15
app.py CHANGED
@@ -1,5 +1,5 @@
1
  import streamlit as st
2
- from openai import OpenAI
3
  import os
4
 
5
  # Page configuration
@@ -74,20 +74,13 @@ st.markdown("""
74
  </style>
75
  """, unsafe_allow_html=True)
76
 
77
- # Initialize OpenAI client
78
- @st.cache_resource
79
- def get_openai_client():
80
- try:
81
- return OpenAI(api_key=os.getenv("OPENAI_API_KEY"))
82
- except Exception as e:
83
- st.error("Please set your OPENAI_API_KEY environment variable")
84
- return None
85
-
86
- client = get_openai_client()
87
 
88
- # Function to generate script with current OpenAI API
89
  def generate_video_script(prompt_data):
90
- if not client:
 
91
  return None
92
 
93
  try:
@@ -120,7 +113,7 @@ def generate_video_script(prompt_data):
120
  Make it {prompt_data['tone'].lower()} and ensure it's compelling from start to finish.
121
  """
122
 
123
- response = client.chat.completions.create(
124
  model="gpt-4",
125
  messages=[
126
  {"role": "system", "content": system_message},
@@ -129,7 +122,7 @@ def generate_video_script(prompt_data):
129
  temperature=0.8
130
  )
131
 
132
- return response.choices[0].message.content
133
 
134
  except Exception as e:
135
  st.error(f"Error generating script: {str(e)}")
 
1
  import streamlit as st
2
+ import openai
3
  import os
4
 
5
  # Page configuration
 
74
  </style>
75
  """, unsafe_allow_html=True)
76
 
77
+ # Initialize OpenAI API key
78
+ openai.api_key = os.getenv("OPENAI_API_KEY")
 
 
 
 
 
 
 
 
79
 
80
+ # Function to generate script with OpenAI API
81
  def generate_video_script(prompt_data):
82
+ if not openai.api_key:
83
+ st.error("Please set your OPENAI_API_KEY environment variable")
84
  return None
85
 
86
  try:
 
113
  Make it {prompt_data['tone'].lower()} and ensure it's compelling from start to finish.
114
  """
115
 
116
+ response = openai.ChatCompletion.create(
117
  model="gpt-4",
118
  messages=[
119
  {"role": "system", "content": system_message},
 
122
  temperature=0.8
123
  )
124
 
125
+ return response["choices"][0]["message"]["content"]
126
 
127
  except Exception as e:
128
  st.error(f"Error generating script: {str(e)}")