Spaces:
Sleeping
Sleeping
Commit
·
558fd96
1
Parent(s):
ca1ad83
Update app.py
Browse files
app.py
CHANGED
@@ -1,6 +1,7 @@
|
|
1 |
import openai
|
2 |
import gradio
|
3 |
import os
|
|
|
4 |
|
5 |
openai.api_key = os.environ["OPENAI_API_KEY"]
|
6 |
|
@@ -10,12 +11,16 @@ to generate topic summary ideas for social media videos. Follow these steps in t
|
|
10 |
2. Generate 100 ideas for videos a real estate agent should make, and analyze them to choose the 10 most compelling. Do not return all 100 ideas.
|
11 |
3. Return a list of these 10 most compelling ideas."""}]
|
12 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
13 |
def CustomChatGPT(user_input, messages):
|
14 |
messages.append({"role": "user", "content": user_input})
|
15 |
-
response =
|
16 |
-
model = "gpt-3.5-turbo",
|
17 |
-
messages = messages
|
18 |
-
)
|
19 |
ChatGPT_reply = response["choices"][0]["message"]["content"]
|
20 |
messages.append({"role": "assistant", "content": ChatGPT_reply})
|
21 |
return ChatGPT_reply, messages
|
@@ -36,4 +41,3 @@ demo = gradio.Interface(fn=wrapped_chat_gpt, inputs="text", outputs="text", titl
|
|
36 |
demo.launch(inline=False)
|
37 |
|
38 |
|
39 |
-
|
|
|
1 |
import openai
|
2 |
import gradio
|
3 |
import os
|
4 |
+
from tenacity import retry, wait_fixed, stop_after_attempt
|
5 |
|
6 |
openai.api_key = os.environ["OPENAI_API_KEY"]
|
7 |
|
|
|
11 |
2. Generate 100 ideas for videos a real estate agent should make, and analyze them to choose the 10 most compelling. Do not return all 100 ideas.
|
12 |
3. Return a list of these 10 most compelling ideas."""}]
|
13 |
|
14 |
+
@retry(stop=stop_after_attempt(3), wait=wait_fixed(1))
|
15 |
+
def call_openai_api(messages):
|
16 |
+
return openai.ChatCompletion.create(
|
17 |
+
model="gpt-3.5-turbo",
|
18 |
+
messages=messages
|
19 |
+
)
|
20 |
+
|
21 |
def CustomChatGPT(user_input, messages):
|
22 |
messages.append({"role": "user", "content": user_input})
|
23 |
+
response = call_openai_api(messages)
|
|
|
|
|
|
|
24 |
ChatGPT_reply = response["choices"][0]["message"]["content"]
|
25 |
messages.append({"role": "assistant", "content": ChatGPT_reply})
|
26 |
return ChatGPT_reply, messages
|
|
|
41 |
demo.launch(inline=False)
|
42 |
|
43 |
|
|