Spaces:
Runtime error
Runtime error
Commit
·
ec81f65
1
Parent(s):
12e8fc2
Update app.py
Browse files
app.py
CHANGED
@@ -1,46 +1,20 @@
|
|
1 |
import gradio
|
2 |
-
import openai
|
3 |
|
4 |
openai.api_key = "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"
|
5 |
|
6 |
-
|
7 |
-
messages = [{"role": "system", "content": "Welcome to Twitter Tweets Pro! Our AI-powered Twitter expert specializes in creating viral tweets for startup marketing and updates."}]
|
8 |
|
9 |
-
# Define function to generate responses to user input
|
10 |
def CustomChatGPT(user_input):
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
engine="text-davinci-002",
|
16 |
-
prompt="Tweet: " + user_input,
|
17 |
-
max_tokens=60,
|
18 |
-
n=1,
|
19 |
-
stop=None,
|
20 |
-
temperature=0.5,
|
21 |
-
)
|
22 |
-
|
23 |
-
# Extract generated tweet from API response
|
24 |
-
tweet = response.choices[0].text
|
25 |
-
|
26 |
-
# Add generated tweet to message history
|
27 |
-
messages.append({"role": "assistant", "content": tweet})
|
28 |
-
|
29 |
-
# Return generated tweet
|
30 |
-
return tweet
|
31 |
-
|
32 |
-
# Define Gradio user interface
|
33 |
-
interface = gradio.Interface(
|
34 |
-
fn=CustomChatGPT,
|
35 |
-
inputs="text",
|
36 |
-
outputs="text",
|
37 |
-
title="Twitter Tweets Pro",
|
38 |
-
description="Enter a prompt for your tweet below. The generated tweet will be displayed in the output section.",
|
39 |
-
examples=[
|
40 |
-
["I just launched my startup!"],
|
41 |
-
["What's the best way to market my business?"],
|
42 |
-
["How can I increase my social media following?"],
|
43 |
-
],
|
44 |
)
|
45 |
-
|
46 |
-
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import gradio
|
2 |
+
import openai
|
3 |
|
4 |
openai.api_key = "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"
|
5 |
|
6 |
+
messages = [{"role": "system", "content": "You are a Twitter Tweets experts that specializes in creating viral tweets for startup marketing and update"}]
|
|
|
7 |
|
|
|
8 |
def CustomChatGPT(user_input):
|
9 |
+
messages.append({"role": "user", "content": user_input})
|
10 |
+
response = openai.ChatCompletion.create(
|
11 |
+
model = "gpt-3.5-turbo",
|
12 |
+
messages = messages
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
13 |
)
|
14 |
+
ChatGPT_reply = response["choices"][0]["message"]["content"]
|
15 |
+
messages.append({"role": "assistant", "content": ChatGPT_reply})
|
16 |
+
return ChatGPT_reply
|
17 |
+
|
18 |
+
demo = gradio.Interface(fn=CustomChatGPT, inputs="text", outputs="text", title="Twitter Tweets Pro")
|
19 |
+
|
20 |
+
demo.launch()
|