Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
CHANGED
|
@@ -1,5 +1,5 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
-
|
| 3 |
import os
|
| 4 |
|
| 5 |
# Page configuration
|
|
@@ -74,20 +74,13 @@ st.markdown("""
|
|
| 74 |
</style>
|
| 75 |
""", unsafe_allow_html=True)
|
| 76 |
|
| 77 |
-
# Initialize OpenAI
|
| 78 |
-
|
| 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
|
| 89 |
def generate_video_script(prompt_data):
|
| 90 |
-
if not
|
|
|
|
| 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 =
|
| 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
|
| 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)}")
|